Hi All, The below code works perfectly <reque...
# pact-jvm
g
Hi All, The below code works perfectly <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? Has anyone tried this?
🎉 1
r
That executes script code between the <requestFilter> tags. You need to update the script to dynamically change the token.
Are you asking how to change that code, or are you asking how to dynamically generate a token? We can't answer the latter because it depends on your systems that produce the tokens.
g
Thanks for the reply @rholshausen, I am asking how to change the code. I am a complete alien to Groovy. What I want to achieve is, I wanted to connect to Secrets Manager and get the creds in groovy script. So it should be something like below <requestFilter> #To make a call to secrets manager I would require libs to import. But I am not able to do that here. If I do that then I can do what I want to achieve request.setHeader('Authorization', "<Token>"); </requestFilter>
b
It kinda depends where your token comes from. If it's available to your groovy script, you just need to put it in the string like
request.setHeader('Authorization', "Bearer $token")
g
Actually, I wanted to grab a token using groovy script but when I add inline groovy script in pom.xml I get the error "*A required class was missing while executing au.com.dius.pact.providermaven4.6.2verify org/apache/ivy/util/MessageLogger*"
I can grab a token by hitting my endpoint but to make a http call, I need to write a groovy script, which i am not able to do as I face dependency issues while writing groovy scripts @Boris
b
This thread has a Gradle example, looks similar to your code sample
g
Thanks @Boris, Let me check this
b
Feels like this is getting out of the scope of Pact, and you need to understand better how Maven & Groovy scripts work
1
I've only used Maven a little, so I can't give you a direct example
I'd need to go through some old computers to find examples of #4 that you asked for earlier
g
Okay, @Boris, That thread has the same thing that we already discussed. I will check how the groovy works. But Pact should come up with a Feature to replace the token dynamically.
m
Thanks for raising, but I really think that’s a mistake - there are already ways to do it. EIther there is a misunderstanding in how to do it, or it’s a bug. Either way, Canny isn’t the best place for it If it’s a bug, it should go to https://github.com/pact-foundation/pact-jvm/ with a reproducible example so it can be fixed.
Unfortunately I don’t know groovy/maven enough either to help you. But perhaps there is somebody in your team/company that does you can pair with? If you have a small reproducible example, perhaps we can try and help you make it work. But if it’s in your project, there are many variables that can make it hard for us to pinpoint the problem. Sometimes it’s just running from an IDE instead of the CLI that executes an entirely different code path. Or it’s a parent POM that overrides/conflicts with dependencies. If you can start from scratch and build up an example, i’d start there
g
Hi @Matt (pactflow.io / pact-js / pact-go), Actually, the pact maven plugin has only the Groovy dependency, but it doesn't have dependencies for external custom libraries like AWS. If we are allowed to add external libraries to pact maven plugin that would help us to creatively use external libraries to support our requirement
👍 1
Sorry, I will try some ways to add the external dependencies to the PACT maven plugin and update you the progress @Matt (pactflow.io / pact-js / pact-go)
m
Honestly, in your case, I would remove auth from the contracts - it sounds really messy. I’d stub the authentication layer in your provider tests and move on.
Having to go to an external system during your Pact tests is a bit of a smell - the point of Pact tests is that they should be deterministic and reliable etc. You might find that running the AWS service locally would be a better use of your time - the tests will run faster, you’ll be able to test it locally, and the work to make it modular will make it more testable
y
Are you able to pair with your developers on this? You might find they will have a much easier time, co-ercing the code into a testable state. It is a good suggestion to consider mocking out the aws service locally, so you are isolating the provider under test from its own external deps. You can utilise tools such as localstack for this purpose
g
Hi @Matt (pactflow.io / pact-js / pact-go), Yeah, you are right We wanted to remove the auth part from the contract and populate it on the provider side, but our use case is that the same API. So wanted to test all the exact cases. So we will use an identifier from the client to mimic the same token on the provider side. So the flow goes like this 1. The client sends a header with the token identifier 2. During Verification, we will generate the token using the token identifier on the provider side I am using groovy script to populate the header with new fresh token. |
👍 1