@@ -440,14 +440,19 @@ class TestVerifyIdToken:
440
440
'iat' : int (time .time ()) - 10000 ,
441
441
'exp' : int (time .time ()) - 3600
442
442
}),
443
+ 'ExpiredTokenShort' : _get_id_token ({
444
+ 'iat' : int (time .time ()) - 10000 ,
445
+ 'exp' : int (time .time ()) - 30
446
+ }),
443
447
'BadFormatToken' : 'foobar'
444
448
}
445
449
446
450
tokens_accepted_in_emulator = [
447
451
'NoKid' ,
448
452
'WrongKid' ,
449
453
'FutureToken' ,
450
- 'ExpiredToken'
454
+ 'ExpiredToken' ,
455
+ 'ExpiredTokenShort' ,
451
456
]
452
457
453
458
def _assert_valid_token (self , id_token , app ):
@@ -555,6 +560,20 @@ def test_expired_token(self, user_mgt_app):
555
560
assert excinfo .value .cause is not None
556
561
assert excinfo .value .http_response is None
557
562
563
+ def test_expired_token_with_tolerance (self , user_mgt_app ):
564
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
565
+ id_token = self .invalid_tokens ['ExpiredTokenShort' ]
566
+ if _is_emulated ():
567
+ self ._assert_valid_token (id_token , user_mgt_app )
568
+ return
569
+ claims = auth .verify_id_token (id_token , app = user_mgt_app ,
570
+ clock_skew_seconds = 60 )
571
+ assert claims ['admin' ] is True
572
+ assert claims ['uid' ] == claims ['sub' ]
573
+ with pytest .raises (auth .ExpiredIdTokenError ):
574
+ auth .verify_id_token (id_token , app = user_mgt_app ,
575
+ clock_skew_seconds = 20 )
576
+
558
577
def test_project_id_option (self ):
559
578
app = firebase_admin .initialize_app (
560
579
testutils .MockCredential (), options = {'projectId' : 'mock-project-id' }, name = 'myApp' )
@@ -619,6 +638,10 @@ class TestVerifySessionCookie:
619
638
'iat' : int (time .time ()) - 10000 ,
620
639
'exp' : int (time .time ()) - 3600
621
640
}),
641
+ 'ExpiredCookieShort' : _get_session_cookie ({
642
+ 'iat' : int (time .time ()) - 10000 ,
643
+ 'exp' : int (time .time ()) - 30
644
+ }),
622
645
'BadFormatCookie' : 'foobar' ,
623
646
'IDToken' : TEST_ID_TOKEN ,
624
647
}
@@ -627,7 +650,8 @@ class TestVerifySessionCookie:
627
650
'NoKid' ,
628
651
'WrongKid' ,
629
652
'FutureCookie' ,
630
- 'ExpiredCookie'
653
+ 'ExpiredCookie' ,
654
+ 'ExpiredCookieShort' ,
631
655
]
632
656
633
657
def _assert_valid_cookie (self , cookie , app , check_revoked = False ):
@@ -715,6 +739,20 @@ def test_expired_cookie(self, user_mgt_app):
715
739
assert excinfo .value .cause is not None
716
740
assert excinfo .value .http_response is None
717
741
742
+ def test_expired_cookie_with_tolerance (self , user_mgt_app ):
743
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
744
+ cookie = self .invalid_cookies ['ExpiredCookieShort' ]
745
+ if _is_emulated ():
746
+ self ._assert_valid_cookie (cookie , user_mgt_app )
747
+ return
748
+ claims = auth .verify_session_cookie (cookie , app = user_mgt_app , check_revoked = False ,
749
+ clock_skew_seconds = 59 )
750
+ assert claims ['admin' ] is True
751
+ assert claims ['uid' ] == claims ['sub' ]
752
+ with pytest .raises (auth .ExpiredSessionCookieError ):
753
+ auth .verify_session_cookie (cookie , app = user_mgt_app , check_revoked = False ,
754
+ clock_skew_seconds = 29 )
755
+
718
756
def test_project_id_option (self ):
719
757
app = firebase_admin .initialize_app (
720
758
testutils .MockCredential (), options = {'projectId' : 'mock-project-id' }, name = 'myApp' )
0 commit comments