Consumer is pact-jvm, Provider pact-js. In the consumer contract specification the header specifies
Content-Type=application/json; charset=UTF-8
The Provider fails with the following error:
Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "Content-Type" to equal "application/json; charset=UTF-8", but was "application/json; charset=utf-8"
I was expecting a ignore case comparison but even if that is not doable I tried to relax the constraint by adding a matcher expression like this:
pactRequestWithPath
.willRespondWith()
.matchHeader("Content-Type", "application/json; charset=UTF-8|application/json; charset=utf-8|application/json;")
...
which seems to have produced the right matching rule (also in case charset is not specified)
"matchingRules": {
"header": {
"Content-Type": {
"matchers": [
{
"match": "regex",
"regex": "application/json; charset=UTF-8|application/json; charset=utf-8|application/json;"
}
],
"combine": "AND"
}
},
Confirm the following:
The verification takes into account the rules specified by consumer for matching the header
The verification seems to ignore the pattern matching rules
OK I see the problem. You're generating a v3 Pact with Pact JVM, but unfortunately Pact JS doesn't fully support v3 in the main branch.
Option 1: Set the spec version to 2 in your JVM test: https://docs.pact.io/implementation_guides/jvm/consumer/junit#generating-v2-spec-pact-files
Option 2: Try the beta version of v3 of Pact JS (https://github.com/pact-foundation/pact-js#pact-js-v3)
Thanks for taking the time to raise the issue.
I'll just like to comment that this is not a V3 vs V2 issue, but a matching issue for headers with attributes. Pact-JVM has specific rules to match headers with attributes, and the matching should be done in a case insensitive manor.
These Content-Type header values should match without needing any special matching rules:
application/json; charset=UTF-8
application/json; charset=utf-8
application/json (only if the expected value has no charset)
Correct me if I'm wrong Ron, but wasn't that header attribute matching introduced in V3 i.e. https://github.com/pact-foundation/pact-specification/tree/version-3#content-type-header-matching-should-include-parameters-in-the-matching ?
Is this in any of the specs @uglyog? It makes sense, but I had no idea that code existed. A quick google on header value matching says "header values may or may not be case sensitive". Helpful!
There is no specs for it. We should add some, because all the specs are based on body matching only.
Yeah we have updated to "@pact-foundation/pact": "10.0.0-beta.15" and it is still failing. I will do more investigation to check if something is needed provider side to force using pact V3
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@giuseppe-salvatore is this still an issue? I seem to recall we sorted it out with a regex in the consumer matching, but just want to check.
@mefellows yeah we are good, at least downgrading the version of PACT to 2. You can close this and when I upgrade both consumer and provider to use 3 I will check for the behaviour
Thanks for confirming @giuseppe-salvatore.