Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Interaction Filtering when working with V4 pacts #1673

Open
jakubbrodzinski opened this issue Feb 28, 2023 · 3 comments
Open

Problem with Interaction Filtering when working with V4 pacts #1673

jakubbrodzinski opened this issue Feb 28, 2023 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@jakubbrodzinski
Copy link

Hi,
I think I've stumbled upon subtle issue regarding Interaction Filtering in pact-jvm, and I would much appreciate someone taking a look at it and confirming whether it is an issue or just misconfiguration on my side.

  • Provider perspective:
    Once we migrated to pact-jvm 4.5.0, we started publishing pacts with pactSpecification.version == 4.0
  • Consumer perspective:
    Once the provider switched to the new version, we cannot verify the latest pacts and we are getting an error:
Source: Pact Broker (...) consumerVersionSelectors=[Selector(tag=dummy-tag, latest=true, consumer=null, fallbackTag=)]
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
  • Potential root cause:
    • As it turns out, we actually are able to locate the latest pacts, but they are getting filter out by @PactFilter(value = "/interaction/path", filter = InteractionFilter.ByRequestPath.class).
    • In the filter mentioned above, we check whether condition interaction instanceof RequestResponseInteraction is true, and it works just fine for V3. Sadly for V4, what we are getting there is a class of type SynchronousHttp which extends both V4Interaction and SynchronousRequestResponse, but no RequestResponseInteraction.
    • I think by replacing the instanceof statement with interaction.isSynchronousRequestResponse() we could make it more flexible and resilient to type structure changes. The implementation would look like this:
               if (interaction.isSynchronousRequestResponse()) {
                   var requestPath = interaction.asSynchronousRequestResponse().getRequest().getPath();
                   return Arrays.stream(values).anyMatch(requestPath::matches);
               } else {
                   return false;
               }

What do you think? Thanks in advance! :)

@jakubbrodzinski
Copy link
Author

I've stumbled upon one more thing. Was the change from:

map["headers"] = request.headers.entries.associate { (key, value) -> key to value.joinToString(COMMA) }

to

map["headers"] = headers (headers is of type MutableMap<String, List<String>>)

between V3 and V4 pacts done intentionally? As of now, users using pact-jvm < 4.50 are unable to verify Pacts published by consumers with pact-jvm >= 4.5.0. I've gone through RFC, and the change to Headers was not mentioned there.

@rholshausen rholshausen added bug Indicates an unexpected problem or unintended behavior smartbear-supported labels Mar 6, 2023
@github-actions
Copy link

github-actions bot commented Mar 6, 2023

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-808). 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 added a commit that referenced this issue Mar 6, 2023
@rholshausen
Copy link
Contributor

As to the headers, the code to join it into a string was a bug, as the V3 spec changed it to use Map<String, List<String>> format. The V4 models were corrected, but I see the original bug is still there (I thought it had been updated).

But they should support both formats of headers. If you are unable to verify Pacts with that format, can you raise an issue with details of the errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants