@@ -164,20 +164,25 @@ 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 = 300 )
167+ expires_in = datetime .timedelta (seconds = 3 )
168168 session_cookie = auth .create_session_cookie (id_token , expires_in = expires_in )
169- time .sleep (300 )
169+ time .sleep (4 )
170170 # expect this to fail because the cookie is expired
171171 with pytest .raises (auth .ExpiredSessionCookieError ):
172172 auth .verify_session_cookie (session_cookie )
173173
174174 # expect this to succeed because we're within the tolerance
175- claims = auth .verify_session_cookie (session_cookie , check_revoked = False , tolerance = 2 )
175+ claims = auth .verify_session_cookie (session_cookie , check_revoked = False , clock_skew_seconds = 2 )
176176 assert claims ['uid' ] == 'user3'
177177 assert claims ['premium' ] is True
178178 assert claims ['subscription' ] == 'silver'
179179 assert claims ['iss' ].startswith ('https://session.firebase.google.com' )
180180
181+ with pytest .raises (ValueError ):
182+ auth .verify_session_cookie (session_cookie , clock_skew_seconds = - 1 )
183+ with pytest .raises (ValueError ):
184+ auth .verify_session_cookie (session_cookie , clock_skew_seconds = 61 )
185+
181186def test_session_cookie_error ():
182187 expires_in = datetime .timedelta (days = 1 )
183188 with pytest .raises (auth .InvalidIdTokenError ):
@@ -601,12 +606,12 @@ def test_verify_id_token_tolerance(new_user, api_key):
601606 # Verify the ID token with a tolerance of 0 seconds. This should
602607 # raise an exception because the token is expired.
603608 with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
604- auth .verify_id_token (expired_id_token , check_revoked = False , clock_skew_in_seconds = 0 )
609+ auth .verify_id_token (expired_id_token , check_revoked = False , clock_skew_seconds = 0 )
605610 assert str (excinfo .value ) == 'The Firebase ID token is expired.'
606611
607612 # Verify the ID token with a tolerance of 2 seconds. This should
608613 # 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 )
614+ auth .verify_id_token (expired_id_token , check_revoked = False , clock_skew_seconds = 2 )
610615
611616def test_verify_id_token_disabled (new_user , api_key ):
612617 custom_token = auth .create_custom_token (new_user .uid )
@@ -649,17 +654,39 @@ def test_verify_session_cookie_revoked(new_user, api_key):
649654 assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
650655
651656def test_verify_session_cookie_tolerance (new_user , api_key ):
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+ expired_session_cookie = auth .create_session_cookie (
658+ _sign_in (auth .create_custom_token (new_user .uid ), api_key ),
659+ expires_in = datetime .timedelta (seconds = 3 )
660+ )
661+ time .sleep (3 )
654662 # Verify the session cookie with a tolerance of 0 seconds. This should
655663 # raise an exception because the cookie is expired.
656664 with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
657- auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_in_seconds = 0 )
665+ auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_seconds = 0 )
658666 assert str (excinfo .value ) == 'The Firebase session cookie is expired.'
659667
660668 # Verify the session cookie with a tolerance of 2 seconds. This should
661669 # not raise an exception because the cookie is within the tolerance.
662- auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_in_seconds = 2 )
670+ auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_seconds = 2 )
671+
672+ def test_verify_session_cookie_clock_skew_seconds_range (new_user , api_key ):
673+ expired_session_cookie = auth .create_session_cookie (
674+ _sign_in (auth .create_custom_token (new_user .uid ), api_key ),
675+ expires_in = datetime .timedelta (seconds = 3 )
676+ )
677+ # Verify the session cookie with a tolerance of 0 seconds. This should
678+ # raise an exception because the cookie is expired.
679+ with pytest .raises (ValueError ) as excinfo :
680+ auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_seconds = - 1 )
681+ assert str (excinfo .value ) == 'clock_skew_seconds must be between 0 and 60.'
682+ with pytest .raises (ValueError ) as excinfo :
683+ auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_seconds = 61 )
684+ assert str (excinfo .value ) == 'clock_skew_seconds must be between 0 and 60.'
685+
686+ # Verify the session cookie with a tolerance of 2 seconds. This should
687+ # not raise an exception because the cookie is within the tolerance.
688+ auth .verify_session_cookie (expired_session_cookie , check_revoked = False , clock_skew_seconds = 2 )
689+
663690
664691def test_verify_session_cookie_disabled (new_user , api_key ):
665692 custom_token = auth .create_custom_token (new_user .uid )
0 commit comments