问题
The internal API's we test need to go through the process of signing them (i.e., get AWS Signature) & add the signed headers to 'request headers' before we do any CRUD operation.
Signing the requests can happen through AWS-SDK or using something like this https://github.com/lucasweb78/aws-v4-signer-java (if our tests are written completely in Java)
What would be the optimum way of achieving this in Karate DSL. Please suggest.
回答1:
Read the docs: https://github.com/intuit/karate#http-basic-authentication-example
For example this is how you do basic auth:
function fn(creds) {
var temp = creds.username + ':' + creds.password;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.bytes);
return 'Basic ' + encoded;
}
The point here is you can plug in any Java code. You can also look at the OAuth examples for more ideas: https://github.com/intuit/karate/tree/master/karate-demo/src/test/java/demo/oauth
来源:https://stackoverflow.com/questions/55050754/karate-signing-aws-http-requests-add-the-generated-headers-to-the-request-he