WireMock.Net: FormEncoded Request fails (404 Not Found) if key value pairs order in mapping is different from request body order

Describe the bug

When trying to use the ExactMatcher or RegexMatcher to match a form encoded request, it fails (404 Not Found) if they order of the form encoded request is different from that in the json mapping file.

Expected behavior:

Ordering of FormEncoded Body requests should not affect matching as it might not always be convenient to control the ordering. If it is going to be a breaking change to fix this, a flag like IgnoreFormEncodedBodyOrder can be provided to override the default.

Test to reproduce

  • 1 Clone Repo, and build.
  • 2 Run the built demo. (Incase you get an error the first time you run the Demo, close it and run again.).

Other related info

Docker is needed to run the Demo as it uses WireMock.NET Test Container.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19

Most upvoted comments

sure, on it.

@Xor-el Currently the latest is always used. Would it be needed to add an option to manually specify the version when using the containerbuilder? Or is this not needed?

@StefH my bad actually. I forgot to clear my Stale Docker Image Cache so my test container was using the old cached 1.5.60 instead of the latest 1.5.62 image.

Thanks for your time.

I’ve just updated the code so that wildcards are supported. See the FormUrlEncodedMatcherTest for details.

and if it’s the other way,

"Patterns": [
           "grant_type=client_credentials"
         ]

And the body contains grant_type=client_credentials, client_id=DDCD99EE1531484E4E21D5EC9FBA5D8B, and client_secret=RERDRDk5RUUxNTMxNDg0RTRFMjFENUVDOUZCQTVEOEI%3D I am guessing the matching would still work right or only the FormUrlEncodedPartialMatcher would work then?

This does already work like it is because Or is used.

By default the MatchOperator is set to Or. So when the matcher is like:

 "Patterns": [
           "grant_type=client_credentials",
           "client_id=DDCD99EE1531484E4E21D5EC9FBA5D8B",
           "client_secret=RERDRDk5RUUxNTMxNDg0RTRFMjFENUVDOUZCQTVEOEI%3D"
         ]

And the body only contains grant_type=client_credentials, this matcher will match.


A FormUrlEncodedPartialMatcher could be used like this (I think)…

"Patterns": [
           "grant_type=*",
           "client_id=DD*",
           "*=RERDRDk5RUUxNTMxNDg0RTRFMjFENUVDOUZCQTVEOEI%3D"
         ]

I’ll check if I can change the implementation from the FormUrlEncodedMatcher to use internally the WildcardMatcher for string compare…

Hello @StefH thanks for your quick feedback. I agree with your suggestion that adding a new matcher would be overall a better approach to address this. Thanks for looking into this.