403 forbidden when using proxy wiremock in c# unit test #670

Open
opened 2025-12-29 08:32:20 +01:00 by adam · 5 comments
Owner

Originally created by @fl0l-gouze on GitHub (Feb 27, 2025).

Originally assigned to: @StefH on GitHub.

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I’ve created an unit test using wiremocknet. I’ve setup so that instead of targeting https://mycompany/private/ it instead target http://localhost:8080/ that forward it then to the https://myco mpany/private

By using Wiremockserver.Start and setting a Logger and an proxyAndRecordSettings.

The issue is that I always have 403 forbidden.
I know that the forward work otherwise I would have no response.
I know the header with authentication are correctly feeded to my http client as I have only switch the url.

By using postman I can see my header correctly fed (if I’m not mistaken)

But it seems wiremock net jinx my auth
Describe the solution you'd like
A clear and concise description of what you want to happen.

Correct forward of header for auth when calling api in forward and record mode

Describe alternatives you've considered
Installed wiremock Java locally to do the forward and record and it worked

Is your feature request supported by WireMock (java version)? Please provide details.
Wiremock Java locally works but I want the net version to be able to have an unit test that record all call to external api so that after record all call are mocked and stored

Additional context
Add any other context or screenshots about the feature request here.

Originally created by @fl0l-gouze on GitHub (Feb 27, 2025). Originally assigned to: @StefH on GitHub. **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] I’ve created an unit test using wiremocknet. I’ve setup so that instead of targeting https://mycompany/private/ it instead target http://localhost:8080/ that forward it then to the https://myco mpany/private By using Wiremockserver.Start and setting a Logger and an proxyAndRecordSettings. The issue is that I always have 403 forbidden. I know that the forward work otherwise I would have no response. I know the header with authentication are correctly feeded to my http client as I have only switch the url. By using postman I can see my header correctly fed (if I’m not mistaken) But it seems wiremock net jinx my auth **Describe the solution you'd like** A clear and concise description of what you want to happen. Correct forward of header for auth when calling api in forward and record mode **Describe alternatives you've considered** Installed wiremock Java locally to do the forward and record and it worked **Is your feature request supported by [WireMock (java version)](https://www.wiremock.org)? Please provide details.** Wiremock Java locally works but I want the net version to be able to have an unit test that record all call to external api so that after record all call are mocked and stored **Additional context** Add any other context or screenshots about the feature request here.
adam added the feature label 2025-12-29 08:32:20 +01:00
Author
Owner

@fl0l-gouze commented on GitHub (Feb 28, 2025):

For information, the auth information are passed through to my http client by :
Httpclient.DefaultRequestHeaders.Authorization = new AuthentificationHeaderValue(« Basic », Convert.ToBase64String(Encoding.ASCII.GetBytes($«{username}:{password} »)));

I feed both of theses value through
WebProxySettings = new WebProxySettings() {. Username = username, Password = password }

@fl0l-gouze commented on GitHub (Feb 28, 2025): For information, the auth information are passed through to my http client by : `Httpclient.DefaultRequestHeaders.Authorization = new AuthentificationHeaderValue(« Basic », Convert.ToBase64String(Encoding.ASCII.GetBytes($«{username}:{password} »))); ` I feed both of theses value through `WebProxySettings = new WebProxySettings() {. Username = username, Password = password }`
Author
Owner

@fl0l-gouze commented on GitHub (Mar 17, 2025):

I managed to fix my issue, it’s indeed a « shortcoming » of wiremock.net when forwarding a http call to a https call over proxy.

Natively, wiremock Java set up the proxy prefix. This is not the case on wiremock.net
You need to either twist your url construction or set correctly the proxy prefix into the header (took the first option as quick fix only impacting test code)

Will enhance issue and problem but this is a real feature for me.

@fl0l-gouze commented on GitHub (Mar 17, 2025): I managed to fix my issue, it’s indeed a « shortcoming » of wiremock.net when forwarding a http call to a https call over proxy. Natively, wiremock Java set up the proxy prefix. This is not the case on wiremock.net You need to either twist your url construction or set correctly the proxy prefix into the header (took the first option as quick fix only impacting test code) Will enhance issue and problem but this is a real feature for me.
Author
Owner

@StefH commented on GitHub (May 16, 2025):

@fl0l-gouze
Can you please provide clear explanation of what is happening and what should happen?
Provide example project if possible.

@StefH commented on GitHub (May 16, 2025): @fl0l-gouze Can you please provide clear explanation of what is happening and what should happen? Provide example project if possible.
Author
Owner

@StefH commented on GitHub (Oct 5, 2025):

@fl0l-gouze
Can you please provide clear explanation of what is happening and what should happen?
Provide example project if possible.

@StefH commented on GitHub (Oct 5, 2025): @fl0l-gouze Can you please provide clear explanation of what is happening and what should happen? Provide example project if possible.
Author
Owner

@StefH commented on GitHub (Dec 9, 2025):

@fl0l-gouze
Can you please provide clear explanation of what is happening and what should happen?
Provide example project if possible.

@StefH commented on GitHub (Dec 9, 2025): @fl0l-gouze Can you please provide clear explanation of what is happening and what should happen? Provide example project if possible.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#670