简体   繁体   中英

Mountebank predicates doesn't check headers

I have below code and looks like it is not checking headers as a predicate.

{
  "responses": [
    {
      "inject": "<%- stringify(filename, 'Scripts/MyDept/CutOffTime.ejs') %>"
    }
  ],
  "predicates": [
    {
      "matches": {
        "method": "GET",
        "path": "/cutoff-times",
        "query": {
          "country": "\\w+"
        },
        "headers": {
          "X-CLIENT-ID": "^[ A-Za-z0-9]*$"
        }
      }
    }
  ]
}

Strangely, when I pass @ as the value to header X-CLIENT-ID it validate and shows the message as no predicate match. Because it is not part of the regex.

Identified the issue,

Basically if you need have multiple predicates need to merge them as below,(using and / or)

{
  "responses": [
    {
      "inject": "<%- stringify(filename, 'Scripts/MyDept/CutOffTime.ejs') %>"
    }
  ],
  "predicates": [
        {
          "and": [
            {
              "exists": {
                "headers": {
                  "X-CLIENT-ID": true,
                  }
              }
            },
            {
              "matches": {
                "method": "GET",
                "path": "/cutoff-times",
                "headers": {
                  "X-CLIENT-ID": "^[ A-Za-z0-9]*$"
                },
                "query": {
                  "country": "\\w+"
                  }
              }
            }
          ]
        }
      ]
  }

Mountebank site

Further matches predicate doesn't check the existence (eg header existence)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM