【问题标题】:Karate Test Framework -Storing credentials outside of github空手道测试框架 - 在 github 之外存储凭据
【发布时间】:2021-07-17 15:24:29
【问题描述】:

我对 Amazon API Gateway 上的 API 进行了空手道测试。因此,在我的空手道测试中,我必须提供 client_idclient_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_idclient_secret 传递给测试而不存储在 github 中的任何指针。

提前致谢!

【问题讨论】:

  • 如果你使用cyberark或类似的,我个人不喜欢从命令行加载它。也许从 java 代码中加载它(例如将它作为参数传递给运行器类)是一种选择。

标签: karate


【解决方案1】:

最简单的方法是通过命令行将它们作为 Java 系统属性传递,您可以通过测试或 CI 触发的运行非常轻松地做到这一点。

请参阅此处的文档:https://github.com/intuit/karate#dynamic-port-numbers

在您的情况下的外观示例:

Given url 'https://api.cloud.xyz.com/oauth2/token'
And param client_id = karate.properties['client.id']
And param client_secret = karate.properties['client.secret']
And param grant_type = 'client_credentials'

在命令行上:

mvn test -DargLine="-Dclient.id=**** -Dclient.secret=**** -Dkarate.env=qa"

【讨论】:

    猜你喜欢
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多