[Rust] Harden OAuth token caching - #701
Open
danilotrninic-db wants to merge 1 commit into
Open
Conversation
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>
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.
What changes are proposed in this pull request?
Parse the OAuth
expires_infield from a quoted integer ("3600") in additionto a plain JSON integer. Previously a token endpoint that returned
expires_inas 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:
expires_in— the code change above.already implemented in
TokenCache::get_or_fetch; this PR verifies it andadds tests pinning it. The one edge case (a refresh that succeeds with no
usable
expires_in) is deliberately left returning the fresh token uncachedrather 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.
TokenCachetests covering concurrencyinvalidation, cancellation, and expiry.
How is this tested?
cargo test --workspace(822 tests, green);cargo fmt --checkandcargo clippyclean. New unit tests coverparse_expires_in(integer, quotedinteger, whitespace, and reject cases) and the
TokenCachebehaviors 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.