-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WithCustomHeader Function does not replace existing headers #460
Comments
I would assume normal usage would be to use a combination request filters / state handlers to check the existing token matches a particular format and then provide a valid token in the request to be verified. see 4 https://docs.pact.io/provider/handling_auth#4-modify-the-request-to-use-real-credentials
When you say you get two headers, are the different in casing? Are you able to provide any logs? |
Yeah, this is what I am doing in the above setup by adding a new, valid token. There is the option of creating a new middleware within the API itself to check for a specific value before it hits the auth middleware, but I would ideally like to avoid this.
Again, I'm unsure of the exact result, but I'd wager you are correct that their are two different headers with the request.
|
So it does indeed just add it (in the core), without considering others, which I assume is by design. If it is the case, maybe we need to warn, or error to the user, in the core, unless we do want to allow us to overwrite an existing error. this is the user facing side pact-net/src/PactNet/Verifier/PactVerifierSource.cs Lines 97 to 101 in 9eb58b3
this is the native interop, so this is calling our rust code pact-net/src/PactNet/Verifier/InteropVerifierProvider.cs Lines 129 to 130 in 9eb58b3
ffi code for pactffi_verifier_add_custom_header which calls add_custom_header to insert some Which I think gets setup here which believe to be processed here We may want to consider What should happen if
Why would you want to add a custom header, without considering state |
A minimal reproducible example You can create an example from the code in pact-net, or our example-consumer-dotnet / example-provider-dotnet repos I want to confirm if there is indeed two headers, I can't imagine you would have two headers with the same casing, you should get one overwritten, however its possible there might be an |
Just curious, are you using bi-directional, as well as consumer driven? So you have a provider OAS to verify against, and then also verifying a running provider with traditional consumer driven Pact? Just as there traditionally wouldn't be a verification task as you show, if you use bi-directional only |
Well in this case, we are the provider, but yes, we are also using the consumer's pact json and running it against our API as the provider.
This would take me some time to do, I'll see if I can get to this today or tomorrow. In the meantime, I ran some tests locally and can provide the requests /responses I see in Fiddler. Overall, it appears as if .WithCustomHeader does nothing if the header already exists, as I'm not seeing a duplicate header (see fiddler response below). Our setup: The consumer pact (removed some data that isn't needed for this discussion): Fiddler Raw request: Response didn't give much detail but threw a 500 because the JWT wasn't parseable (since it wasn't replaced and is just 'Test') |
Cheers buddy! That is useful, I'm not a pact-net maintainer, nor a pact-rust maintainer but do use the pact ffi library, so the information you've provided is useful. Something else we or others could do, is add test cases here pact-net/tests/PactNet.Tests/Verifier/PactVerifierSourceTests.cs Lines 71 to 78 in 9eb58b3
This uses a mock provider so under if it actually calls the native core, I'm going to a couple of tests with the ffi directly :) |
This commit pact-foundation/pact-reference@cd83d3e shows the issue with php, directly using the pact_ffi libarary.
Code examples below. This will probably want transferring to the pact-reference repository and discussing with @uglyog as to whether this is expected behaviour or a bug consumer 1
consumer 2's headers
|
Yeah this is a problem in the FFI rather than PactNet itself. It'll need a tracking issue |
Okay, should I create that? If so, what repo should that go under? |
Hey @RChild0916 sorry, we should have said (or done it for you), if you could raise the issue against https://github.com/pact-foundation/pact-reference/ and mention this issue that would be great |
This is useful if the provider wants to use real authentication flow for the contract tests. Disclaimer: `pactffi_verifier_add_custom_header` function unfortunately is not able to override an existing header, so using this requires the pact to not include the authorization header in the first place. This can either be done by simply not using it on the consumer-side test or removing it somehow before publishing the pact. Although I worked through the following issues: - pact-foundation/pact-net#460 - pact-foundation/pact-reference#275 from which the latter is actually marked as closed, and the fix is allegedly included in the pact-ffi version that we use, it still did not override an existing header. I tried bumping to a higher version as well but without any luck. I will create an issue to pact-foundation to try to get clarity on this.
Hello all!
I'm working with pact-net as a provider using pactflow which has some bi-directional testing, and ran into an interesting issue.
We recently added authentication to our API, and needed to add an auth header using the .WithCustomHeader method like so:
`
`
The "WithCustomHeader" function seems to have an issue, which I haven't been able to discern exactly but believe it is one of two things:
Either way, the end result is the same in that our API grabs the old token that exists within the pact file and attempts to use it, sees it is expired and throws a 401.
To get this working, we removed the Authorization header from the pact file and everything ran clean from the provider side, but this lead to a new issue within pactflow. Pactflow will check the request headers against our API's OAS, and sees that the authorization header is missing and fails for the consumer side check.
Is it possible to get new functionality to allow users to replace existing headers?
The text was updated successfully, but these errors were encountered: