pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

Header matching fails due to terminating on comma #353

Closed alexeits closed 3 months ago

alexeits commented 9 months ago

Given the following pact JSON:

"headers": {
"Content-Type": "application/json",
"Set-Cookie": "auth=fake-token; HttpOnly"
},
"body": {},
"matchingRules": {
"$.headers.Content-Type": {
  "match": "regex",
  "regex": "^application\\/json(;|$)"
},
"$.headers.Set-Cookie": {
  "match": "regex",
  "regex": "^auth=[^;]+;.*\\s[Hh]ttp[Oo]nly(?:;|$)"
}

Complete JSON: agent-desktop-impersonation_tokens.json

and the provider responding with:

auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQyMTczMDQsImlhdCI6MTcwNDIxMDEwNCwiYWN0aXZhdGVkQXQiOiIyMDI0LTAxLTAyVDE1OjQxOjQ1Ljg0NVoiLCJ1c2VySWQiOiJleGFtcGxlVXNlcklkIiwib3JnSWQiOiJleGFtcGxlT3JnSWQiLCJyb2xlSWRzIjpbImFnZW50Il0sInNhZ2FuVXNlciI6ImFkbWluQGV4YW1wbGUub3JnIiwic2Vzc2lvbiI6eyJpZCI6IkY2QklCd2xtUXNTckJvQ01CX0pEZXcifX0.kNXCzxDQjGEmEwEAoLC1JLLUYPTQjWgHheLlhEPlOc0; Path=/; Expires=Tue, 02 Jan 2024 17:41:44 GMT; Max-Age=7198; HttpOnly

which matches the Set-Cookie regex: https://regex101.com/r/bTjvJT/1,

the verification fails with:

1) Verifying a pact between agent-desktop and impersonation_tokens Given agent user exists - start impersonation
    1.1) includes header 'Set-Cookie' with value 'auth=fake-token; HttpOnly'
           Expected header 'Set-Cookie' to have value 'auth=fake-token; HttpOnly' but was 'auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQyMTczMDQsImlhdCI6MTcwNDIxMDEwNCwiYWN0aXZhdGVkQXQiOiIyMDI0LTAxLTAyVDE1OjQxOjQ1Ljg0NVoiLCJ1c2VySWQiOiJleGFtcGxlVXNlcklkIiwib3JnSWQiOiJleGFtcGxlT3JnSWQiLCJyb2xlSWRzIjpbImFnZW50Il0sInNhZ2FuVXNlciI6ImFkbWluQGV4YW1wbGUub3JnIiwic2Vzc2lvbiI6eyJpZCI6IkY2QklCd2xtUXNTckJvQ01CX0pEZXcifX0.kNXCzxDQjGEmEwEAoLC1JLLUYPTQjWgHheLlhEPlOc0; Path=/; Expires=Tue'

Notice that the match is terminated on the comma after "Tue".

YOU54F commented 3 months ago

This should be resolved in libpact_ffi-v0.4.13 or higher.

Please let us know if this is still an issue

alexeits commented 3 months ago

@YOU54F: I confirm that it's resolved. We are currently on 0.4.16 and no longer see this issue.

YOU54F commented 3 months ago

appreciate the confirmation @alexeits!