pact-provider-verifier
pact-provider-verifier copied to clipboard
JSON malformed on GET requests with body
Seems there is a problem with sending a wrong formatted JSON body on a GET request with a JSON body.
I am executing the next command:
bundle exec pact-provider-verifier /hq-placements-client-hq-placements.json --provider hq-placements --provider-base-url 'http://localhost:3000/'
The body in the contract is this one:
"body": {
"sort_field": "not permitted value"
}
And I can see that the provider is receiving this body:
"{\"sort_field\":\"not permitted value\"}"=>nil
But in case I use the query
instead of body
in the contract JSON file: "query": "sort_field=invalid"
, the request works properly.
Also, mention that I can do the same request using Postman or ‘curl’ and it works properly:
curl --location --request GET 'localhost:3000/placements' \
--header 'Content-Type: application/json' \
--data '{
"sort_field": "not permitted value"
}'
Did some debugging and I can see that when the query method is a GET (catching it with Wireshark), the body is translated into query params, but with what it seems with white spaces (what is formerly accepted, since the body on a GET request is not the ‘correct’ way to handle the request). As fast as I change it to other methods, the body appears in the correct way.
So it parses the body into %7B%22sort_field%22%3A%22invalid%22%7D
when it should be either a JSON body or a query parameter like sort_field=invalid
I am using a contract with this specification: "pactSpecification": { "version": "2.0.0" } For the gem: pact-provider-verifier (1.36.1)
GET requests shouldn't have bodies
Well you can send one, but it should be ignored by clients. Whether Pact should do they same, is open to interpretation