在空手道DSL中进行REST调用之前,如何检索原始请求内容? [英] How to retrieve raw request contents before making a REST call in Karate DSL?

查看:56
本文介绍了在空手道DSL中进行REST调用之前,如何检索原始请求内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上是试图生成AWS签名,以便将其用于授权.我们拥有第三方Java库(uk.co.lucasweb.aws.v4.signer)来生成此AWS签名.使用Java Interop的概念,我可以调用它们并检索签名.但是我必须在参数中传递所有请求详细信息(URL,标头,参数)才能生成请求. (getSignature()是使用规定的库编写的自定义java方法)

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()方法的实现看起来像这样

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();

空手道DSL:

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

场景:获取AWS签名

 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 

使用空手道DSL构成请求后,我需要一种方法来检索内容,以便可以在如下所示的参数中传递它们

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

我知道我们有一项规定,可以使用karate.prevRequest进行通话.但是,在进行调用之前,我们是否有任何准备来检索原始请求数据.也参考了oAuth2和签署者文档,但找不到任何解决方案

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

推荐答案

您可以查看ExecutionHook是否为您提供了一种方法,否则这可能是功能请求:https://stackoverflow.com/a/59080128/143475

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.

这篇关于在空手道DSL中进行REST调用之前,如何检索原始请求内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