Skip to content
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

Exact byte array request matching fails on specific byte arrays #601

Closed
Archomeda opened this issue Apr 12, 2021 · 3 comments
Closed

Exact byte array request matching fails on specific byte arrays #601

Archomeda opened this issue Apr 12, 2021 · 3 comments
Assignees
Labels

Comments

@Archomeda
Copy link

Describe the bug

Exact matching on byte arrays sometimes fails, depending on the byte array contents.

Expected behavior:

Exact matching should succeed, no matter what the byte array contents are, as long as it's the same.

Test to reproduce

The following code reproduces the bug:

static async Task Main(string[] args)
{
    await DoStuff(new byte[] { 201, 202, 203 });
    await DoStuff(new byte[] { 49, 50, 51 });
}

static async Task DoStuff(byte[] bytes)
{
    using var server = WireMockServer.Start();
    using var httpClient = new HttpClient { BaseAddress = new Uri(server.Urls[0]) };

    server
        .Given(Request.Create()
            .WithPath("/test")
            .WithBody(bytes)
            .UsingPost())
        .RespondWith(Response.Create()
            .WithSuccess()
            .WithBody("success"));

    using var content = new ByteArrayContent(bytes);
    var response = await httpClient.PostAsync("test", content);

    Console.WriteLine($"{response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
}

The output:

OK - success
NotFound - {"Status":"No matching mapping found"}

Other related info

From my limited debugging, I've noticed that the request log shows different behavior. In the first case, it shows that DetectedBodyType = Bytes, while in the second case it's DetectedBodyType = String. In both cases the DetectedBodyTypeFromContentType = Bytes.

I don't expect WireMock to transform a request to a string automatically and then fail to match because it expects a byte array.

@Archomeda Archomeda added the bug label Apr 12, 2021
@StefH
Copy link
Collaborator

StefH commented Apr 16, 2021

The different DetectedBodyType should not cause this error I think.

I'll take a look what's the root cause.

Thank you for noticing this issue.

@StefH
Copy link
Collaborator

StefH commented Apr 18, 2021

New version will be released soon.

@StefH StefH closed this as completed Apr 18, 2021
@Archomeda
Copy link
Author

Cool, thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants