【发布时间】:2021-07-17 15:24:29
【问题描述】:
我对 Amazon API Gateway 上的 API 进行了空手道测试。因此,在我的空手道测试中,我必须提供 client_id 和 client_secret 进行身份验证。我想知道是否有一种方法可以将凭据存储在我的 github 存储库之外并在运行时使用它。空手道可以做到吗?
这是我的测试的样子:
Feature: API Test all endpoints using Karate
Background:
* configure ssl = true
* url baseUrl
* def res = (env == 'qa'? 'classpath:endpoints/user-login.feature' : 'classpath:endpoints/user-login-dev.feature')
* def token = call read(res)
* def headerData = {Authorization: #(token.nextGen),Accept: 'application/json;v=1'}
* headers headerData
这里是 user-login.feature 文件
Feature: API Test using Karate
Background:
* configure ssl = true
Scenario: Get authorization header
Given url 'https://api.cloud.xyz.com/oauth2/token?client_id=****&client_secret=****&grant_type=client_credentials'
When method get
Then status 200
And def tokenType = response.token_type
And def accessToken = response.access_token
* def nextGen = tokenType + ' '+ accessToken
* def headerData = {Authorization: nextGen,Accept: 'application/json;v=1'}
关于如何在运行时将 client_id 和 client_secret 传递给测试而不存储在 github 中的任何指针。
提前致谢!
【问题讨论】:
-
如果你使用cyberark或类似的,我个人不喜欢从命令行加载它。也许从 java 代码中加载它(例如将它作为参数传递给运行器类)是一种选择。
标签: karate