@@ -222,7 +222,7 @@ def test_sign_with_iam_error(self):
222
222
with pytest .raises (auth .FirebaseAuthError ) as excinfo :
223
223
auth .create_custom_token (MOCK_UID , app = app )
224
224
assert excinfo .value .code == exceptions .UNKNOWN
225
- assert excinfo .value ._auth_error_code == _token_gen .TOKEN_SIGN_FAILED
225
+ assert excinfo .value ._auth_error_code == auth .TOKEN_SIGN_FAILED
226
226
assert iam_resp in str (excinfo .value )
227
227
finally :
228
228
firebase_admin .delete_app (app )
@@ -341,14 +341,6 @@ class TestVerifyIdToken(object):
341
341
'iat' : int (time .time ()) - 10000 ,
342
342
'exp' : int (time .time ()) - 3600
343
343
}),
344
- 'NoneToken' : None ,
345
- 'EmptyToken' : '' ,
346
- 'BoolToken' : True ,
347
- 'IntToken' : 1 ,
348
- 'ListToken' : [],
349
- 'EmptyDictToken' : {},
350
- 'NonEmptyDictToken' : {'a' : 1 },
351
- 'BadFormatToken' : 'foobar'
352
344
}
353
345
354
346
@pytest .mark .parametrize ('id_token' , valid_tokens .values (), ids = list (valid_tokens ))
@@ -390,11 +382,19 @@ def test_revoked_token_do_not_check_revoked(self, user_mgt_app, revoked_tokens,
390
382
assert claims ['admin' ] is True
391
383
assert claims ['uid' ] == claims ['sub' ]
392
384
385
+ @pytest .mark .parametrize ('id_token' , [None , '' , 'foobar' , True , 1 , [], {}, {'a' : 1 }])
386
+ def test_invalid_jwt (self , user_mgt_app , id_token ):
387
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
388
+ with pytest .raises (ValueError ):
389
+ auth .verify_id_token (id_token , app = user_mgt_app )
390
+
393
391
@pytest .mark .parametrize ('id_token' , invalid_tokens .values (), ids = list (invalid_tokens ))
394
392
def test_invalid_token (self , user_mgt_app , id_token ):
395
393
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
396
- with pytest .raises (ValueError ) :
394
+ with pytest .raises (auth . FirebaseAuthError ) as excinfo :
397
395
auth .verify_id_token (id_token , app = user_mgt_app )
396
+ assert excinfo .value .code == exceptions .INVALID_ARGUMENT
397
+ assert excinfo .value .auth_error_code == auth .INVALID_ID_TOKEN
398
398
399
399
def test_project_id_option (self ):
400
400
app = firebase_admin .initialize_app (
@@ -419,15 +419,17 @@ def test_project_id_env_var(self, env_var_app):
419
419
def test_custom_token (self , auth_app ):
420
420
id_token = auth .create_custom_token (MOCK_UID , app = auth_app )
421
421
_overwrite_cert_request (auth_app , MOCK_REQUEST )
422
- with pytest .raises (ValueError ) :
422
+ with pytest .raises (auth . FirebaseAuthError ) as excinfo :
423
423
auth .verify_id_token (id_token , app = auth_app )
424
+ assert excinfo .value .code == exceptions .INVALID_ARGUMENT
425
+ assert excinfo .value .auth_error_code == auth .INVALID_ID_TOKEN
424
426
425
427
def test_certificate_request_failure (self , user_mgt_app ):
426
428
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
427
429
with pytest .raises (auth .FirebaseAuthError ) as excinfo :
428
430
auth .verify_id_token (TEST_ID_TOKEN , app = user_mgt_app )
429
431
assert excinfo .value .code == exceptions .UNKNOWN
430
- assert excinfo .value .auth_error_code == ' CERTIFICATE_FETCH_FAILED'
432
+ assert excinfo .value .auth_error_code == auth . CERTIFICATE_FETCH_FAILED
431
433
432
434
433
435
class TestVerifySessionCookie (object ):
@@ -452,14 +454,6 @@ class TestVerifySessionCookie(object):
452
454
'iat' : int (time .time ()) - 10000 ,
453
455
'exp' : int (time .time ()) - 3600
454
456
}),
455
- 'NoneCookie' : None ,
456
- 'EmptyCookie' : '' ,
457
- 'BoolCookie' : True ,
458
- 'IntCookie' : 1 ,
459
- 'ListCookie' : [],
460
- 'EmptyDictCookie' : {},
461
- 'NonEmptyDictCookie' : {'a' : 1 },
462
- 'BadFormatCookie' : 'foobar' ,
463
457
'IDToken' : TEST_ID_TOKEN ,
464
458
}
465
459
@@ -496,11 +490,19 @@ def test_revoked_cookie_does_not_check_revoked(self, user_mgt_app, revoked_token
496
490
assert claims ['admin' ] is True
497
491
assert claims ['uid' ] == claims ['sub' ]
498
492
493
+ @pytest .mark .parametrize ('cookie' , [None , '' , 'foobar' , True , 1 , [], {}, {'a' : 1 }])
494
+ def test_invalid_jwt (self , user_mgt_app , cookie ):
495
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
496
+ with pytest .raises (ValueError ):
497
+ auth .verify_session_cookie (cookie , app = user_mgt_app )
498
+
499
499
@pytest .mark .parametrize ('cookie' , invalid_cookies .values (), ids = list (invalid_cookies ))
500
500
def test_invalid_cookie (self , user_mgt_app , cookie ):
501
501
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
502
- with pytest .raises (ValueError ) :
502
+ with pytest .raises (auth . FirebaseAuthError ) as excinfo :
503
503
auth .verify_session_cookie (cookie , app = user_mgt_app )
504
+ assert excinfo .value .code == exceptions .INVALID_ARGUMENT
505
+ assert excinfo .value .auth_error_code == auth .INVALID_SESSION_COOKIE
504
506
505
507
def test_project_id_option (self ):
506
508
app = firebase_admin .initialize_app (
@@ -522,15 +524,17 @@ def test_project_id_env_var(self, env_var_app):
522
524
def test_custom_token (self , auth_app ):
523
525
custom_token = auth .create_custom_token (MOCK_UID , app = auth_app )
524
526
_overwrite_cert_request (auth_app , MOCK_REQUEST )
525
- with pytest .raises (ValueError ) :
527
+ with pytest .raises (auth . FirebaseAuthError ) as excinfo :
526
528
auth .verify_session_cookie (custom_token , app = auth_app )
529
+ assert excinfo .value .code == exceptions .INVALID_ARGUMENT
530
+ assert excinfo .value .auth_error_code == auth .INVALID_SESSION_COOKIE
527
531
528
532
def test_certificate_request_failure (self , user_mgt_app ):
529
533
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
530
534
with pytest .raises (auth .FirebaseAuthError ) as excinfo :
531
535
auth .verify_session_cookie (TEST_SESSION_COOKIE , app = user_mgt_app )
532
536
assert excinfo .value .code == exceptions .UNKNOWN
533
- assert excinfo .value .auth_error_code == ' CERTIFICATE_FETCH_FAILED'
537
+ assert excinfo .value .auth_error_code == auth . CERTIFICATE_FETCH_FAILED
534
538
535
539
536
540
class TestCertificateCaching (object ):
0 commit comments