Skip to content

[Rust] Harden OAuth token caching - #701

Open
danilotrninic-db wants to merge 1 commit into
mainfrom
issue-607-harden-oauth-token-caching
Open

[Rust] Harden OAuth token caching#701
danilotrninic-db wants to merge 1 commit into
mainfrom
issue-607-harden-oauth-token-caching

Conversation

@danilotrninic-db

Copy link
Copy Markdown

What changes are proposed in this pull request?

Parse the OAuth expires_in field from a quoted integer ("3600") in addition
to a plain JSON integer. Previously a token endpoint that returned expires_in
as a JSON string was read as "no lifetime reported," so the token was fetched
fresh on every stream creation instead of being cached.

How this addresses #607

#607 has three asks:

  1. Parse quoted expires_in — the code change above.
  2. Continue serving a valid cached token when a proactive refresh fails
    already implemented in TokenCache::get_or_fetch; this PR verifies it and
    adds tests pinning it. The one edge case (a refresh that succeeds with no
    usable expires_in) is deliberately left returning the fresh token uncached
    rather than falling back to the near-expiry cached one — a missing lifetime is
    missing metadata about the token, not evidence it is bad, and the freshly
    minted token is the more likely of the two to still be valid.
  3. Add deterministic tests — new TokenCache tests covering concurrency
    invalidation, cancellation, and expiry.

How is this tested?

cargo test --workspace (822 tests, green); cargo fmt --check and
cargo clippy clean. New unit tests cover parse_expires_in (integer, quoted
integer, whitespace, and reject cases) and the TokenCache behaviors above.

No live-server testing was needed: the sole production change is a pure parsing
function with no I/O or state, fully exercised by the unit tests above.

Parse the OAuth `expires_in` field from a quoted integer ("3600") in
addition to a plain JSON integer, so a token endpoint returning it as a
JSON string no longer drops the TTL and re-mints on every stream creation.

Add deterministic TokenCache tests covering concurrency,
invalidation, cancellation, and expiry.

Fixes #607.

Signed-off-by: Danilo Trninić <danilo.trninic@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant