Mountebank predicates doesn't check headers

1.1k Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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 (e.g. header existence)