I am trying to create a mock server for handling functional tests in Karate. For that purpose I need to match certain incoming requests based on certain elements like method, path and presence of "Authorization" header in the incoming requests.
The condition I have is something like:
methodIs('get') && pathMatches('/mypath')
I need to write a condition for the presence of an "Authorization" header in the request.
As per documentation, we can use:
karate.get('requestHeaders.Authorization[0]') == 'foo'
However, when I am trying to use the above, it isn't working. I checked for the presence of requestHeaders.Authorization[0]
but that is being returned as Null
. My idea was to modify the above to something like karate.get('requestHeaders.Authorization[0]') == '#notnull'
.
I ended up trying headerContains('Authorization','')
, which seems to be working - however I am not sure if that is the right way to check for the presence of that specific header. Is there any other (better) way to do this?