pact-foundation/pact-mock_service

Pact stub service throws error for query values with matching rules

mefellows opened this issue · 5 comments

Pre issue-raising checklist

I have already (please mark the applicable with an x):

  • Read through the relevant docs at https://docs.pact.io
  • Upgraded to the latest version of the gem
  • Checked the CHANGELOG to see if the issue I am about to raise has been fixed
  • Created an executable example that demonstrates the issue using either a:
    • Dockerfile
    • Git repository with a Travis or Appveyor (or similar) build

Software versions

  • OS: e.g. Mac OSX 12.2.1
  • pact stub service: eg. v 3.9.0

Expected behaviour

Pact stub service can match on query strings

Actual behaviour

Error is thrown

Steps to reproduce

Given the following v2 pact file saved to /tmp/test.json:

{
  "provider": {
    "name": "sample-provider"
  },
  "consumer": {
    "name": "sample-consumer"
  },
  "interactions": [
    {
      "description": "a request to get a product",
      "request": {
        "method": "GET",
        "path": "/product/10",
        "query": "param=S",
        "matchingRules": {
          "$.query.param": {
            "match": "regex",
            "regex": "[A-Za-z0-9]{1,20}"
          }
        }
      },
      "response": {
        "status": 200
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    },
    "pact-jvm": {
      "version": "4.2.9"
    }
  }
}

Running the following command

pact-stub-service /tmp/test.json

Results in the error:

/opt/pact/lib/vendor/ruby/2.4.0/gems/pact-support-1.17.0/lib/pact/term.rb:31:in `initialize': Value to generate "["S"]" does not match regular expression /[A-Za-z0-9]{1,20}/ (Pact::Error)

Relevant log files

n/a

Hm. It deserializes the query as a map of string key to array values, and then the matcher can't be matched to an array.

Thanks Beth. Should the matcher be applied to each element of the query? Or is it an incorrect matcher serialisation, which should instead be in "eachLike" form?

should instead be in "eachLike" form?

Just noting that AFAIK, there is no standardised format for query strings beyond which characters are allowed, and which characters are separators (there isn't even a defacto convention, which is very annoying), so I think it's worth clearly documenting whatever choices Pact makes.

Hi, looping back around on this. Is this some change I can do or will this be more of a bug fix?