Reputation: 15305
Imagine the scenario where the consumer production code under test is adding an API key as query parameter when calling the provider because it's required by some intermediate layers between the consumer and provider (typically an API Gateway).
There are some cases where this API key as query parameter doesn't make much sense to be part of the Pact contract.
However, if not added to the contract, the mock server created from the contract in consumer tests will not match queries that are actually adding the query parameter. Thus making it impossible to write a unit test using the mock server on the consumer side.
Is there a way to have a query parameter actually present in the requests be ignored from the consumer mock server when matching query parameters to find the appropriate response?
(Asking in a JVM (Java and/or Scala) context if that matters).
Upvotes: 0
Views: 845
Reputation: 4065
This article goes into some detail about handling authentication in a general sense, and this article](https://docs.pact.io/recipes/apigateway) might be helpful for API gatewawys specifically.
Does the presence of the query string during provider verification cause an issue? If the provider simply ignores things it doesn't care about (Postel's law) then it's probably simplest kept that way.
If it causes issues, I would leave it in the consumer contract, and consider modifying it prior to provider verification through the use of a request filter to strip the query string off the request.
Upvotes: 1