Repository navigation
Pass redemption handler dependencies as a struct - #7220
Conversation
The JWT-bearer and ID-JAG redemption constructors took seven and ten positional parameters, and the factory's build closure took eight, so every new dependency touched every constructor, both factory closures and about 25 test call sites. Collect the compose-time inputs in an issuanceDeps struct. Both constructors now take it and name their assertion form through a shared newIssuanceCore, which filters the trusted issuers once. The exported factory signatures, error texts and log lines are unchanged. Tests build handlers through one fixture builder. New tests pin that both constructors refuse bad dependencies with the same error, that the issuer-is-resource warning reads the unfiltered issuer list, and that both factories pass their inputs through to the handler. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Approve. This is a pure plumbing refactor and I found no behaviour change.
Design: Collapsing the long constructor and factory argument lists into one dependencies struct is made at the right place, jwt_bearer_handler.go, which builds the shared core that both the plain jwt-bearer and ID-JAG handlers use. All constructors involved are unexported, and both exported factories reach them through jwtBearerGrantFactory, so every entry point is covered and exported signatures are unchanged. Validation order and error strings, per-form policy filtering, and the ID-JAG audience warning (which still reads the unfiltered issuer list) all match the old behaviour, so nothing changes on upgrade. The struct also makes the planned extra dependencies cheap to add.
The one weak spot (not blocking): dependency validation is split between deps.validate() and newJWTBearerHandler, and the comment says a new field needs a check in one of the two. Moving the validator and token-endpoint checks into validate() would remove that trap.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7220 +/- ##
==========================================
- Coverage 81.62% 81.62% -0.01%
==========================================
Files 902 903 +1
Lines 91736 91738 +2
==========================================
- Hits 74882 74879 -3
- Misses 16849 16854 +5
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Dependency checks were split: newJWTBearerHandler checked the validator and token endpoint, issuanceDeps.validate checked the rest. A new field could be checked in one place and missed in the other. Move the validator and endpoint checks into a shared helper that both newJWTBearerHandler and issuanceDeps.validate call. newIssuanceCore now validates once, up front. Check order and error texts are unchanged. Co-authored-by: Mecatl <[email protected]>
|
@rdimitrov I took your validation point. The validator and token-endpoint checks now sit in a shared helper that both |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of c4b29ed: still approve. The new commit only moves the validator and token-endpoint checks into checkValidatorAndEndpoint, called by both newJWTBearerHandler and issuanceDeps.validate().
This closes the one weak spot from my earlier approval: all dependency checks now live in validate(), so a new field has one place to be checked. The check order (validator, endpoint, consumer, then the fosite dependencies) and the error texts are unchanged. newIssuanceCore validates once, up front, and builds the handler with the same two fields newJWTBearerHandler set. The design is unchanged, and CI is green.
🤖 Reviewed with Claude Code
Summary
The JWT-bearer and ID-JAG redemption constructors take seven and ten positional parameters, and the factory's
buildclosure takes eight. Every new dependency has to be threaded through every constructor, both factory closures and about 25 test call sites. Three planned changes each add one dependency (a per-client lifespan map, theauthorization_detailsregistry, and the subject resolver).This PR collects the compose-time inputs in one
issuanceDepsstruct, so each of those changes adds one field instead of editing every signature.issuanceDeps(new file) holds the inputs and owns the dependency checks and the per-issuer policy map.newJWTBearerIssuanceHandlerandnewIDJAGIssuanceHandlertake the struct. Both build on a sharednewIssuanceCore, which filters trusted issuers by assertion form in one place.jwtBearerGrantFactory'sbuildclosure takes the struct. The exportedJWTBearerIssuanceFactoryandIDJAGIssuanceFactorysignatures do not change.No behaviour changes: error texts, log lines and rejection reasons are the same as before.
Type of change
Test plan
go test -race ./pkg/authserver/server/tokenexchange/... ./pkg/authserver/golangci-lintandgo veton the same packagesNew tests pin that both constructors reject bad dependencies with the same error, that the issuer-is-resource startup warning counts every trusted issuer (not only those accepting
id_jag), and that both factories refuse to build without a shared validator.Changes
issuance_deps.goissuanceDepsstruct withvalidateandpoliciesForjwt_bearer_handler.gonewIssuanceCoreid_jag_handler.go*_test.gotestIssuanceDeps; call sites updated; new pinning testsSpecial notes for reviewers
Adding a dependency later, before and after:
buildclosure, both factory closures, ~25 test call sitesauthorization_detailsregistrynewJWTBearerHandler(the two-argument test seam) is left as is.