1

I am basically trying to generate AWS signature in order to use them for Authorization. We have third party java libraries (uk.co.lucasweb.aws.v4.signer) to generate this AWS signature. Using the concept of Java Interop, I would be able to call them and retrieve the signature. But I will have to pass all the request details (url, header, param) in the arguments in order to generate it. (getSignature() is a custom java method which was written using the prescribed library)

getSignature() method's implementation would look something like this

   String contentSha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
    HttpRequest request = new HttpRequest("GET", new URI(URL));
    String signature = Signer.builder()
            .awsCredentials(new AwsCredentials(ACCESS_KEY, SECRET_KEY))
            .header("Host", "examplebucket.s3.amazonaws.com")
            .header("x-amz-date", "20130524T000000Z")
            .header("x-amz-content-sha256", contentSha256)
            .buildS3(request, contentSha256)
            .getSignature();

Karate DSL :

* def awsUtils = Java.type('customJavaClasses.AWSUtils')
* url 'https://sit.ecom.com/atp-config-entity-dev'

Scenario: get AWS signature

 Given path '/v1/atp-config-entity/config'
 And header wtr-correlation-id = '58f3de9b-6276-4f05-a78d-0a39c6044877'
 And header customer-id = '279809907'
 And header principal-id = '279809906'
 And header X-Amz-Date = '20200325T120000Z'
 And def requestPayload = read('request.json')
 And request requestPayload 

Once the request is composed using Karate DSL, I need a way to retrieve the contents, so that I can pass them in the arguments as shown below

And def signature = awsUtils.getSignature(url, headers, params);
And header Authorization = signature
When method post
Then status 200

I am aware that we have a provision to do that after making a call using karate.prevRequest. But do we have any provision to retrieve the raw request data before we make the call. Have referred oAuth2 and signer documentation as well but couldn't find any solution

Deepak Prabhu
  • 219
  • 1
  • 4
  • 15

1 Answers1

0

You can see if the ExecutionHook gives you a way, else this may be a feature request: https://stackoverflow.com/a/59080128/143475

We are actually doing a refactor of the code right now - and I agree this use-case is important, so we can consider it.

EDIT: this is now possible in Karate, refer: https://stackoverflow.com/a/65019538/143475 and https://github.com/karatelabs/karate/issues/1385

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248