pact-foundation / pact-reference

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

Header is parsed incorrectly #259

Closed sergeyklay closed 1 year ago

sergeyklay commented 1 year ago

Hi,

I seem to have hit a dead end with the header verification. Relevant part of pact looks as follows:

"response": {

        // ...

        "headers": {
          "Last-Modified": "Sun, 12 Mar 2023 01:21:35 GMT"
        },

        // ...

       "matchingRules": {
          "$.headers.Last-Modified": {
            "match": "regex",
            "regex": "^[A-Za-z]{3},\\s\\d{2}\\s[A-Za-z]{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\sGMT$"
          },

          // ...

        }

      }

  // ...

  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }

I think the regular expression in Python consumer is correct, since I have tested it many times using various tools:

# The date and time format used in the Last-Modified header according to
# RFC 7231 is described in section 7.1.1.1.
#
# Examples:
#
#    Last-Modified: Mon, 12 Feb 1996 11:36:28 GMT
#    Last-Modified: Sat, 11 Mar 2023 21:56:41 GMT
#
LAST_MODIFIED_REGEX = r'^[A-Za-z]{3},\s\d{2}\s[A-Za-z]{3}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT$' 

But when I try to verify it, it somehow compares for an exact match, without using a regular expression:

Pending Failures:

1) Verifying a pact between ProductServiceClient and ProductService Given there is a product with ID 1 - a request for a product
    1.1) includes header 'Last-Modified' with value 'Sun'
           Expected header 'Last-Modified' to have value 'Sun' but was 'Sun'
           Expected header 'Last-Modified' to have value '12 Mar 2023 01:21:35 GMT' but was '12 Mar 2023 01:21:52 GMT'

image

The difference in seconds: 35 vs 52. And it fails because (I guess. I could be wrong.) in pact I have:

but providers returns

I use the same approach ( using regular expression test) for other headers like ETag, Content-Type and they are fine, verification passes as expected. The problem is only with this header.

Of course, I can create the required date on the provider side using request to /_pact/provider_states. However, in this case all my efforts will be to provide an exact match, and I would like to use the pattern here.

In one of the chats, @TimothyJones suggested that this is the bug with the header parsing where it’s splitting on ,. Looks like a bug in pact-reference, probably. Anyway, there is a similar issue: https://github.com/pact-foundation/pact-js/issues/1058


Versions:

Verifier

% pact_verifier_cli --version
pact verifier version   : v0.10.3
pact specification      : v4.0
models version          : v1.0.4

Broker

Docker images: pactfoundation/pact-broker:latest
github-actions[bot] commented 1 year ago

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-823). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

rholshausen commented 1 year ago

pact_verifier_cli 0.10.4 has been released with a fix for this

sergeyklay commented 1 year ago

I can confirm it, now everything works as expected. Thanks for the quick fix!