pact-mock_service icon indicating copy to clipboard operation
pact-mock_service copied to clipboard

Pact stub service throws error for query values with matching rules

Open mefellows opened this issue 3 years ago • 5 comments
trafficstars

Pre issue-raising checklist

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

  • [x] Read through the relevant docs at https://docs.pact.io
  • [x] Upgraded to the latest version of the gem
  • [x] Checked the CHANGELOG to see if the issue I am about to raise has been fixed
  • [x] 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

mefellows avatar Nov 23 '22 00:11 mefellows

See also https://github.com/pactflow/example-consumer-java-junit/issues/27

Tagging @rebutler97

mefellows avatar Nov 23 '22 00:11 mefellows

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.

bethesque avatar Nov 23 '22 02:11 bethesque

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?

mefellows avatar Nov 23 '22 04:11 mefellows

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.

TimothyJones avatar Nov 27 '22 13:11 TimothyJones

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

rebutler97 avatar Jan 04 '23 16:01 rebutler97