Skip to content

Commit 7a8582f

Browse files
authored
Fix #1494: WithClientIP(MatchOperator, IStringMatcher[]) ignores the operator (#1495)
1 parent 05929bd commit 7a8582f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/WireMock.Net.Minimal/RequestBuilders/Request.ClientIP.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public IRequestBuilder WithClientIP(MatchOperator matchOperator, params IStringM
1919
{
2020
Guard.NotNullOrEmpty(matchers);
2121

22-
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Or, matchers));
22+
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, matchOperator, matchers));
2323
return this;
2424
}
2525

test/WireMock.Net.Tests/RequestBuilders/RequestBuilderWithClientIPTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,23 @@ public void Request_WithClientIP_Func()
6464
var requestMatchResult = new RequestMatchResult();
6565
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
6666
}
67+
68+
[Fact]
69+
public void Request_WithClientIP_MatchOperator_And_RequiresAllMatchers()
70+
{
71+
// given: two matchers combined with And (the client IP must satisfy BOTH)
72+
var spec = Request.Create().WithClientIP(MatchOperator.And, new WildcardMatcher("1.2.*"), new WildcardMatcher("*.3.4"));
73+
74+
// when: an IP matching both matchers -> perfect match
75+
var matchesBoth = new RequestMessage(new UrlDetails("http://localhost"), "GET", "1.2.3.4");
76+
spec.GetMatchingScore(matchesBoth, new RequestMatchResult()).Should().Be(1.0);
77+
78+
// when: an IP matching only the first matcher -> mismatch
79+
var matchesFirstOnly = new RequestMessage(new UrlDetails("http://localhost"), "GET", "1.2.9.9");
80+
spec.GetMatchingScore(matchesFirstOnly, new RequestMatchResult()).Should().Be(0.0);
81+
82+
// when: an IP matching only the second matcher -> mismatch
83+
var matchesSecondOnly = new RequestMessage(new UrlDetails("http://localhost"), "GET", "9.3.4");
84+
spec.GetMatchingScore(matchesSecondOnly, new RequestMatchResult()).Should().Be(0.0);
85+
}
6786
}

0 commit comments

Comments
 (0)