BDD测试在任何点平台上进行监视

发布于 2025-02-03 08:55:30 字数 1508 浏览 4 评论 0原文

我正在创建在任何点平台上监视的测试。首先,我有一些终点来生成令牌,我想在标题中使用此令牌。

import * from bat::BDD
import * from bat::Assertions

var context = bat::Mutable::HashMap() // <--- First, the HashMap

var headers = {
  'example': 'test'
}
---
describe `token jwt` in [
  it should "take token" in [
  GET `example: some endpoind to get token` with {
    headers: headers
     
  } assert [
  
    $.response.status mustEqual 200
  
  ] execute [
    context.set('token', $.response.payload[26 to 102]), // <--- Setting token
    log(context.get('token'))
  ]
 
  ],

  it should "token header" in [
    POST `example: endpoint with token in headers` with {
      headers: {
 
      'token': context.get('token'),
      'Content-Type': 'application/json'

},
      body: 
        {
    "test": "example"

      } 
    } assert [
      $.response.status mustEqual 200, 
       $.request.headers.token mustEqual context.get('token')
    ]
    execute  [
      log(context.get('token'))
    ]
  ]
]

有人可以帮助我如何在标题中使用这个令牌?我有一个错误:

 message: "You called the function 'wrappedRequest' with these arguments: \n 
 1: String (\"POST\")\n  2: String (\""example: endpoint with token in headers)\n 
 3: Object ({headers: {"token: \"exampleToken...)\n\n
 But it expects arguments of these types:\n  1: String\n  2: String\n  3: HttpCustomOptions\n",
 
 "location": "\n144|     wrappedRequest(method, stringInterpolation(parts, interpolation map $ as String), configDelegate(null, null))\n

I'm creating the test for monitoring on anypoint platform. And first I have some endpoint to generate the token and the I would like use this token in header.

import * from bat::BDD
import * from bat::Assertions

var context = bat::Mutable::HashMap() // <--- First, the HashMap

var headers = {
  'example': 'test'
}
---
describe `token jwt` in [
  it should "take token" in [
  GET `example: some endpoind to get token` with {
    headers: headers
     
  } assert [
  
    $.response.status mustEqual 200
  
  ] execute [
    context.set('token', $.response.payload[26 to 102]), // <--- Setting token
    log(context.get('token'))
  ]
 
  ],

  it should "token header" in [
    POST `example: endpoint with token in headers` with {
      headers: {
 
      'token': context.get('token'),
      'Content-Type': 'application/json'

},
      body: 
        {
    "test": "example"

      } 
    } assert [
      $.response.status mustEqual 200, 
       $.request.headers.token mustEqual context.get('token')
    ]
    execute  [
      log(context.get('token'))
    ]
  ]
]

Someone could help me how I can use this token in header ? I have this error:

 message: "You called the function 'wrappedRequest' with these arguments: \n 
 1: String (\"POST\")\n  2: String (\""example: endpoint with token in headers)\n 
 3: Object ({headers: {"token: \"exampleToken...)\n\n
 But it expects arguments of these types:\n  1: String\n  2: String\n  3: HttpCustomOptions\n",
 
 "location": "\n144|     wrappedRequest(method, stringInterpolation(parts, interpolation map $ as String), configDelegate(null, null))\n

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤浅笑 2025-02-10 08:55:30

发布或获得的第一个论点是URL。看起来您正在传递描述(示例:端点eNDPOINT in Headers in Headers)。同样,当您具有授权令牌时,通常会在标准授权 http标头中发送。

例子:

POST `http://somehost/somepath` with {
      headers: {
         Authorization: context.get('token'),
         ...
      }
      ...
},

The first argument to POST or GET is the URL. It looks like you are passing a description instead (example: endpoint with token in headers). Also when you have an authorization token usually it is sent in the standard Authorization HTTP header.

Example:

POST `http://somehost/somepath` with {
      headers: {
         Authorization: context.get('token'),
         ...
      }
      ...
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文