RequestMessageHeaderMatcher with MatchBehaviour.RejectOnMatch reverses match results twice #444

Closed
opened 2025-12-29 08:28:14 +01:00 by adam · 0 comments
Owner

Originally created by @flts on GitHub (Aug 22, 2022).

Describe the bug

Following the Reversing the match behaviour with MatchBehaviour.RejectOnMatch
example the reponse will always be Unauthorized even if a correct header is added on the request.

I believe the following line shouldn't call MatchBehaviourHelper.Convert() again as it is already called for each Matcher. Other RequestMessage***Matcher's do not call MatchBehaviourHelper.Convert() before returning.
be4b0addca/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs (L138)

Expected behavior:

Given the following example taken from the docs. The expected behavior is that only an Unauthorized response is returned when the header api-key is missing from the http request.

server
   .Given(Request.Create()
             .WithPath("/needs-a-key")
             .UsingGet()
             .WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch)
             .UsingAnyMethod())
   .RespondWith(Response.Create()
             .WithStatusCode(HttpStatusCode.Unauthorized)
             .WithBody(@"{ ""result"": ""api-key missing""}"));

Since WireMock.Net v1.5.0.

Originally created by @flts on GitHub (Aug 22, 2022). ### Describe the bug Following the [Reversing the match behaviour with MatchBehaviour.RejectOnMatch ](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#reversing-the-match-behaviour-with-matchbehaviourrejectonmatch) example the reponse will always be `Unauthorized` even if a correct header is added on the request. I believe the following line shouldn't call `MatchBehaviourHelper.Convert()` again as it is already called for each Matcher. Other RequestMessage***Matcher's do not call `MatchBehaviourHelper.Convert()` before returning. https://github.com/WireMock-Net/WireMock.Net/blob/be4b0addca8d89cedbdbbd645c842417a04b8178/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs#L138 ### Expected behavior: Given the following example taken from the docs. The expected behavior is that only an `Unauthorized` response is returned when the header `api-key` is missing from the http request. ``` C# server .Given(Request.Create() .WithPath("/needs-a-key") .UsingGet() .WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch) .UsingAnyMethod()) .RespondWith(Response.Create() .WithStatusCode(HttpStatusCode.Unauthorized) .WithBody(@"{ ""result"": ""api-key missing""}")); ``` ### Other related info Since WireMock.Net v1.5.0.
adam added the bug label 2025-12-29 08:28:14 +01:00
adam closed this issue 2025-12-29 08:28:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#444