@@ -164,20 +164,25 @@ 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 = 300 )
167
+ expires_in = datetime .timedelta (seconds = 3 )
168
168
session_cookie = auth .create_session_cookie (id_token , expires_in = expires_in )
169
- time .sleep (300 )
169
+ time .sleep (4 )
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 )
173
173
174
174
# 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 )
176
176
assert claims ['uid' ] == 'user3'
177
177
assert claims ['premium' ] is True
178
178
assert claims ['subscription' ] == 'silver'
179
179
assert claims ['iss' ].startswith ('https://session.firebase.google.com' )
180
180
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
+
181
186
def test_session_cookie_error ():
182
187
expires_in = datetime .timedelta (days = 1 )
183
188
with pytest .raises (auth .InvalidIdTokenError ):
@@ -601,12 +606,12 @@ def test_verify_id_token_tolerance(new_user, api_key):
601
606
# Verify the ID token with a tolerance of 0 seconds. This should
602
607
# raise an exception because the token is expired.
603
608
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 )
605
610
assert str (excinfo .value ) == 'The Firebase ID token is expired.'
606
611
607
612
# Verify the ID token with a tolerance of 2 seconds. This should
608
613
# 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 )
610
615
611
616
def test_verify_id_token_disabled (new_user , api_key ):
612
617
custom_token = auth .create_custom_token (new_user .uid )
@@ -649,17 +654,39 @@ def test_verify_session_cookie_revoked(new_user, api_key):
649
654
assert claims ['iat' ] * 1000 >= user .tokens_valid_after_timestamp
650
655
651
656
def 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 )
654
662
# Verify the session cookie with a tolerance of 0 seconds. This should
655
663
# raise an exception because the cookie is expired.
656
664
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 )
658
666
assert str (excinfo .value ) == 'The Firebase session cookie is expired.'
659
667
660
668
# Verify the session cookie with a tolerance of 2 seconds. This should
661
669
# 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
+
663
690
664
691
def test_verify_session_cookie_disabled (new_user , api_key ):
665
692
custom_token = auth .create_custom_token (new_user .uid )
0 commit comments