Header not being processed ? #488

Closed
opened 2025-12-29 08:29:00 +01:00 by adam · 1 comment
Owner

Originally created by @MichaelIDS on GitHub (Feb 16, 2023).

Whenever I send a test request to this static mapping I always get the first result back (priority 1). Even when I have the correct header for Content-Type.

[
    {
        "Swagger Doc Title": "Bad Request",
        "Comment": "Bad Content-Type",
        "Priority": 1,
        "Request": {
            "Path": {
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "/timeEntry"
                    }
                ]
            },
            "Methods": [
                "post"
            ],
            "Headers": [
				{
					"Name": "Content-Type",
					"Matcher": {
						"Name": "ExactMatcher",
						"Pattern": "application/json",
                        "RejectOnMatch": true
					}
				}
			]
        },
        "Response": {
            "StatusCode": 400,
            "Headers": {
                "Content-Type": "application/json"
            },
            "BodyAsJson": {
                "errorMessage": "Validation exception",
                "status": 400,
                "WireMock reason": "bad content-type"
            },
            "UseTransformer": false
        }
    },
    {
        "Swagger Doc Title": "Successfully created time entries",
        "Comment": "Everything correct ",
        "Priority": 50,
        "Request": {
            "Path": {
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "/timeEntry"
                    }
                ]
            },
            "Headers": [
                {
                    "Name": "Authorization",
                    "Matcher": {
                        "Name": "WildcardMatcher",
                        "Comment": "TODO: validate JWT token format",
                        "Pattern": "bearer *"
                    }
                }
            ],
            "Methods": [
                "post"
            ]
        },
        "Response": {
            "StatusCode": 200,
            "Headers": {
                "Content-Type": "application/json"
            },
            "BodyAsJson": {
                "message": "Time entry data accepted.",
                "status": 200,
                "success": true
            },
            "UseTransformer": false
        }
    },
    {
        "Swagger Doc Title": "Bad Request",
        "Comment": "A final catch all on the URL path.",
        "Priority": 100,
        "Request": {
            "Path": {
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "/timeEntry"
                    }
                ]
            }
        },
        "Response": {
            "StatusCode": 400,
            "Headers": {
                "Content-Type": "application/json"
            },
            "BodyAsJson": {
                "errorMessage": "Validation exception",
                "status": 400,
                "WireMock reason": "catch all"
            },
            "UseTransformer": false
        }
    }
]

Se example request that should trigger the priority 50 one, but didn't.

2023-02-16 13:09:35,109 [3] DEBUG Program - Admin[False] {
  "Guid": "1689e673-3b30-41b4-be30-3141912deea6",
  "Request": {
    "ClientIP": "::1",
    "DateTime": "2023-02-16T13:09:35.0532814Z",
    "Path": "/timeEntry",
    "AbsolutePath": "/timeEntry",
    "Url": "http://localhost:9091/timeEntry",
    "AbsoluteUrl": "http://localhost:9091/timeEntry",
    "ProxyUrl": null,
    "Query": {},
    "Method": "POST",
    "Headers": {
      "Postman-Token": [
        "eb4cc60d-c6ca-4ba7-b762-e424dee50b7c"
      ],
      "Connection": [
        "keep-alive"
      ],
      "Content-Length": [
        "54"
      ],
      "Content-Type": [
        "application/json"
      ],
      "Accept": [
        "*/*"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br"
      ],
      "Authorization": [
        "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
      ],
      "Host": [
        "localhost:9091"
      ],
      "User-Agent": [
        "PostmanRuntime/7.31.0"
      ]
    },
    "Cookies": {},
    "Body": "{\n  \"username\": \"username\",\n  \"password\": \"password\"\n}",
    "BodyAsJson": {
      "username": "username",
      "password": "password"
    },
    "BodyAsBytes": null,
    "BodyEncoding": {
      "CodePage": 65001,
      "EncodingName": "Unicode (UTF-8)",
      "WebName": "utf-8"
    },
    "DetectedBodyType": "Json",
    "DetectedBodyTypeFromContentType": "Json"
  },
  "Response": {
    "StatusCode": 400,
    "Headers": {
      "Content-Type": [
        "application/json"
      ]
    },
    "BodyDestination": null,
    "Body": null,
    "BodyAsJson": {
      "errorMessage": "Validation exception",
      "status": 400,
      "WireMock reason": "bad content-type"
    },
    "BodyAsBytes": null,
    "BodyAsFile": null,
    "BodyAsFileIsCached": null,
    "BodyOriginal": null,
    "BodyEncoding": null,
    "DetectedBodyType": 2,
    "DetectedBodyTypeFromContentType": null,
    "FaultType": null,
    "FaultPercentage": null
  },
  "MappingGuid": "b0a41442-eef5-4f5e-9cf9-aa2943052995",
  "MappingTitle": null,
  "RequestMatchResult": {
    "TotalScore": 2.0,
    "TotalNumber": 2,
    "IsPerfectMatch": true,
    "AverageTotalScore": 1.0,
    "MatchDetails": [
      {
        "Name": "PathMatcher",
        "Score": 1.0
      },
      {
        "Name": "MethodMatcher",
        "Score": 1.0
      }
    ]
  },
  "PartialMappingGuid": "b0a41442-eef5-4f5e-9cf9-aa2943052995",
  "PartialMappingTitle": null,
  "PartialRequestMatchResult": {
    "TotalScore": 2.0,
    "TotalNumber": 2,
    "IsPerfectMatch": true,
    "AverageTotalScore": 1.0,
    "MatchDetails": [
      {
        "Name": "PathMatcher",
        "Score": 1.0
      },
      {
        "Name": "MethodMatcher",
        "Score": 1.0
      }
    ]
  }
}

