Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
mefellows opened this issue Nov 23, 2022 · 5 comments
Open
4 tasks done

Comments

@mefellows
Copy link
Member

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

@mefellows
Copy link
Member Author

See also pactflow/example-consumer-java-junit#27

Tagging @rebutler97

@bethesque
Copy link
Member

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
Copy link
Member Author

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
Copy link
Contributor

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants