Hey all - I'm run some validation tests against my...
# pact-js
c
Hey all - I'm run some validation tests against my provider, and it looks like at the end i'm getting a rust related error thrown?
Copy code
2022-11-10T20:49:15.773684Z DEBUG ThreadId(01) verify_interaction{interaction="a request with a country code exactly three characters long"}: pact_matching::json: compare_values: Comparing 'Number(1)' to 'Number(1)' at path '$.totalPages' -> Ok(())
thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching\src\<http://headers.rs:22:45|headers.rs:22:45>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
t
I agree with you. Can you share the test that is producing this?
c
the provider side javascript or the pactfile I suppose?
t
This is almost certainly a bug, even if the problem is that the test isn't correct. You'll probably want to open an issue on pact-js, which will probably move to pact-reference (where the rust core code is)
Yes, probably the pact file as a first step
Do you know what headers your provider is returning?
c
one sec just making sure there's nothing accidentally of value in here
t
Please do!
c
Copy code
{
  "consumer": {
    "name": "RestLegalService"
  },
  "interactions": [
    {
      "description": "a request with a country code exactly three characters long",
      "request": {
        "body": {
          "countryCode": "GBR"
        },
        "headers": {
          "Content-Type": "application/json"
        },
        "matchingRules": {
          "body": {
            "$.countryCode": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "regex",
                  "regex": "^.{3}$"
                }
              ]
            }
          },
          "header": {}
        },
        "method": "POST",
        "path": "/rpc/service/rpc/LegalService/queryDocumentMetadata"
      },
      "response": {
        "body": {
          "documentMetadata": [
            {
              "documentId": "cccccccc-eeee-dddd-ffff-gggggggggggg",
              "localizedNames": [],
              "revisionId": 111111
            }
          ],
          "pageNumber": 1,
          "pageSize": 1,
          "totalPages": 1
        },
        "headers": {
          "Content-Type": "application/json;"
        },
        "matchingRules": {
          "body": {
            "$.documentMetadata": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            },
            "$.documentMetadata[*].documentId": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            },
            "$.documentMetadata[*].localizedNames": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            },
            "$.documentMetadata[*].revisionId": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            },
            "$.pageNumber": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            },
            "$.pageSize": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            },
            "$.totalPages": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            }
          },
          "header": {}
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-js": {
      "version": "10.1.4"
    },
    "pactRust": {
      "ffi": "0.3.12",
      "models": "0.4.5"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "RPCLegalService"
  }
}
at least when i manually hit the same endpoint via postman i'm getting content-type of application/json, the server type, transfer-encoding of chunked, and then a date
as a response header from the server
excuse me, content type of application/json;charset=UTF-8
as far as i can tell, it's making it through the validation of the entire response (it's a bit beefy due to the seed data they have in their underlying service) and then basically bombing out as soon as it's done
t
https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_matching/src/headers.rs#L22 I think it's something to do with the charset. Can you open an issue on pact-reference with this pact file and the exact content-type and accept header(s) returned by the server?
c
sure thing
t
Oh, same question for the accept header in the request
c
hmm, well i'm not specifying one in my provider definition - just the application/json content-type - so it would be whatever pact would be applying in this case no?
when it's making the request to my service
t
Right! Sorry, my brain skipped a cog.
c
No worries
t
If there is a header in the request, it will be in the pact
Aha! This is the problem:
Copy code
"application/json;"
I think you can work around by removing the
;
in your consumer test
but I think it's still a bug
c
the classic misplaced semicolon
Yeah, a more informative error if nothing else
Okay, yeah, that fixed it. I'll still open up the issue laying out our decided fix. I appreciate the help.
t
It's a bug in pact-reference, not a misplaced semicolon - the parameter is optional, so
application/json;
is valid: https://httpwg.org/specs/rfc9110.html#rule.parameter
I appreciate the help.
You're welcome! Thanks for the report!
c
Here ya go, I think this contains the relevant information: https://github.com/pact-foundation/pact-js/issues/973 Have a good one and thanks again. 🙂
🙏 1
m
Thanks Chris