pact-foundation / pact-reference

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

Throwing Rust Exception during Provider Validation #228

Closed chrisgodsey closed 1 year ago

chrisgodsey commented 1 year ago

Thank you for reporting a bug! We appreciate it very much. Issues are a big input into the priorities for Pact-JS development

All italic text in this template is safe to remove before submitting

Thanks again!

Software versions

Please provide at least OS and version of pact-js

Issue Checklist

Please confirm the following:

Expected behaviour

My validation should complete and give me a result based on the state of my pact one way or another.

Actual behaviour

I receive the following Rust exception. It looks like this exception gets thrown after the validation of everything in my response body:

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\headers.rs:22:45 note: run withRUST_BACKTRACE=1environment variable to display a backtrace

Steps to reproduce

Walking through this with one of the people in the Slack, it looks like the end cause of my issue was that in my expected response headers, I fatfingered and typed:

                        headers: {
                            'Content-Type': 'application/json;'
                        }

Note the semi-colon at the end of this string. Upon removing this semi-colon, and re-publishing the pact my provider was able to properly verify.

I'd expect, if nothing else, simply informing me of a mismatch in my validation, or a more informative error letting me know if this input error.

TimothyJones commented 1 year ago

According to the http spec, the parameter after the semicolon is optional, so pact should not fail on application/json; - see https://httpwg.org/specs/rfc9110.html#rule.parameter

Of course, even if it were malformed, it would be a nicer experience if pact didn't explode and instead warned.

mefellows commented 1 year ago

Looks like an issue in the core, I'm going to transfer the issue there.

rholshausen commented 1 year ago

/jira ticket

github-actions[bot] commented 1 year ago

👋 Thanks, Jira [PACT-471] ticket created.