Karate: Signing AWS HTTP requests & add the generated headers to the 'request headers'

家住魔仙堡 提交于 2021-02-11 00:23:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!