Skip to content

Commit 71b8a4e

Browse files
committed
Move the expiry-instant check to a top-level test
1 parent 527864f commit 71b8a4e

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎tests/client/auth/extensions/test_identity_assertion.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async def test_stored_token_is_reused_without_reauthorizing() -> None:
327327

328328
@pytest.mark.anyio
329329
async def test_stored_token_is_not_sent_at_its_expiry_instant() -> None:
330-
"""A stored token whose expiry equals the current time is already expired, so it is not attached."""
330+
"""SDK-defined: a token is expired at its `expires_in` deadline, like a JWT `exp` (RFC 7519 §4.1.4)."""
331331
requests: list[httpx2.Request] = []
332332
storage = InMemoryStorage(tokens=OAuthToken(access_token="cached", token_type="Bearer", expires_in=0))
333333
auth = make_provider(storage)

‎tests/client/test_auth.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ async def test_token_validity_checking(self, oauth_provider: OAuthClientProvider
244244
assert not context.is_token_valid()
245245
assert context.can_refresh_token() # Can still refresh
246246

247-
# At the expiry instant itself the token is already expired (RFC 7519 §4.1.4)
248-
with mock.patch("time.time", return_value=1_800_000_000.0):
249-
context.token_expiry_time = 1_800_000_000.0
250-
assert not context.is_token_valid()
251-
252247
# Remove refresh token
253248
context.current_tokens.refresh_token = None
254249
assert not context.can_refresh_token()
@@ -3672,3 +3667,13 @@ async def echo_callback() -> AuthorizationCodeResult:
36723667
await auth_flow.asend(httpx2.Response(200, request=final_req))
36733668
except StopAsyncIteration:
36743669
pass
3670+
3671+
3672+
def test_a_token_is_invalid_at_its_expiry_instant(oauth_provider: OAuthClientProvider):
3673+
"""SDK-defined: the deadline from `expires_in` is exclusive, like a JWT `exp` (RFC 7519 §4.1.4)."""
3674+
context = oauth_provider.context
3675+
with mock.patch("time.time", return_value=1_800_000_000.0):
3676+
token = OAuthToken(access_token="t", token_type="Bearer", expires_in=0)
3677+
context.current_tokens = token
3678+
context.update_token_expiry(token)
3679+
assert not context.is_token_valid()

0 commit comments

Comments
 (0)