pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
72 stars 68 forks source link

Pact stub service throws error for query values with matching rules #140

Open mefellows opened 1 year ago

mefellows commented 1 year ago

Pre issue-raising checklist

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

Software versions

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 commented 1 year ago

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

Tagging @rebutler97

bethesque commented 1 year ago

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.

mefellows commented 1 year ago

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?

TimothyJones commented 1 year ago

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.

rebutler97 commented 1 year ago

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