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

Request body is base64 encoded when the content-type is application/x-www-form-urlencoded #1164

Closed
pendsley opened this issue Jul 8, 2020 · 3 comments

Comments

@pendsley
Copy link
Contributor

pendsley commented Jul 8, 2020

The generated pact for a request with a body that is form-urlencoded is base64 encoded.

Pact definition

return builder.given("A user exists with credentials user///pass")
                .uponReceiving("A request to authenticate with correct credentials")
                .path("/login")
                .method("POST")
                .headers("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE)
                .body("username=user&password=pass", MediaType.APPLICATION_FORM_URLENCODED_VALUE)
                .willRespondWith()
                .headers(ImmutableMap.of("Content-Type", MediaType.APPLICATION_JSON_VALUE))
                .status(200)
                .toPact();

Generated Pact

{
  "provider": {
    "name": "provider"
  },
  "consumer": {
    "name": "consumer"
  },
  "interactions": [
    {
      "description": "A request to authenticate with correct credentials",
      "request": {
        "method": "POST",
        "path": "/login",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "body": "dXNlcm5hbWU9dXNlciZwYXNzd29yZD1wYXNz"
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        }
      },
      "providerStates": [
        {
          "name": "A user exists with credentials user///pass"
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.1.6"
    }
  }
}
@pendsley
Copy link
Contributor Author

pendsley commented Jul 8, 2020

I can override it manually by setting pact.content_type.override.application.x-www-form-urlencoded=text, but that seems like a workaround. I don't think it should default to being encoded.

It looks like the issue might be in ContentType.isBinaryType().

registry.getSupertype("application/x-www-form-urlencoded") is resolving to application/octet-stream

@pulgupta
Copy link

pulgupta commented Jul 24, 2020

I am also facing the same issue body is getting base64 encoded. The header which I am using is Content-Type=application/x-www-form-urlencoded;charset=UTF-8 and but for this my tests.

@uglyog
Copy link
Member

uglyog commented Aug 9, 2020

4.1.7 has been released with this fix

@uglyog uglyog closed this as completed Apr 21, 2021
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

3 participants