pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.59k stars 343 forks source link

Mismatch with header 'Accept' #1031

Closed danymarques closed 1 year ago

danymarques commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behavior

When giving multiple arguments to a header, the tests should work.

Actual behavior

When we give multiple arguments to a header, eg:

Accept: 'application/problem+json, application/json, text/plain, */*',

the tests fail with the following error:

1.0 Mismatch with header 'Accept': Expected header 'Accept' to have value 'application/problem+jsonapplication/jsontext/plain*/*' but was 'application/problem+json'

which means that the headers are not handled correctly.

Steps to reproduce

mefellows commented 1 year ago

Thanks for this. I think it's a duplicate of #964. I've just pushed up a fix that should fix it, at least as far as we can in Pact JS.

You can now either specify headers as a comma delimited list (as you have in your repro) or explicitly as an [] of items, each of which can also have matching rules if desired.

I've noticed a small bug with the way it reports mismatches if the request header doesn't match, but you can see what's happening in the debug logs when enabled. I'll raise an upstream issue for that.

danymarques commented 1 year ago

Hi @mefellows , I compiled your branch and tested it in the project and it works perfectly. When are you planning to release it? Cheers

GeorgeTailor commented 1 year ago

@mefellows afair HTTP header does not have any constraints to be either a string or a comma-separated string or an array, for example, we use a JSON in a header with multiple properties, thus the object has commas. When it is sent as a string, some splitting magic happens and probably pact tries to treat broken parts of json as a separate array entries, while in reality it is a single string, but with commas.

mefellows commented 1 year ago

You're right, it is a bug - thanks for raising it. I'll need to review the RFC and the current core implementation to think of the best way to handle this.