pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

Pact parser is removing quoting on Content-Type params

Open fragonib opened this issue 2 years ago • 3 comments

Hi 👋 ,

Is this by design or a BUG?

  1. You are running a PROVIDER Contract Test that fetches contracts to validate from PactBroker
  2. The PACT framework parses contract coming from defined PactBroker
  3. This particular contract has this header Content-Type: multipart/related; type="application/json"; boundary=myBoundary
  4. When parsing this contract quotes disappear on PACT Request Model (that can be ok)
  5. But when PACT serializes the Request Model the generated header miss quotes so is outside standard when param values has special symbols like / as in type in this particular case: Content-Type: multipart/related; type=application/json; boundary=myBoundary

I'm having issues during provider verification because generated request doesn't contain quotes and provider requires them to dispatch it

fragonib avatar Apr 27 '22 15:04 fragonib

I guess this can be useful: https://www.w3.org/Protocols/rfc1341/4_Content-Type.html

fragonib avatar Apr 27 '22 19:04 fragonib

The involved code is in class au.com.dius.pact.core.model.HeaderParser. This serialization code isn´t dealing with quotes

private fun hvToString(headerValue: HeaderValue): String {
  return if (headerValue.params.isEmpty()) {
    headerValue.value.trim()
  } else {
    headerValue.value.trim() + ";" + headerValue.params.joinToString(";") { it.name + "=" + it.value }
  }
}

fragonib avatar Apr 28 '22 09:04 fragonib

Hi there, we're also having a problem with this. We should send an Accept Header with Accept: application/hal+json;profile="https://api.example.de/examples+v1" and receive the same value in the Content-Type Header. When using a pact file for the test and sending a query the quoting is removed and the test fails.

timoschroeder1213 avatar Jun 09 '23 08:06 timoschroeder1213