Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiremock match request POST by params

I have a simple POST request sending params using application/x-www-form-urlencoded encoding.

Looking in the wiremock docs I can't find a way to match the request by the params values, something like the querystring match I mean.

Furthermore it seems also impossible to contains for the body, nor to match the entire body in clear (just as base64).

Is there a way to match this kind of requests?

like image 434
rascio Avatar asked Feb 05 '18 16:02

rascio


2 Answers

Another option that I found was to use contains for Stubbing Content-Type: application/x-www-form-urlencoded

{
  "request": {
    "method": "POST",
    "url": "/oauth/token",
    "basicAuthCredentials": {
      ...
    },
    "bodyPatterns": [
      {
        "contains": "username=someuser"
      }
    ]
  },
  "response": {
    ....
  }
}
like image 128
Harold Castillo Avatar answered Oct 01 '22 08:10

Harold Castillo


With classic wiremock you can use bodyPatterns' matchers and regular expressions:

for example:

...
"request": {
   "method": "POST",
   "url": "/api/v1/auth/login",
   "bodyPatterns": [
     {
       "matches": "(.*&|^)username=test($|&.*)"
     },
     {
       "matches": "(.*&|^)password=123($|&.*)"
     }
   ]
},
like image 33
RadekJ Avatar answered Oct 01 '22 08:10

RadekJ