mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-13 13:53:34 +01:00
Server returns unexpected 400 unless I use Fiddler which fixes the issue #511
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
Test passing when Fiddler is capturing
@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):
@laura-rodriguez
I think I found your issue.
This mapping is setup like:

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:

@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.
@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.
@laura-rodriguez commented on GitHub (May 23, 2023):
@StefH thank you! Your suggestion fixes my issue.