JmesPathMatcher or and MatchOperator working in version 1.5.34 but not 1.5.35 #545

Closed
opened 2025-12-29 15:26:36 +01:00 by adam · 13 comments
Owner

Originally created by @PoovenB on GitHub (Aug 28, 2023).

Originally assigned to: @StefH on GitHub.

Describe the bug

When we use version 1.5.35, the JmesPathMatcher we're using stops working. Rolling back to version 1.5.34 works again. We're using the following matcher:

"Body": {
  "MatchOperator": "and",
  "Matchers": [
      {
        "Name": "JmesPathMatcher",
        "Pattern": "definition.id == '6548'"
      },
      ...

I have two requests using this matcher with different ids. It could also be that the MatchOperator set to and isn't working.

Expected behavior:

The JmesPathMatcher should only return true if the id matches, and the and MatchOperator should only return the response for the exact match. I seem to always get back the first request matching the path, instead of the second request which matches the id.

Test to reproduce

  • Add two requests with the same request body, except for an id.
  • Use different ids for the different requests.

This behaves as expected in version 1.5.34.

Originally created by @PoovenB on GitHub (Aug 28, 2023). Originally assigned to: @StefH on GitHub. ### Describe the bug When we use version [1.5.35](https://github.com/WireMock-Net/WireMock.Net/releases/tag/1.5.35), the `JmesPathMatcher` we're using stops working. Rolling back to version 1.5.34 works again. We're using the following matcher: ``` "Body": { "MatchOperator": "and", "Matchers": [ { "Name": "JmesPathMatcher", "Pattern": "definition.id == '6548'" }, ... ``` I have two requests using this matcher with different ids. It could also be that the `MatchOperator` set to `and` isn't working. ### Expected behavior: The `JmesPathMatcher` should only return true if the id matches, and the `and` `MatchOperator` should only return the response for the exact match. I seem to always get back the first request matching the path, instead of the second request which matches the id. ### Test to reproduce - Add two requests with the same request body, except for an id. - Use different ids for the different requests. ### Other related info This behaves as expected in version 1.5.34.
adam added the bug label 2025-12-29 15:26:36 +01:00
adam closed this issue 2025-12-29 15:26:36 +01:00
Author
Owner

@StefH commented on GitHub (Aug 28, 2023):

@PoovenB
I've added two extra unit tests, and both are correct in the 1.5.35 version:

[Fact]
    public void JmesPathMatcher_IsMatch_MultiplePatternsUsingMatchOperatorAnd()
    {
        // Assign 
        var matcher = new JmesPathMatcher(MatchOperator.And, "things.x == 'RequiredThing'", "things.x == 'abc'");

        // Act 
        double score = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score;

        // Assert 
        score.Should().Be(0);
    }

    [Fact]
    public void JmesPathMatcher_IsMatch_MultiplePatternsUsingMatchOperatorOr()
    {
        // Assign 
        var matcher = new JmesPathMatcher(MatchOperator.Or, "things.x == 'RequiredThing'", "things.x == 'abc'");

        // Act 
        double score = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score;

        // Assert 
        score.Should().Be(1);
    }

Can you please post your example in more detail?

@StefH commented on GitHub (Aug 28, 2023): @PoovenB I've added two extra unit tests, and both are correct in the 1.5.35 version: ``` c# [Fact] public void JmesPathMatcher_IsMatch_MultiplePatternsUsingMatchOperatorAnd() { // Assign var matcher = new JmesPathMatcher(MatchOperator.And, "things.x == 'RequiredThing'", "things.x == 'abc'"); // Act double score = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score; // Assert score.Should().Be(0); } [Fact] public void JmesPathMatcher_IsMatch_MultiplePatternsUsingMatchOperatorOr() { // Assign var matcher = new JmesPathMatcher(MatchOperator.Or, "things.x == 'RequiredThing'", "things.x == 'abc'"); // Act double score = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score; // Assert score.Should().Be(1); } ``` Can you please post your example in more detail?
Author
Owner

@PoovenB commented on GitHub (Aug 29, 2023):

Thanks for having a look @StefH! I tried again to be sure, and since version 1.5.34, I get this failed result:

Expected object to be "https://dev.azure.com/pathx?buildId=2182601", but found "https://dev.azure.com/pathx?buildId=2182602".

Here's more detail about my setup:

{
  "Title": "Queue Build 1",
  "Request": {
    "Path": "/pathx/Builds",
    "Method": "POST",
    "Body": {
      "MatchOperator": "and",
      "Matchers": [
        {
          "Name": "JmesPathMatcher",
          "Pattern": "definition.id == '6548'"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.a"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.b"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.c"
        },
        {
          "Name": "JmesPathMatcher",
          "Pattern": "params.d == 'd'"
        }
      ]
    }
  },
  "Response": {
    "StatusCode": 200,
    "Headers": {
      "Content-Type": "application/json; charset=utf-8; api-version=6.0"
    },
    "BodyAsJson": {
      "_links": {
        "web": {
          "href": "https://dev.azure.com/pathx?buildId=2182601"
        }
      },
      "status": "notStarted"
    }
  }
},
{
  "Title": "Queue Build 2",
  "Request": {
    "Path": "/pathx/Builds",
    "Method": "POST",
    "Body": {
      "MatchOperator": "and",
      "Matchers": [
        {
          "Name": "JmesPathMatcher",
          "Pattern": "definition.id == '6796'"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.a"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.b"
        },
        {
          "Name": "JsonPathMatcher",
          "Pattern": "$.params.c"
        },
        {
          "Name": "JmesPathMatcher",
          "Pattern": "params.d == 'd'"
        }
      ]
    }
  },
  "Response": {
    "StatusCode": 200,
    "Headers": {
      "Content-Type": "application/json; charset=utf-8; api-version=6.0"
    },
    "BodyAsJson": {
      "_links": {
        "web": {
          "href": "https://dev.azure.com/pathx?buildId=2182602"
        }
      },
      "status": "notStarted"
    }
  }
}

Does anything stand out?

@PoovenB commented on GitHub (Aug 29, 2023): Thanks for having a look @StefH! I tried again to be sure, and since version 1.5.34, I get this failed result: > Expected object to be "https://dev.azure.com/pathx?buildId=2182601", but found "https://dev.azure.com/pathx?buildId=2182602". Here's more detail about my setup: ``` json { "Title": "Queue Build 1", "Request": { "Path": "/pathx/Builds", "Method": "POST", "Body": { "MatchOperator": "and", "Matchers": [ { "Name": "JmesPathMatcher", "Pattern": "definition.id == '6548'" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.a" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.b" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.c" }, { "Name": "JmesPathMatcher", "Pattern": "params.d == 'd'" } ] } }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/json; charset=utf-8; api-version=6.0" }, "BodyAsJson": { "_links": { "web": { "href": "https://dev.azure.com/pathx?buildId=2182601" } }, "status": "notStarted" } } }, { "Title": "Queue Build 2", "Request": { "Path": "/pathx/Builds", "Method": "POST", "Body": { "MatchOperator": "and", "Matchers": [ { "Name": "JmesPathMatcher", "Pattern": "definition.id == '6796'" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.a" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.b" }, { "Name": "JsonPathMatcher", "Pattern": "$.params.c" }, { "Name": "JmesPathMatcher", "Pattern": "params.d == 'd'" } ] } }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/json; charset=utf-8; api-version=6.0" }, "BodyAsJson": { "_links": { "web": { "href": "https://dev.azure.com/pathx?buildId=2182602" } }, "status": "notStarted" } } } ``` Does anything stand out?
Author
Owner

@StefH commented on GitHub (Aug 29, 2023):

"Pattern": "params.d == 'd"

should that be this? (with an extra ' at the end?)

"Pattern": "params.d == 'd'"
@StefH commented on GitHub (Aug 29, 2023): ``` "Pattern": "params.d == 'd" ``` should that be this? (with an extra ' at the end?) ``` "Pattern": "params.d == 'd'" ```
Author
Owner

@PoovenB commented on GitHub (Aug 30, 2023):

Apologies, that was a typo when I was trying to anonymize the data (I updated in the original comment). I haven't had enough time to look closely at the repo; is there perhaps a unit test example I could follow to try and replicate this in code?

Based on the existing tests, this does not seem to be related to the JmesPathMatcher nor the MatchOperator, so I'm wondering if it's related to the code that's taking in a request and executing the match specifications?

@PoovenB commented on GitHub (Aug 30, 2023): Apologies, that was a typo when I was trying to anonymize the data (I updated in the original comment). I haven't had enough time to look closely at the repo; is there perhaps a unit test example I could follow to try and replicate this in code? Based on the existing tests, this does not seem to be related to the `JmesPathMatcher` nor the `MatchOperator`, so I'm wondering if it's related to the code that's taking in a request and executing the match specifications?
Author
Owner

@StefH commented on GitHub (Aug 30, 2023):

It would help if you can provide the full request and the mapping.

And you can check this:
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-Tips

@StefH commented on GitHub (Aug 30, 2023): It would help if you can provide the full request and the mapping. And you can check this: https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-Tips
Author
Owner

@VictorioBerra commented on GitHub (Oct 6, 2023):

I too think there is a regression here. Just updated from .30 to .37 and my tests started inexplicably breaking.

My code is very simple too:

WireMockServer
    .Given(Request.Create()
                .WithPath("/v1/person/workers")
                .WithParam("delta_from", WireMock.Matchers.MatchBehaviour.RejectOnMatch) <-- PROBLEM!!!
                .UsingGet())

URL: http://localhost:8083/v1/person/workers?showsourcesystem=true&count=700&page=1&sections=personal%2Corganizations%2Cemployment

WireMoq result says WithParam(...) is a score of 0. My app is fixed when I comment out WithParam(...).

Possibly a bug with RejectOnMatch?

@VictorioBerra commented on GitHub (Oct 6, 2023): I too think there is a regression here. Just updated from .30 to .37 and my tests started inexplicably breaking. My code is very simple too: ```csharp WireMockServer .Given(Request.Create() .WithPath("/v1/person/workers") .WithParam("delta_from", WireMock.Matchers.MatchBehaviour.RejectOnMatch) <-- PROBLEM!!! .UsingGet()) ``` URL: `http://localhost:8083/v1/person/workers?showsourcesystem=true&count=700&page=1&sections=personal%2Corganizations%2Cemployment` WireMoq result says `WithParam(...)` is a score of 0. My app is fixed when I comment out `WithParam(...)`. Possibly a bug with RejectOnMatch?
Author
Owner

@StefH commented on GitHub (Oct 6, 2023):

@VictorioBerra
This is indeed an error.

Can you try preview version 1.5.38-ci-17808?

@StefH commented on GitHub (Oct 6, 2023): @VictorioBerra This is indeed an error. Can you try preview version 1.5.38-ci-17808?
Author
Owner

@StefH commented on GitHub (Oct 9, 2023):

@VictorioBerra did you have time yet to verify ?

@StefH commented on GitHub (Oct 9, 2023): @VictorioBerra did you have time yet to verify ?
Author
Owner

@VictorioBerra commented on GitHub (Oct 9, 2023):

@StefH Is 1.5.38-ci-17808 published to NuGet?

@VictorioBerra commented on GitHub (Oct 9, 2023): @StefH Is 1.5.38-ci-17808 published to NuGet?
Author
Owner

@StefH commented on GitHub (Oct 9, 2023):

@StefH Is 1.5.38-ci-17808 published to NuGet?

On MyGet
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Oct 9, 2023): > @StefH Is 1.5.38-ci-17808 published to NuGet? On MyGet https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@VictorioBerra commented on GitHub (Oct 9, 2023):

@StefH 1.5.38-ci-17808 fixed it for me, thank you!

@VictorioBerra commented on GitHub (Oct 9, 2023): @StefH 1.5.38-ci-17808 fixed it for me, thank you!
Author
Owner

@StefH commented on GitHub (Oct 9, 2023):

https://github.com/WireMock-Net/WireMock.Net/pull/1006

@StefH commented on GitHub (Oct 9, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/1006
Author
Owner

@StefH commented on GitHub (Oct 9, 2023):

@VictorioBerra
I'll close this issue and create a new official NuGet in some time

@StefH commented on GitHub (Oct 9, 2023): @VictorioBerra I'll close this issue and create a new official NuGet in some time
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#545