How to determine non-existent field(s) in cookies and headers? #249

Closed
opened 2025-12-29 08:24:43 +01:00 by adam · 10 comments
Owner

Originally created by @qq362220083 on GitHub (Feb 10, 2020).

I want to judge non-existent fields in cookie (header, param), such as "Authentication".

I found mapping files cannot implement this logic.

How to solve this problem?

thanks!

Originally created by @qq362220083 on GitHub (Feb 10, 2020). I want to judge non-existent fields in cookie (header, param), such as "Authentication". I found mapping files cannot implement this logic. How to solve this problem? thanks!
adam added the question label 2025-12-29 08:24:43 +01:00
adam closed this issue 2025-12-29 08:24:43 +01:00
Author
Owner

@qq362220083 commented on GitHub (Feb 10, 2020):

I tried to solve this problem by creating property on the cookie model (header & param model) object, but I found that the change exceeded my expectations, so I hope the author can help me!

@qq362220083 commented on GitHub (Feb 10, 2020): I tried to solve this problem by creating property on the cookie model (header & param model) object, but I found that the change exceeded my expectations, so I hope the author can help me!
Author
Owner

@StefH commented on GitHub (Feb 10, 2020):

What do you mean by judge ?

Do you want to match a mapping when a cookie is absent?

@StefH commented on GitHub (Feb 10, 2020): What do you mean by **judge** ? Do you want to match a mapping when a cookie is absent?
Author
Owner

@qq362220083 commented on GitHub (Feb 10, 2020):

Yes, you're right!

i want to match a mapping when a cookie(header or param) is absent.

@qq362220083 commented on GitHub (Feb 10, 2020): Yes, you're right! i want to match a mapping when a cookie(header or param) is absent.
Author
Owner
@StefH commented on GitHub (Feb 11, 2020): Take a look at : https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#reversing-the-match-behaviour-with-matchbehaviourrejectonmatch
Author
Owner

@qq362220083 commented on GitHub (Feb 11, 2020):

thanks. I have seen it, but I want to use mapping files to solve it.

@qq362220083 commented on GitHub (Feb 11, 2020): thanks. I have seen it, but I want to use mapping files to solve it.
Author
Owner

@StefH commented on GitHub (Feb 11, 2020):

This is possible using mappings. See the updated WIKI page.

@StefH commented on GitHub (Feb 11, 2020): This is possible using mappings. See the updated WIKI page.
Author
Owner

@qq362220083 commented on GitHub (Feb 11, 2020):

Sorry, I tested it according to the wiki and found that it still doesn't work.

take a look at:
https://github.com/WireMock-Net/WireMock.Net/blob/83866f57192fa54125595592cc09210fbc5bbfdd/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs#L122-L125

the _matchBehaviour variable is still the default value AcceptOnMatch.

@qq362220083 commented on GitHub (Feb 11, 2020): Sorry, I tested it according to the wiki and found that it still doesn't work. take a look at: [https://github.com/WireMock-Net/WireMock.Net/blob/83866f57192fa54125595592cc09210fbc5bbfdd/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs#L122-L125](https://github.com/WireMock-Net/WireMock.Net/blob/83866f57192fa54125595592cc09210fbc5bbfdd/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs#L122-L125) the ```_matchBehaviour``` variable is still the default value ```AcceptOnMatch```.
Author
Owner

@StefH commented on GitHub (Feb 15, 2020):

Can you try MyGet version:
WireMock.Net.1.1.7-ci-12734.nupkg?

It should be used like:

  {
    "Guid": "f4f0be0c-089d-407c-95a2-5a90375b9382",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/needs-a-key",
            "IgnoreCase": true
          }
        ]
      },
      "Headers": [
        {
          "Name": "api-key",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "*",
              "IgnoreCase": true
            }
          ],
          "RejectOnMatch": true
        }
      ]
    },
    "Response": {
      "StatusCode": 401,
      "BodyDestination": "SameAsSource",
      "Body": "{ \"result\": \"api-key missing\"}"
    }
  }
@StefH commented on GitHub (Feb 15, 2020): Can you try MyGet version: `WireMock.Net.1.1.7-ci-12734.nupkg`? It should be used like: ``` jspn { "Guid": "f4f0be0c-089d-407c-95a2-5a90375b9382", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/needs-a-key", "IgnoreCase": true } ] }, "Headers": [ { "Name": "api-key", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "*", "IgnoreCase": true } ], "RejectOnMatch": true } ] }, "Response": { "StatusCode": 401, "BodyDestination": "SameAsSource", "Body": "{ \"result\": \"api-key missing\"}" } } ```
Author
Owner

@qq362220083 commented on GitHub (Feb 20, 2020):

Wow, this code is great!

i want to pull request #423 to master branche

@qq362220083 commented on GitHub (Feb 20, 2020): Wow, this code is great! i want to pull request #423 to master branche
Author
Owner

@StefH commented on GitHub (Feb 20, 2020):

I will merge this code in 2days and also create new NuGet

@StefH commented on GitHub (Feb 20, 2020): I will merge this code in 2days and also create new NuGet
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#249