Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial match and unordered match of request body #112

Open
mattburman opened this issue Apr 30, 2020 · 4 comments
Open

Partial match and unordered match of request body #112

mattburman opened this issue Apr 30, 2020 · 4 comments

Comments

@mattburman
Copy link

mattburman commented Apr 30, 2020

I want to match bodies with at least a set of specific key-value pairs in either a JSON-encoded or www-form-urlencoded body.

This is a probably insecure example but:
if Content-Type is application/json and the body is { "username": "*", "password": "*" } then i respond with 200. Any valid json string specifying the username and password would ideally match that, but instead it has to match exactly, spaces and all.
So the order of the fields shouldn't matter either e.g.:
{ "password": "*", "username": "*" } should be 200 too.

So then I could then match on just the username too for example, and say password required if there's at least some valid string with a username.
So I could match { "username": "*" } or {"username" :"*"} or any other valid json string to return something like password required.

And a similar behaviour for application/x-www-form-urlencoded - the order shouldn't matter in the string as long as the specified values match.

Is that kind of thing currently possible? I can't see an easy way to do it when body is just a string match.

@dkoontz
Copy link

dkoontz commented Aug 5, 2020

I am running into this exact same issue. I have a body where I want to match on one parameter, but the others will vary by test case and aren't relevant to the data I'm submitting. Example:

{ "A": "THIS FIELD IS CONSISTENT", "B": "THIS FIELD VARIES AND CAN BE IGNORED" }

I would like to be able to specify the body as

{ "A": "A REQUIRED VALUE", "B": * }

@ericchaves
Copy link

I am running into this exact same issue. I have a body where I want to match on one parameter, but the others will vary by test case and aren't relevant to the data I'm submitting. Example:

{ "A": "THIS FIELD IS CONSISTENT", "B": "THIS FIELD VARIES AND CAN BE IGNORED" }

I would like to be able to specify the body as

{ "A": "A REQUIRED VALUE", "B": * }

@dkoontz I had a similar issue until I figured that body payload must match the text exactly, the wildcard just allow anything in that position of the string. check if your submitted payload matches the break lines and spaces in your request config. I had a similar issue because my payload was sent as compacted JSON (one line, no spaces) and the config had break lines.

For example:

request:
 method: GET
  path: /
  body: >
    { "A": "A REQUIRED VALUE", "B": * }

should match a payload

{ "A": "A REQUIRED VALUE", "B": "THIS FIELD VARIES AND CAN BE IGNORED" }

but won't match

{ "A": "A REQUIRED VALUE", 
  "B": "THIS FIELD VARIES AND CAN BE IGNORED" }

@mroach
Copy link

mroach commented Sep 15, 2020

I also got stuck with this issue and was surprised to find it's doing string matching on a JSON body. Request matching already has queryStringParameters to match on a proper object which is great. I imagine the next logical extension would be doing this for request bodies, whether they be JSON or HTML multi-part.

Something like this for a parsable body.

  • The "*" lives-on as a string wildcard.
  • Fields can be marked as optional
  • Constraints on enum-type fields. Though this may be getting out of scope for a first draft of this.
request:
  method: POST
  path: /auth/sessions
  bodyParams:
    username: "*"
    password: "*"
    remember_me:
      one_of: ["true", "false"]
    another_field:
      optional: true

Same thing with JSON config:

{
  "request": {
    "method": "POST",
    "path": "/auth/sessions",
    "bodyParams": {
      "username": "*",
      "password": "*",
      "remember_me": {
        "one_of": [
          "true",
          "false"
        ]
      },
      "another_field": {
        "optional": true
      }
    }
  }
}

@dennypenta
Copy link

apparently it counts spaces as well on wildcard matching and ignores the application/json header to compare the objects.
so currently it supports only full body wildcard and not a partial matching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants