pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

query string encoding when verifying contracts with pact-jvm #97

Closed nagliyvred closed 9 years ago

nagliyvred commented 9 years ago

Link to a corresponding google thread

Hi guys,

We are using a ruby-based pact-mock-service on the consumer side to generate a pact file and verifying the contract by using pact-jvm (more specifically the gradle plugin). One of our resources accepts a bunch of query parameters, and the generated contract looks like this:

"request": {
  "method": "get",
  "path": "/autoComplete/address",
  "query": "max_results=100&state=NSW&term=80+CLARENCE+ST,+SYDNEY+NSW+2000",
}

As you can see the query is encoded on the ruby side, however, apparently the java side expects a decoded value there and we receive "80+CLARENCE+..." in our controller.

Thanks, Evgeny

uglyog commented 9 years ago

I'm thinking of pushing for a change in the pact spec to store the query parameters as a map of arrays. That way they will always be stored unencoded, and it will resolve this issue.

As a work around, I'm going to unencode the query string after loading it from the pact file. The side effect of this is that any query parameter that contains a '+' will be replaced with a space. However, '+' should be used in paths, and %20 in query parameters.

bethesque commented 9 years ago

The Ruby impl already talks between the test and the mock server using a map of arrays, it would be very simple to change that to serialise it to the pact that way. I think it's a good idea.

uglyog commented 9 years ago

Version 3.1.0 allows V3 format pact files which should resolve this issue.