Repository navigation
fix: cache the app JWT with a custom client, reject a bad installation ID - #62
Merged
Merged
Conversation
…n ID Two inconsistencies where a path diverged from its equivalent. WithHTTPClient wired the raw application token source into the transport while NewInstallationTokenSource wraps the same source in oauth2.ReuseTokenSource. Supplying a custom HTTP client therefore re-signed a JWT on every installation-token request instead of reusing one. It now wraps the source the same way. A zero App ID is rejected at construction, but a zero installation ID was not, so it reached GitHub as /app/installations/0/access_tokens and came back as a 404 that reads like an outage rather than a misconfiguration. Non-positive IDs now fail through the existing configuration-error path, before any network call. Also replaces a hand-rolled substring matcher in the tests with strings.Contains.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62 +/- ##
==========================================
+ Coverage 96.44% 96.50% +0.06%
==========================================
Files 4 4
Lines 281 286 +5
==========================================
+ Hits 271 276 +5
Misses 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Two paths diverged from their own equivalents.
WithHTTPClientwired the raw application token source into the transport, whileNewInstallationTokenSourcewraps that same source inoauth2.ReuseTokenSource, so passing a custom HTTP client re-signed a JWT on every installation-token request. Separately, a zero App ID is rejected at construction but a zero installation ID was not, so it reached GitHub as/app/installations/0/access_tokensand returned a 404 that reads like an outage rather than a misconfiguration.Changes
WithHTTPClientwraps the source inoauth2.ReuseTokenSource, matching the default transport; a test asserts one signing across three installation-token fetches, where it was three beforestrings.ContainsRationale
Both fixes route through mechanisms the package already has: the same
ReuseTokenSourcewrapper the default transport uses, and the samesetConfigErrpath that already reports a nil HTTP client and an unparseable base URL. Neither adds public API or a new failure mode.Migration Notes
A non-positive installation ID now fails at the first
Token()call instead of returning a 404 from GitHub. Both tests were written to fail against the current code first, then fixed.