1

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.

Sud
  • 166
  • 12

1 Answers1

0

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

Also see: How to handle requests with signatures on karate tests?

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Perfect, I will have a look @Peter & get back to you. – Sud Mar 08 '19 at 22:16
  • [peter](https://stackoverflow.com/users/143475/peter-thomas) We tried the above way of getting AWS IAM credentials and we can achieve it. The problem is that we already have a lot of spring beans which we would like to reuse e.g., Custom AWS Signer configured on apache HTTP client. Is there a way to start a spring context in karate similar to cucumber CLI (i..e, cucumber.api.cli.main) – Sud Mar 11 '19 at 17:33
  • 1
    My original query is answered hence i am closing this. Will raise new queries if i bump into other issues. – Sud Mar 13 '19 at 15:33