On my other (first) endpoint stubs I did positive detection as first (lowest priority value) and then the incomplete detection as later (higher priority values) fallback detection. But I found with this new one I needed to confirm both the headers content-type and authorization, and with WireMock just doing "or" comparisons I thought maybe this invalid stubbing checking was the excepted usage route?

Originally created by @MichaelIDS on GitHub (Feb 16, 2023). Whenever I send a test request to this static mapping I always get the first result back (priority 1). Even when I have the correct header for Content-Type. ``` [ { "Swagger Doc Title": "Bad Request", "Comment": "Bad Content-Type", "Priority": 1, "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/timeEntry" } ] }, "Methods": [ "post" ], "Headers": [ { "Name": "Content-Type", "Matcher": { "Name": "ExactMatcher", "Pattern": "application/json", "RejectOnMatch": true } } ] }, "Response": { "StatusCode": 400, "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "errorMessage": "Validation exception", "status": 400, "WireMock reason": "bad content-type" }, "UseTransformer": false } }, { "Swagger Doc Title": "Successfully created time entries", "Comment": "Everything correct ", "Priority": 50, "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/timeEntry" } ] }, "Headers": [ { "Name": "Authorization", "Matcher": { "Name": "WildcardMatcher", "Comment": "TODO: validate JWT token format", "Pattern": "bearer *" } } ], "Methods": [ "post" ] }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "message": "Time entry data accepted.", "status": 200, "success": true }, "UseTransformer": false } }, { "Swagger Doc Title": "Bad Request", "Comment": "A final catch all on the URL path.", "Priority": 100, "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/timeEntry" } ] } }, "Response": { "StatusCode": 400, "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "errorMessage": "Validation exception", "status": 400, "WireMock reason": "catch all" }, "UseTransformer": false } } ] ``` Se example request that should trigger the priority 50 one, but didn't. ``` 2023-02-16 13:09:35,109 [3] DEBUG Program - Admin[False] { "Guid": "1689e673-3b30-41b4-be30-3141912deea6", "Request": { "ClientIP": "::1", "DateTime": "2023-02-16T13:09:35.0532814Z", "Path": "/timeEntry", "AbsolutePath": "/timeEntry", "Url": "http://localhost:9091/timeEntry", "AbsoluteUrl": "http://localhost:9091/timeEntry", "ProxyUrl": null, "Query": {}, "Method": "POST", "Headers": { "Postman-Token": [ "eb4cc60d-c6ca-4ba7-b762-e424dee50b7c" ], "Connection": [ "keep-alive" ], "Content-Length": [ "54" ], "Content-Type": [ "application/json" ], "Accept": [ "*/*" ], "Accept-Encoding": [ "gzip, deflate, br" ], "Authorization": [ "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ], "Host": [ "localhost:9091" ], "User-Agent": [ "PostmanRuntime/7.31.0" ] }, "Cookies": {}, "Body": "{\n \"username\": \"username\",\n \"password\": \"password\"\n}", "BodyAsJson": { "username": "username", "password": "password" }, "BodyAsBytes": null, "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": "Json", "DetectedBodyTypeFromContentType": "Json" }, "Response": { "StatusCode": 400, "Headers": { "Content-Type": [ "application/json" ] }, "BodyDestination": null, "Body": null, "BodyAsJson": { "errorMessage": "Validation exception", "status": 400, "WireMock reason": "bad content-type" }, "BodyAsBytes": null, "BodyAsFile": null, "BodyAsFileIsCached": null, "BodyOriginal": null, "BodyEncoding": null, "DetectedBodyType": 2, "DetectedBodyTypeFromContentType": null, "FaultType": null, "FaultPercentage": null }, "MappingGuid": "b0a41442-eef5-4f5e-9cf9-aa2943052995", "MappingTitle": null, "RequestMatchResult": { "TotalScore": 2.0, "TotalNumber": 2, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "PathMatcher", "Score": 1.0 }, { "Name": "MethodMatcher", "Score": 1.0 } ] }, "PartialMappingGuid": "b0a41442-eef5-4f5e-9cf9-aa2943052995", "PartialMappingTitle": null, "PartialRequestMatchResult": { "TotalScore": 2.0, "TotalNumber": 2, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "PathMatcher", "Score": 1.0 }, { "Name": "MethodMatcher", "Score": 1.0 } ] } } ``` On my other (first) endpoint stubs I did positive detection as first (lowest priority value) and then the incomplete detection as later (higher priority values) fallback detection. But I found with this new one I needed to confirm both the headers content-type and authorization, and with WireMock just doing "or" comparisons I thought maybe this invalid stubbing checking was the excepted usage route?
adam added the question label 2025-12-29 08:29:00 +01:00
adam closed this issue 2025-12-29 08:29:00 +01:00
Author
Owner

@MichaelIDS commented on GitHub (Feb 16, 2023):

And after hours of trying to work this out, minutes after posting this I realise what the issue was.
I had somehow changed from my Headers having Matchers array to just having a Matcher object. And this was silently failing.

After moving to the blow syntax it works as expected.

"Headers": [
                {
                    "Name": "Content-Type",
                    "Matchers": [
                        {
                            "Name": "ExactMatcher",
                            "Pattern": "application/json",
                            "RejectOnMatch": true
                        }
                    ]
                }
            ]
@MichaelIDS commented on GitHub (Feb 16, 2023): And after hours of trying to work this out, minutes after posting this I realise what the issue was. I had somehow changed from my Headers having Matchers array to just having a Matcher object. And this was silently failing. After moving to the blow syntax it works as expected. ``` "Headers": [ { "Name": "Content-Type", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "application/json", "RejectOnMatch": true } ] } ] ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#488