Repository navigation
Propagate the request replaced by AuthenticationFunc to the next handler - #96
Open
draarivpatel-ui wants to merge 1 commit into
Open
draarivpatel-ui wants to merge 1 commit into
draarivpatel-ui wants to merge 1 commit into
Conversation
An AuthenticationFunc that attaches claims via RequestValidationInput.Request = r.WithContext(...) had no effect: after validation the middleware served the original request, so the context values, and any body left by KeepValidatedValue on the replacement request, never reached the handler. Serve the request left on the RequestValidationInput instead, keeping the restored RequestURI when a Prefix is configured. Fixes oapi-codegen#60
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.
Fixes #60
Problem
An
AuthenticationFuncthat attaches claims to the request by replacingRequestValidationInput.Request(the only channelopenapi3filterexposes) had no effect: afterValidateRequest, the middleware served the original*http.Requestto the next handler, so the new context never reached it. The validated body left byKeepValidatedValueon the replacement request was lost the same way.Fix
On successful validation, serve
RequestValidationInput.Requestwhen it differs from the incoming request, in both validation paths (OapiRequestValidator/ErrorHandlerandErrorHandlerWithOpts).RequestURIis a plain field rather than part of the shared*url.URL, so the restored value is copied onto the replacement whenOptions.Prefixstripped it.Test
Added
TestAuthenticationFuncRequestPropagation, which runs anAuthenticationFuncthat replacesinput.RequestValidationInput.Requestwith aWithContextcopy carrying a value, and asserts the downstream handler sees the value and the original path. It covers both code paths and fails before the fix (got <nil>) in each.go test -cover ./...passes (84.0%).