:wave: I've hit somewhat of a roadblock in impleme...
# pact-js
m
๐Ÿ‘‹ I've hit somewhat of a roadblock in implementation. I've created provider tests for an AWS API Gateway application and I've been invoking the API directly in the tests, adding the proper authentication headers to each request. When using aws sig4 to sign requests, if the API requires a body, the signature must also include the body of the request. I'm looking for a way to intercept the body from each consumer pact and grab it to add to the signature. I'm currently using the
requestFilter
to intercept each request and add the auth to the headers, but the request object passed in doesn't contain a body. I've attempted to use SAM CLI to host the API gateway (to bypass auth) but it seems the way we've structured our stacks, the automated
sam local start-api
command can't find the lambda functions that we tie to each api. Only other way to use SAM afaik is to hardcode each endpoint into the template.yaml file, and include each request/response model, which isn't viable for our teams to do. TIA!
๐Ÿ‘‹ 1
y
Hey buddy I used something similar to this on my client site https://github.com/YOU54F/jest-pact-typescript/blob/master/src/pact/verifier/verify.ts I had the same issue as you, there is an open feature request on pact js GitHub issues and @bernardodazn did a really good medium article on a bit of a workaround, Iโ€™ll find a link
https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78 Basically you pull the pact down prior and get access to the pact object beforehand and you can monkey patch your requests, with the obvious caveats before passing them to a verifier
m
@Yousaf Nabi (pactflow.io) this is excellent! The medium article workaround isn't viable but I can try looking into v3 as suggested in that Github Issue. Thanks for the help!
๐Ÿ‘ 1
y
No worries Mike :) Just reread the issue, will set myself a reminder to update the main post with a summary of discussion and clearly distinguish that itโ€™s a v2 issue and point to an example of it working in v3 :)
m
I'm attempting to get it working with v3 right now. If you come across an example of it, feel free to drop it here. I'm also happy to add my code as an example on that github issue once i get it working ๐Ÿ™‚
@Yousaf Nabi (pactflow.io) No luck with v3. When I attempt to use the requestFilters property and return an object like the documentation suggests, it fails. It really wants the
next
callback to be executed.
The last option i'm holding in my back pocket is to make a request to the pact broker myself and parse out any request bodies there and sign with them within each state handler.
y
Yeah just had a quick play with v3 and still not able to access the incoming body, I may be able to overwrite it, but as yourself for our use case, we needed to access the request body to send it in the AWS v4 sig request to get the appropriate headers. I did indeed choose the latter option that is in your back pocket to get round it on our account. I have to say I do like the v3 interface. Will take a delve further when I get a bit more time. Good luck buddy
m
Sounds good. Thanks so much for the help @Yousaf Nabi (pactflow.io)!