Hi All, I am new to PACT and I have completed the...
# pact-jvm
g
Hi All, I am new to PACT and I have completed the publishing pacts to the pact broker from the consumer and I also verified the pacts against the running Provider. This works awesome. All the requests I have should have an active token to verify the pact against the provider. Is there a way to modify the auth token before triggering verification tasks? I need this to be done when I am doing the verification when I provider makes a change. I am using mvn pact:verify to verify the contracts. Can someone help me with this? Is there a sample to check?
🙌 1
m
See 👇 (howtoauth)
s
Approaches to handling authentication in Pact tests: https://docs.pact.io/provider/handling_auth
m
There's some general guidelines there.
To see an example, check out the java workshops authorisation step (howtolearn)
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
g
Thanks @Matt (pactflow.io / pact-js / pact-go), I will check this out and let you know if I have any issues
👍 1
Hi @Matt (pactflow.io / pact-js / pact-go), I made the changes like this I am using Provider version 4.5.6, but still I am not able to replace the token. I run mvn pact:verify to verify my test cases. Am I missing something ?
I hard-coded both valid and invalid token, but still I don't see it gets applied during provider verification
This is the place where I am stuck and want to find a way to replace the valid token when the provider tries to verify the contracts when a new version is deployed. Your Help is much appreciated. @Matt (pactflow.io / pact-js / pact-go) Java Version 17 Pact Provider Version 4.5.6 I am running the test using "mvn pact:verify" command. I tried adding the Auth token in verifyPact method but still this is not getting updated.
m
Do you know if that method is being invoked?
If you set log level to DEBUG, we should be able to see the request/response from the verifier to the actual provider.
g
Hi @Matt (pactflow.io / pact-js / pact-go), The method is not being called when I run mvn pact:verify Can we use requestFilter in pom.xml?
m
g
Hi @Matt (pactflow.io / pact-js / pact-go), I tried writing groovy scripts with <requestFilters> but I am getting error A required class was missing while executing au.com.dius.pact.providermaven4.6.2verify org/apache/ivy/util/MessageLogger But the dependencies are downloaded but it in not included in pact verify step. Does this needs any fix?
@Matt (pactflow.io / pact-js / pact-go), The below code works perfect <requestFilter> request.setHeader('Authorization', 'Bearer eyJhbGciOiJS***') </requestFilter> I am able to replace the header 'Authorization' but I want to dynamically change the token. Is there any way to do that?