mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-13 05:50:36 +01:00
Post request with "BodyAsBytes" is not matched by RegexMatcher #354
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @FSatmar on GitHub (Aug 4, 2021).
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
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.
@StefH commented on GitHub (Aug 4, 2021):
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
AnyBytesMatcherwill be added, which can be used to detect if the body contains any bytes.Another option would be to update the
ExactObjectMatcherwhich can take a base64 string which defines the exact body you want to match.@FSatmar commented on GitHub (Aug 4, 2021):
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.
@StefH commented on GitHub (Aug 4, 2021):
I've added a
NotNullOrEmptyMatcherwhich 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
@FSatmar commented on GitHub (Aug 4, 2021):
This works great, thank you very much!
@StefH commented on GitHub (Aug 4, 2021):
@FSatmar OK
I'll merge the PR and create a new official version in some time.