首先,感谢构建空手道,这对于测试API和UI非常有用。我们正在使用它来测试许多端点,但是我们想知道是否有一种方法或哪种方法是处理标题中请求的一部分的签名请求的最佳方法。
情况
而在请求主体内容执行请求之前?
在这里,您可以看到请求的两个示例
样本1:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'YYY'
And request { }
When method POST
Then status 200
样本2:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'ZZZ'
And request { name: 'John' }
When method POST
Then status 200
谢谢
First of all, thanks for build karate it's a very useful for test API's and UI's. We are using it to test a lot of our endpoints but we would like to know if there is a way or which is the best approach to handle requests with signature as part of the request in the header.
In our case we have two headers:
- ApiKey: this value is always the same
- Signature: this value depends on the request body content
Is there any way to inject the signature value just before the request is executed based on the request body content?
Here you can see two samples of the requests
Sample 1:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'YYY'
And request { }
When method POST
Then status 200
Sample 2:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'ZZZ'
And request { name: 'John' }
When method POST
Then status 200
Thanks
发布评论
评论(1)
空手道有一个用于生成标头的“钩子”,但截至目前,它尚未“意识到”当前构建的请求主体 +标头: https://github.com/intuit/karate#configure-headers
我们在这里收到了类似的请求,并且正在考虑添加此功能:在在空手道DSL中进行休息之前,如何检索原始请求内容?
也许OAuth示例可能会为您提供案例的前进: https://stackoverflow.com/a/a/55055111/143475
可以随意提出增强请求版本(在您的帮助下进行测试)。我在想 - 如果您能够从标题JS函数中调用
bacarate.get('request')
怎么办。但是目前,您需要做的就是这样做:
在
header.js
函数中编辑:这将在空手道1.0上实现: https://github.com/intuit/karate/karate/issues/1385
Karate has a "hook" for generating headers, but as of now it is not "aware" of the currently built request body + headers: https://github.com/intuit/karate#configure-headers
We got a similar request here, and are thinking of adding this capability: How to retrieve raw request contents before making a REST call in Karate DSL?
Maybe the OAuth examples will give you the way forward for your case for now: https://stackoverflow.com/a/55055111/143475
Feel free to raise an enhancement request, and we can get this in to the next version (with your help to test it). I'm thinking - what if you are able to call
karate.get('request')
from within the header JS function.But for now all you need to do is do something like this:
And in the
header.js
functionEDIT: this will be implemented in Karate 1.0 onwards: https://github.com/intuit/karate/issues/1385