Repository navigation
test(auth): cover non-401 token errors and expiry boundaries - #432
Merged
Merged
Conversation
The 401 path was well covered; nothing drove a 5xx, a transport error, or a 200 whose body cannot yield a token, and nothing ever moved the clock. So the raise_for_status branch, the "missing access_token or expires_in" branch, the skew calculation and the 401 cooldown were all unasserted in both providers. These add, for the sync and async providers: a 5xx and a transport error, each asserted to be retried rather than memoized and to leave no tarpit file behind, which is the distinction that matters for a non-401; five malformed 200 bodies, asserted to cache nothing in memory or on disk; and, driven through the injected clock so they are deterministic, reuse just before the skew-adjusted expiry and a refetch just after, the clamp that keeps a lifetime shorter than the skew from landing in the past, an expired file-cached entry replaced and unlinked even when the refetch fails, a still-valid entry served without a request, and the 401 cooldown on both sides of its boundary. Checked that they bite: memoizing every status, not only 401, fails the non-401 tests; removing the skew fails the expiry tests. Closes #427 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Async expiry and disk-cache behavior lack test coverage, and the short-lifetime test does not verify that the stored expiry is clamped to the current time.
2 open issues
What changed in this PR
Extends the SDK’s OAuth acceptance tests to address the coverage gaps in #427, without changing production code.
Changes:
- Tests non-401 HTTP errors, transport failures, and malformed token responses for sync and async providers.
- Uses
ManualClockto check token reuse, refresh, and 401 cooldown timing without sleeps. - Adds sync-provider tests for short token lifetimes and disk-cache expiry, deletion, and reuse.
| File | Description |
|---|---|
tests/acceptance/test_pluggable_auth.py |
Adds provider helpers, mocked token responses, and deterministic failure and expiry tests. |
Review effort: Balanced
…c provider From Copilot's review. The short-lifetime test asserted only that every call refetched, which removing max(0.0, ...) also satisfies -- an expiry ten seconds in the past looks identical from the outside. It now asserts the stored expiry equals the clock's current time, so the clamp the test is named after is what it checks; both sync and async fail against that mutant. The clamp and the three on-disk cache cases were sync-only, although the async provider has its own expiry calculation and its own cache loading. All four now have async counterparts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda
Resolve the add/add conflict at the end of tests/acceptance/test_pluggable_auth.py: keep this branch's token-endpoint failure and expiry-boundary cases, and main's OAuth User-Agent cases from #477. The two sets are independent; no test was changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda
Contributor
|
Successfully created backport PR for |
This was referenced Nov 30, 2026
Merged
Contributor
|
Successfully created backport PR for |
jwulf
pushed a commit
that referenced
this pull request
Nov 30, 2026
…535) * test(auth): cover non-401 token errors and expiry boundaries The 401 path was well covered; nothing drove a 5xx, a transport error, or a 200 whose body cannot yield a token, and nothing ever moved the clock. So the raise_for_status branch, the "missing access_token or expires_in" branch, the skew calculation and the 401 cooldown were all unasserted in both providers. These add, for the sync and async providers: a 5xx and a transport error, each asserted to be retried rather than memoized and to leave no tarpit file behind, which is the distinction that matters for a non-401; five malformed 200 bodies, asserted to cache nothing in memory or on disk; and, driven through the injected clock so they are deterministic, reuse just before the skew-adjusted expiry and a refetch just after, the clamp that keeps a lifetime shorter than the skew from landing in the past, an expired file-cached entry replaced and unlinked even when the refetch fails, a still-valid entry served without a request, and the 401 cooldown on both sides of its boundary. Checked that they bite: memoizing every status, not only 401, fails the non-401 tests; removing the skew fails the expiry tests. Closes #427 Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda * chore(auth): pin the clamped expiry, and mirror the cases on the async provider From Copilot's review. The short-lifetime test asserted only that every call refetched, which removing max(0.0, ...) also satisfies -- an expiry ten seconds in the past looks identical from the outside. It now asserts the stored expiry equals the clock's current time, so the clamp the test is named after is what it checks; both sync and async fail against that mutant. The clamp and the three on-disk cache cases were sync-only, although the async provider has its own expiry calculation and its own cache loading. All four now have async counterparts. Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda --------- (cherry picked from commit a2da089) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
jwulf
added a commit
that referenced
this pull request
Nov 30, 2026
…#432 to stable/9) (#536) * test(auth): cover non-401 token errors and expiry boundaries (#432) * test(auth): cover non-401 token errors and expiry boundaries The 401 path was well covered; nothing drove a 5xx, a transport error, or a 200 whose body cannot yield a token, and nothing ever moved the clock. So the raise_for_status branch, the "missing access_token or expires_in" branch, the skew calculation and the 401 cooldown were all unasserted in both providers. These add, for the sync and async providers: a 5xx and a transport error, each asserted to be retried rather than memoized and to leave no tarpit file behind, which is the distinction that matters for a non-401; five malformed 200 bodies, asserted to cache nothing in memory or on disk; and, driven through the injected clock so they are deterministic, reuse just before the skew-adjusted expiry and a refetch just after, the clamp that keeps a lifetime shorter than the skew from landing in the past, an expired file-cached entry replaced and unlinked even when the refetch fails, a still-valid entry served without a request, and the 401 cooldown on both sides of its boundary. Checked that they bite: memoizing every status, not only 401, fails the non-401 tests; removing the skew fails the expiry tests. Closes #427 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda * chore(auth): pin the clamped expiry, and mirror the cases on the async provider From Copilot's review. The short-lifetime test asserted only that every call refetched, which removing max(0.0, ...) also satisfies -- an expiry ten seconds in the past looks identical from the outside. It now asserts the stored expiry equals the clock's current time, so the clamp the test is named after is what it checks; both sync and async fail against that mutant. The clamp and the three on-disk cache cases were sync-only, although the async provider has its own expiry calculation and its own cache loading. All four now have async counterparts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda --------- Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit a2da089) * test: use test-local clock in OAuth backport tests (stable/9 lacks runtime clock) Signed-off-by: Josh Wulf <josh.wulf@camunda.com> --------- Signed-off-by: Josh Wulf <josh.wulf@camunda.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Josh Wulf <josh.wulf@camunda.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Requested by Joshua Wulf · Slack thread
Before: The 401 path was well covered, but no test ever made the token endpoint return a 5xx, fail at the transport, or answer 200 with a body that cannot yield a token — and no test ever moved the clock. The
raise_for_statusbranch, the "missing access_token or expires_in" branch, the skew calculation and the 401 cooldown were unasserted in both the sync and the async provider. The twoResponse(500, ...)occurrences in the file arehandler_should_not_runguards; they assert the endpoint is not called and never reach the error path.After: Every one of those paths is driven and its consequence asserted, for both providers, deterministically.
Twenty-six new tests close the negative-case baseline for token-endpoint errors and expiry boundaries.
How:
httpx.MockTransportfor the failures, and the providers' already-injectableClockfor the timing, so nothing sleeps and nothing depends on wall-clock time.access_token, missingexpires_in, empty body, empty token, zero lifetime. Each is rejected, and nothing is cached in memory or on disk.expires_at - 1and refetched atexpires_at + 1, whereexpires_atisnow + 3600 - max(30, 5%); and a 20-second lifetime, shorter than the 30-second skew floor, clamping tonowso the token is never treated as valid, rather than landing in the past and being the same behaviour by accident.These are tests for a gap, not a fix, so there is no production change and no red/green pair. Instead I checked that they bite, by mutating the runtime and confirming the failures (all reverted): memoizing every status rather than only 401 fails the two non-401 tests; removing the skew fails the expiry tests; and removing the
max(0.0, ...)clamp fails the two clamp tests.After Copilot's review the clamp test now asserts the stored expiry equals the clock's current time, rather than only that every call refetched — which an expiry in the past also satisfies — and the clamp and the three on-disk cache cases gained async counterparts, since the async provider has its own expiry calculation and its own cache loading.
Verification on Python 3.13 (
make generate-only, then the Makefile validation steps):ruff check .,ty checkandty check examples/are clean;pytest tests/acceptanceis 868 passed, 1 skipped (842 before). Nogenerated/orstubs/change, so this is a single commit.Known overlap: none in code. #425 adds a separate sentinel-secret file that drives some of the same auth paths for a different purpose (non-disclosure, not behaviour); the two touch different files and can merge in any order.
Closes #427
🤖 Generated with Claude Code
https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda