@@ -164,9 +164,9 @@ def test_session_cookies_with_tolerance(api_key):
164164 dev_claims = {'premium' : True , 'subscription' : 'silver' }
165165 custom_token = auth .create_custom_token ('user3' , dev_claims )
166166 id_token = _sign_in (custom_token , api_key )
167- expires_in = datetime .timedelta (seconds = 1 )
167+ expires_in = datetime .timedelta (seconds = 300 )
168168 session_cookie = auth .create_session_cookie (id_token , expires_in = expires_in )
169- time .sleep (2 )
169+ time .sleep (300 )
170170 # expect this to fail because the cookie is expired
171171 with pytest .raises (auth .ExpiredSessionCookieError ):
172172 auth .verify_session_cookie (session_cookie )
@@ -596,20 +596,17 @@ def test_verify_id_token_revoked(new_user, api_key):
596596 assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
597597
598598def 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 )
602600 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.'
603606
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 )
613610
614611def test_verify_id_token_disabled (new_user , api_key ):
615612 custom_token = auth .create_custom_token (new_user .uid )
@@ -652,8 +649,8 @@ def test_verify_session_cookie_revoked(new_user, api_key):
652649 assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
653650
654651def 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 )
657654 # Verify the session cookie with a tolerance of 0 seconds. This should
658655 # raise an exception because the cookie is expired.
659656 with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
0 commit comments