WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Post request with "BodyAsBytes" is not matched by RegexMatcher

Open FSatmar opened this issue 5 years ago • 5 comments

Describe the bug

When a mapping is in place for a Post request with Body RegexMatcher = ".*" and a request with "BodyAsBytes" is made, the mapping is not returned.

Expected behavior:

The mapping should be returned since the RegexMatcher should match any body content.

Test to reproduce

  • 1 create Post mapping with RegexMatcher = ".*"
  • 2 make request with "BodyAsBytes"

Other related info

Please see attached files for examples of mapping and requests. Note that Request1with String body type works, while Request2 with BodyAsBytes fails. Mapping.txt Request1.txt Request2.txt Also note that this used to work fine in version 1.0.9.

FSatmar avatar Aug 04 '21 11:08 FSatmar

Hello @FSatmar ,

I understand your point, however when the body is just bytes, a RegExMatcher/WildcardMatcher (= StringMatcher) cannot be used because I never know if the bytes area actually a string (and which encoding is used).

So I think what could be a solution for you is that a new matcher like AnyBytesMatcher will be added, which can be used to detect if the body contains any bytes.

Another option would be to update the ExactObjectMatcher which can take a base64 string which defines the exact body you want to match.

StefH avatar Aug 04 '21 12:08 StefH

Is there an option to define a matcher that would match any type of body and any content? as in this case I don't care about the body content. otherwise, it seems I'll need to create 2 mappings, one for each body type.

FSatmar avatar Aug 04 '21 12:08 FSatmar

I've added a NotNullOrEmptyMatcher which should be possible to use for string, json and bytes.

Try the MyGet preview version: 1.4.19-ci-15242.

https://github.com/WireMock-Net/WireMock.Net/pull/625

StefH avatar Aug 04 '21 13:08 StefH

I've added a NotNullOrEmptyMatcher which should be possible to use for string, json and bytes.

Try the MyGet preview version: 1.4.19-ci-15242.

#625

This works great, thank you very much!

FSatmar avatar Aug 04 '21 13:08 FSatmar

@FSatmar OK

I'll merge the PR and create a new official version in some time.

StefH avatar Aug 04 '21 13:08 StefH