regex 具有查询参数正则表达式匹配的Wirerock urlPattern

k5ifujac  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(127)

我有下面的wirerock设置&尝试使用regex设置urlPattern匹配。

{
  "scenarioName": "CPM Get Entitlements:Error - CPM_10000 - DOWNSTREAM_ERROR - Status 500",
  "request": {
    "method": "GET",
    "urlPattern": "<REGEX>"
  },
  "response": {
    "status": 500,
    "body": "{\"code\": \"CPM_10000\",\"description\": \"some description\"}"
  }
}

我的URL可以是这两个中的任何一个。
1.用户权限
1.服务器上的所有服务器都是本地服务器。服务器上的所有服务器都是本地服务器。
我已经尝试了各种REGEX模式,如下面的一个,但没有一个工作的第二个URL与查询参数。我可以构造的REGEX工作在文本编辑器或在java中,但它似乎是不工作的wirerock配置文件。

正则表达式

  • /家庭/.+/权利(.*)
  • /家庭/.+/权利(\?包括未来日期=true)
  • /家庭/.+/权利(?包括未来日期=true)

有没有办法在wiremock中修复这个问题?

xdyibdwo

xdyibdwo1#

我发现在这种情况下,在urlPathPattern上匹配比在urlPattern上匹配更容易,然后有一个单独的queryParameters匹配器。

{
  "scenarioName": "CPM Get Entitlements:Error - CPM_10000 - DOWNSTREAM_ERROR - Status 500",
  "request": {
    "method": "GET",
    "urlPathPattern": "/househould/.+/entitlements", // this should match your URL
    "queryParameters": {
      "includeFutureDated": {
        "or": [
          { "matches": "true" }, // update this to change your query parameter matching
          { "absent": true }, // this allows for a match when the query parameter is absent
        ],
      },
    },
  },
  "response": {
    "status": 500,
    "body": "{\"code\": \"CPM_10000\",\"description\": \"some description\"}"
  }
}

相关问题