@@ -164,9 +164,9 @@ def test_session_cookies_with_tolerance(api_key):
164
164
dev_claims = {'premium' : True , 'subscription' : 'silver' }
165
165
custom_token = auth .create_custom_token ('user3' , dev_claims )
166
166
id_token = _sign_in (custom_token , api_key )
167
- expires_in = datetime .timedelta (seconds = 1 )
167
+ expires_in = datetime .timedelta (seconds = 300 )
168
168
session_cookie = auth .create_session_cookie (id_token , expires_in = expires_in )
169
- time .sleep (2 )
169
+ time .sleep (300 )
170
170
# expect this to fail because the cookie is expired
171
171
with pytest .raises (auth .ExpiredSessionCookieError ):
172
172
auth .verify_session_cookie (session_cookie )
@@ -596,20 +596,17 @@ def test_verify_id_token_revoked(new_user, api_key):
596
596
assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
597
597
598
598
def test_verify_id_token_tolerance (new_user , api_key ):
599
- # create token that expires in 1 second.
600
- custom_token = auth .create_custom_token (new_user .uid , expires_in = datetime .timedelta (seconds = 1 ))
601
- id_token = _sign_in (custom_token , api_key )
599
+ expired_id_token = _sign_in_with_password (new_user .email , 'password' , api_key )
602
600
time .sleep (1 )
601
+ # Verify the ID token with a tolerance of 0 seconds. This should
602
+ # raise an exception because the token is expired.
603
+ with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
604
+ auth .verify_id_token (expired_id_token , check_revoked = False , clock_skew_in_seconds = 0 )
605
+ assert str (excinfo .value ) == 'The Firebase ID token is expired.'
603
606
604
- # verify with tolerance of 0 seconds. This should fail.
605
- with pytest .raises (auth .ExpiredIdTokenError ) as excinfo :
606
- auth .verify_id_token (id_token , check_revoked = False , max_age = datetime .timedelta (seconds = 0 ))
607
- assert str (excinfo .value ) == 'The Firebase ID token has expired.'
608
-
609
- # verify with tolerance of 2 seconds. This should succeed.
610
- claims = auth .verify_id_token (id_token , check_revoked = False , max_age = datetime .timedelta (seconds = 2 ))
611
- assert claims ['sub' ] == new_user .uid
612
-
607
+ # Verify the ID token with a tolerance of 2 seconds. This should
608
+ # not raise an exception because the token is within the tolerance.
609
+ auth .verify_id_token (expired_id_token , check_revoked = False , clock_skew_in_seconds = 2 )
613
610
614
611
def test_verify_id_token_disabled (new_user , api_key ):
615
612
custom_token = auth .create_custom_token (new_user .uid )
@@ -652,8 +649,8 @@ def test_verify_session_cookie_revoked(new_user, api_key):
652
649
assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
653
650
654
651
def test_verify_session_cookie_tolerance (new_user , api_key ):
655
- expired_session_cookie = auth .create_session_cookie (_sign_in (auth .create_custom_token (new_user .uid ), api_key ), expires_in = datetime .timedelta (seconds = 1 ))
656
- time .sleep (1 )
652
+ expired_session_cookie = auth .create_session_cookie (_sign_in (auth .create_custom_token (new_user .uid ), api_key ), expires_in = datetime .timedelta (seconds = 300 ))
653
+ time .sleep (300 )
657
654
# Verify the session cookie with a tolerance of 0 seconds. This should
658
655
# raise an exception because the cookie is expired.
659
656
with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
0 commit comments