Server returns unexpected 400 unless I use Fiddler which fixes the issue #511

Closed
opened 2025-12-29 15:25:41 +01:00 by adam · 5 comments
Owner

Originally created by @laura-rodriguez on GitHub (May 18, 2023).

Describe the bug

I have a unit test to test rate limits that requires two stub responses. The first one is to get an OAuth token (200 - access token) to authorize a request, and the second one which returns a 429. When I run the test from Visual Studio or CCI, the test fails because the response status is 400 instead of 429. However, when I use Fiddler (which I used for debugging) the test works just fine, and I'm not able to reproduce the issue.

Expected behavior:

I expect the test to return 200 with access token for the first call (this works fine), and then a 429 instead of 400.

Test to reproduce

The exact test code to reproduce it is public and can be found here.

Other related info

Provide additional information if any.
Test failing:
image
Test passing when Fiddler is capturing
image

Originally created by @laura-rodriguez on GitHub (May 18, 2023). ### Describe the bug [I have a unit test](https://github.com/okta/okta-sdk-dotnet/pull/647/files#diff-7f09bbe57f1259168b5379acf39db39b624d898edd7424ae1a3208a338c39148R150) to test rate limits that requires two stub responses. The first one is to get an OAuth token (200 - access token) to authorize a request, and the second one which returns a 429. When I run the test from Visual Studio or CCI, the test fails because the response status is 400 instead of 429. However, when I use Fiddler (which I used for debugging) the test works just fine, and I'm not able to reproduce the issue. ### Expected behavior: I expect the test to return 200 with access token for the first call (this works fine), and then a 429 instead of 400. ### Test to reproduce The exact test code to reproduce it is public and can be found [here](https://github.com/okta/okta-sdk-dotnet/pull/647/files#diff-7f09bbe57f1259168b5379acf39db39b624d898edd7424ae1a3208a338c39148R150). ### Other related info Provide additional information if any. Test failing: ![image](https://github.com/WireMock-Net/WireMock.Net/assets/16751130/047a4aab-1ccd-43b4-9e57-e06046970a95) Test passing when Fiddler is capturing ![image](https://github.com/WireMock-Net/WireMock.Net/assets/16751130/22b79e03-e004-482a-aa4b-e87ef0c276e7)
adam added the question label 2025-12-29 15:25:41 +01:00
adam closed this issue 2025-12-29 15:25:41 +01:00
Author
Owner

@StefH commented on GitHub (May 19, 2023):

It is a strange bug. It seems that the request is invalid and is not handled by WireMock?

I will take a look.

@StefH commented on GitHub (May 19, 2023): It is a strange bug. It seems that the request is invalid and is not handled by WireMock? I will take a look.
Author
Owner

@StefH commented on GitHub (May 19, 2023):

@laura-rodriguez

I think I found your issue.

This mapping is setup like:
image

However WireMock.Net will return the access_token as defined, so with \r\n and with spaces.

This response is added to headers using this code:
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + token);

And apparently RestSharp breaks on the \r\n.
Because when I do this: token.Replace("\r", "").Replace("\n", "") it works.

(Probably Fiddler tries to repair the data which is probably the explanation that it works with fiddler)

The next issue is that the errorLink is not valid json:
image

@StefH commented on GitHub (May 19, 2023): @laura-rodriguez I think I found your issue. This mapping is setup like: ![image](https://github.com/WireMock-Net/WireMock.Net/assets/249938/52420eee-93f9-4e3a-860a-48e06cf01116) However WireMock.Net will return the access_token as defined, so with \r\n and with spaces. This response is added to headers using this code: `localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + token);` And apparently RestSharp breaks on the \r\n. Because when I do this: token.Replace("\r", "").Replace("\n", "") it works. (Probably Fiddler tries to repair the data which is probably the explanation that it works with fiddler) The next issue is that the errorLink is not valid json: ![image](https://github.com/WireMock-Net/WireMock.Net/assets/249938/7fe723a4-e400-4be2-a1df-c5b560b898e1)
Author
Owner

@laura-rodriguez commented on GitHub (May 20, 2023):

Thanks so much for looking into it @StefH ! I'll fix my code with your suggestions and try again.

@laura-rodriguez commented on GitHub (May 20, 2023): Thanks so much for looking into it @StefH ⭐ ! I'll fix my code with your suggestions and try again.
Author
Owner

@StefH commented on GitHub (May 21, 2023):

@laura-rodriguez Please let me know if this indeed solves your issue. Then this issue can be closed.

@StefH commented on GitHub (May 21, 2023): @laura-rodriguez Please let me know if this indeed solves your issue. Then this issue can be closed.
Author
Owner

@laura-rodriguez commented on GitHub (May 23, 2023):

@StefH thank you! Your suggestion fixes my issue.

@laura-rodriguez commented on GitHub (May 23, 2023): @StefH thank you! Your suggestion fixes my issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#511