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

JSON malformed on GET requests with body #105

Open
lluis-jt opened this issue May 16, 2023 · 2 comments
Open

JSON malformed on GET requests with body #105

lluis-jt opened this issue May 16, 2023 · 2 comments

Comments

@lluis-jt
Copy link
Contributor

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
Screenshot 2023-05-16 at 16 59 23


I am using a contract with this specification:
"pactSpecification": {
"version": "2.0.0"
}
For the gem: pact-provider-verifier (1.36.1)

@YOU54F
Copy link
Member

YOU54F commented Jun 12, 2023

GET requests shouldn't have bodies

@YOU54F
Copy link
Member

YOU54F commented Jun 12, 2023

Well you can send one, but it should be ignored by clients. Whether Pact should do they same, is open to interpretation

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

2 participants