mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Can't detect non present header fields #489
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 @MichaelIDS on GitHub (Feb 16, 2023).
I was trying to do bad/missing header field detection.
I could detect the values of a header fine when it was present, however, I can't seem to get anything to trigger when it's not present.
I lifted the below api-key check from the Wiki, but for me this doesn't ever trigger.
Log output for sample request without this Header field provided.
@MichaelIDS commented on GitHub (Feb 16, 2023):
I also tried a simple ExactMatcher and neither RejectOnMatch true or false matched.
If I remove the header check entirely then it matches, so I know the path element is correct.
Built against WireMock 1.5.16 from NuGet.
@MichaelIDS commented on GitHub (Feb 17, 2023):
As a workaround I set a requirement on my valid response for a wildcard result "*" for this header, thus stopping a request missing it from reaching the valid response matcher. It does mean that it ends up in my final generic catch-all bad request mapping, which is less ideal, but documentable.
EDIT: I have ended up with a second catch-all request handler to differentiate requests missing this header from any other unhandled bad requests. But I hoped to avoid this as it means I have duplication of request requirement logic across multiple mappings.
@StefH commented on GitHub (Mar 23, 2023):
@MichaelIDS

From your logging:
It seems that the path is not matched, which means that the whole mapping is not matched.
@MichaelIDS commented on GitHub (Mar 23, 2023):
In the log it has the path captured and it looks identical to the stub definition in the original message here to me.
@StefH commented on GitHub (Mar 23, 2023):
@MichaelIDS
I did some testing and this works, but you have to configure the mapping for the header in a different way.
It should be:
This means that when the header-key ("api-key") or "API-Key" (ignorecase = true) is missing the header mapping will match because RejectOnMatch is true.
I'll add this to the wiki.