Mapping adding order matters for multiple mappings? #213

Closed
opened 2025-12-29 14:25:14 +01:00 by adam · 9 comments
Owner

Originally created by @gregoks on GitHub (Sep 15, 2019).

hi,

I have a weird behavior for these 2 mappings that I'm adding.

I'm sending the following request:

body:

<xml>555</xml>

headers:

SOAPAction ->http://tempuri.org/IService/DecryptByKeyType
Content-Type -> text/xml

I'm creating 2 mappings (dont mind the mapping guids):

{
    "Guid": "2453d1d1-d64f-4f7b-b0bd-e58aa0451094",
    "Priority": 1,
    "Request": {
      "Methods": [
        "POST"
      ],
      "Headers": [
        {
          "Name": "Content-Type",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "text/xml",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"text/xml\"",
              "IgnoreCase": true
            }
          ]
        },
        {
          "Name": "SOAPAction",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "http://tempuri.org/IService/DecryptByKeyType",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"http://tempuri.org/IService/DecryptByKeyType\"",
              "IgnoreCase": true
            }
          ]
        }
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyDestination": "SameAsSource",
      "Body": "<a:DecryptedValue>5678</a:DecryptedValue>",
      "Headers": {
        "Content-Type": "text/xml"
      }
    }
  },
  {
    "Guid": "69223327-5d5a-471a-abbe-9089d1f9ec28",
    "Priority": 1,
    "Request": {
      "Methods": [
        "POST"
      ],
      "Headers": [
        {
          "Name": "Content-Type",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "text/xml",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"text/xml\"",
              "IgnoreCase": true
            }
          ]
        },
        {
          "Name": "SOAPAction",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "http://tempuri.org/IService/DecryptByKeyType",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"http://tempuri.org/IService/DecryptByKeyType\"",
              "IgnoreCase": true
            }
          ]
        }
      ],
      "Body": {
        "Matcher": {
          "Name": "RegexMatcher",
          "Pattern": "^.*555.*$",
          "IgnoreCase": false
        }
      }
    },
    "Response": {
      "StatusCode": 200,
      "BodyDestination": "SameAsSource",
      "Body": "<a:DecryptedValue>1234</a:DecryptedValue>",
      "Headers": {
        "Content-Type": "text/xml"
      }
    }
  }

The thing that it seems that if I add the first mapping first then its get caught and the other way around then the 2nd mapping gets caught:

example of the admin/requests when first mapping added first:

{
    "Guid": "12b0e84c-ce26-4eb7-86b5-ffc2e3dade21",
    "Request": {
      "ClientIP": "127.0.0.1",
      "DateTime": "2019-09-15T18:42:41.7264408Z",
      "Path": "/",
      "AbsolutePath": "/",
      "Url": "http://localhost:5566/",
      "AbsoluteUrl": "http://localhost:5566/",
      "Query": {},
      "Method": "POST",
      "Headers": {
        "Cache-Control": [
          "no-cache"
        ],
        "Connection": [
          "keep-alive"
        ],
        "Content-Type": [
          "text/xml"
        ],
        "Accept": [
          "*/*"
        ],
        "Accept-Encoding": [
          "gzip, deflate"
        ],
        "Cookie": [
          "sails.sid=s%3AwwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc"
        ],
        "Host": [
          "localhost:5566"
        ],
        "User-Agent": [
          "PostmanRuntime/7.15.2"
        ],
        "Content-Length": [
          "24"
        ],
        "SOAPAction": [
          "http://tempuri.org/IService/DecryptByKeyType"
        ],
        "Postman-Token": [
          "d8363d3a-8510-4e6d-98ad-0ac0e2f71193"
        ]
      },
      "Cookies": {
        "sails.sid": "s:wwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc"
      },
      "Body": "<xml>555</xml>",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": "String",
      "DetectedBodyTypeFromContentType": "String"
    },
    "Response": {
      "StatusCode": 200,
      "Headers": {
        "Content-Type": [
          "text/xml"
        ]
      },
      "BodyDestination": "SameAsSource",
      "Body": "<a:DecryptedValue>5678</a:DecryptedValue>",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": 1,
      "DetectedBodyTypeFromContentType": 0
    },
    "MappingGuid": "877d3ff6-d749-495b-8f41-1c1b078ae834",
    "RequestMatchResult": {
      "TotalScore": 4.0,
      "TotalNumber": 4,
      "IsPerfectMatch": true,
      "AverageTotalScore": 1.0,
      "MatchDetails": [
        {
          "Name": "MethodMatcher",
          "Score": 1.0
        },
        {
          "Name": "BodyMatcher",
          "Score": 1.0
        },
        {
          "Name": "HeaderMatcher",
          "Score": 1.0
        },
        {
          "Name": "HeaderMatcher",
          "Score": 1.0
        }
      ]
    }

example of the admin/requests when second mapping added first:

{
    "Guid": "8438ae3b-fa78-4754-85eb-62cb888ecb22",
    "Request": {
      "ClientIP": "127.0.0.1",
      "DateTime": "2019-09-15T18:43:56.0778042Z",
      "Path": "/",
      "AbsolutePath": "/",
      "Url": "http://localhost:5566/",
      "AbsoluteUrl": "http://localhost:5566/",
      "Query": {},
      "Method": "POST",
      "Headers": {
        "Cache-Control": [
          "no-cache"
        ],
        "Connection": [
          "keep-alive"
        ],
        "Content-Type": [
          "text/xml"
        ],
        "Accept": [
          "*/*"
        ],
        "Accept-Encoding": [
          "gzip, deflate"
        ],
        "Cookie": [
          "sails.sid=s%3AwwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc"
        ],
        "Host": [
          "localhost:5566"
        ],
        "User-Agent": [
          "PostmanRuntime/7.15.2"
        ],
        "Content-Length": [
          "24"
        ],
        "SOAPAction": [
          "http://tempuri.org/IService/DecryptByKeyType"
        ],
        "Postman-Token": [
          "8195e66a-98df-48ad-9e34-4a111717394a"
        ]
      },
      "Cookies": {
        "sails.sid": "s:wwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc"
      },
      "Body": "<xml>555</xml>",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": "String",
      "DetectedBodyTypeFromContentType": "String"
    },
    "Response": {
      "StatusCode": 200,
      "Headers": {
        "Content-Type": [
          "text/xml"
        ]
      },
      "BodyDestination": "SameAsSource",
      "Body": "<a:DecryptedValue>1234</a:DecryptedValue>",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": 1,
      "DetectedBodyTypeFromContentType": 0
    },
    "MappingGuid": "2453d1d1-d64f-4f7b-b0bd-e58aa0451094",
    "RequestMatchResult": {
      "TotalScore": 3.0,
      "TotalNumber": 3,
      "IsPerfectMatch": true,
      "AverageTotalScore": 1.0,
      "MatchDetails": [
        {
          "Name": "MethodMatcher",
          "Score": 1.0
        },
        {
          "Name": "HeaderMatcher",
          "Score": 1.0
        },
        {
          "Name": "HeaderMatcher",
          "Score": 1.0
        }
      ]
    }
  }

Can you please check if I'm missing anything?

Originally created by @gregoks on GitHub (Sep 15, 2019). hi, I have a weird behavior for these 2 mappings that I'm adding. I'm sending the following request: body: `<xml>555</xml>` headers: ``` SOAPAction ->http://tempuri.org/IService/DecryptByKeyType Content-Type -> text/xml ``` I'm creating 2 mappings (dont mind the mapping guids): ``` { "Guid": "2453d1d1-d64f-4f7b-b0bd-e58aa0451094", "Priority": 1, "Request": { "Methods": [ "POST" ], "Headers": [ { "Name": "Content-Type", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "text/xml", "IgnoreCase": true }, { "Name": "WildcardMatcher", "Pattern": "\"text/xml\"", "IgnoreCase": true } ] }, { "Name": "SOAPAction", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "http://tempuri.org/IService/DecryptByKeyType", "IgnoreCase": true }, { "Name": "WildcardMatcher", "Pattern": "\"http://tempuri.org/IService/DecryptByKeyType\"", "IgnoreCase": true } ] } ] }, "Response": { "StatusCode": 200, "BodyDestination": "SameAsSource", "Body": "<a:DecryptedValue>5678</a:DecryptedValue>", "Headers": { "Content-Type": "text/xml" } } }, { "Guid": "69223327-5d5a-471a-abbe-9089d1f9ec28", "Priority": 1, "Request": { "Methods": [ "POST" ], "Headers": [ { "Name": "Content-Type", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "text/xml", "IgnoreCase": true }, { "Name": "WildcardMatcher", "Pattern": "\"text/xml\"", "IgnoreCase": true } ] }, { "Name": "SOAPAction", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "http://tempuri.org/IService/DecryptByKeyType", "IgnoreCase": true }, { "Name": "WildcardMatcher", "Pattern": "\"http://tempuri.org/IService/DecryptByKeyType\"", "IgnoreCase": true } ] } ], "Body": { "Matcher": { "Name": "RegexMatcher", "Pattern": "^.*555.*$", "IgnoreCase": false } } }, "Response": { "StatusCode": 200, "BodyDestination": "SameAsSource", "Body": "<a:DecryptedValue>1234</a:DecryptedValue>", "Headers": { "Content-Type": "text/xml" } } } ``` The thing that it seems that if I add the first mapping first then its get caught and the other way around then the 2nd mapping gets caught: example of the admin/requests when first mapping added first: ``` { "Guid": "12b0e84c-ce26-4eb7-86b5-ffc2e3dade21", "Request": { "ClientIP": "127.0.0.1", "DateTime": "2019-09-15T18:42:41.7264408Z", "Path": "/", "AbsolutePath": "/", "Url": "http://localhost:5566/", "AbsoluteUrl": "http://localhost:5566/", "Query": {}, "Method": "POST", "Headers": { "Cache-Control": [ "no-cache" ], "Connection": [ "keep-alive" ], "Content-Type": [ "text/xml" ], "Accept": [ "*/*" ], "Accept-Encoding": [ "gzip, deflate" ], "Cookie": [ "sails.sid=s%3AwwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc" ], "Host": [ "localhost:5566" ], "User-Agent": [ "PostmanRuntime/7.15.2" ], "Content-Length": [ "24" ], "SOAPAction": [ "http://tempuri.org/IService/DecryptByKeyType" ], "Postman-Token": [ "d8363d3a-8510-4e6d-98ad-0ac0e2f71193" ] }, "Cookies": { "sails.sid": "s:wwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc" }, "Body": "<xml>555</xml>", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": "String", "DetectedBodyTypeFromContentType": "String" }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": [ "text/xml" ] }, "BodyDestination": "SameAsSource", "Body": "<a:DecryptedValue>5678</a:DecryptedValue>", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": 1, "DetectedBodyTypeFromContentType": 0 }, "MappingGuid": "877d3ff6-d749-495b-8f41-1c1b078ae834", "RequestMatchResult": { "TotalScore": 4.0, "TotalNumber": 4, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "MethodMatcher", "Score": 1.0 }, { "Name": "BodyMatcher", "Score": 1.0 }, { "Name": "HeaderMatcher", "Score": 1.0 }, { "Name": "HeaderMatcher", "Score": 1.0 } ] } ``` example of the admin/requests when second mapping added first: ``` { "Guid": "8438ae3b-fa78-4754-85eb-62cb888ecb22", "Request": { "ClientIP": "127.0.0.1", "DateTime": "2019-09-15T18:43:56.0778042Z", "Path": "/", "AbsolutePath": "/", "Url": "http://localhost:5566/", "AbsoluteUrl": "http://localhost:5566/", "Query": {}, "Method": "POST", "Headers": { "Cache-Control": [ "no-cache" ], "Connection": [ "keep-alive" ], "Content-Type": [ "text/xml" ], "Accept": [ "*/*" ], "Accept-Encoding": [ "gzip, deflate" ], "Cookie": [ "sails.sid=s%3AwwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc" ], "Host": [ "localhost:5566" ], "User-Agent": [ "PostmanRuntime/7.15.2" ], "Content-Length": [ "24" ], "SOAPAction": [ "http://tempuri.org/IService/DecryptByKeyType" ], "Postman-Token": [ "8195e66a-98df-48ad-9e34-4a111717394a" ] }, "Cookies": { "sails.sid": "s:wwZNPsU03ioQg2VhyQAtk5c5BB1j3FmB.hhaxvwUjdQErRAhH14WkmlSNgD7A8pEKxmBu9NeMeNc" }, "Body": "<xml>555</xml>", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": "String", "DetectedBodyTypeFromContentType": "String" }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": [ "text/xml" ] }, "BodyDestination": "SameAsSource", "Body": "<a:DecryptedValue>1234</a:DecryptedValue>", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": 1, "DetectedBodyTypeFromContentType": 0 }, "MappingGuid": "2453d1d1-d64f-4f7b-b0bd-e58aa0451094", "RequestMatchResult": { "TotalScore": 3.0, "TotalNumber": 3, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "MethodMatcher", "Score": 1.0 }, { "Name": "HeaderMatcher", "Score": 1.0 }, { "Name": "HeaderMatcher", "Score": 1.0 } ] } } ``` Can you please check if I'm missing anything?
adam added the bug label 2025-12-29 14:25:14 +01:00
adam closed this issue 2025-12-29 14:25:15 +01:00
Author
Owner

@StefH commented on GitHub (Sep 15, 2019):

The first doesn't have a match on body. Is that intended?

@StefH commented on GitHub (Sep 15, 2019): The first doesn't have a match on body. Is that intended?
Author
Owner

@gregoks commented on GitHub (Sep 15, 2019):

Yes. I want to have 2 mappings where one more strict with specific body and the other more general for requests without such body

@gregoks commented on GitHub (Sep 15, 2019): Yes. I want to have 2 mappings where one more strict with specific body and the other more general for requests without such body
Author
Owner

@StefH commented on GitHub (Sep 16, 2019):

I see.

The code does just take the first available match:
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Owin/MappingMatcher.cs#L48

Maybe it a good idea to also take into account the number of successful matches.

@StefH commented on GitHub (Sep 16, 2019): I see. The code does just take the first available match: https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Owin/MappingMatcher.cs#L48 Maybe it a good idea to also take into account the number of successful matches.
Author
Owner

@gregoks commented on GitHub (Sep 16, 2019):

Oh so it does not matter the total score of the matchings? I would assume that it should return the best matching available and not the first one..

@gregoks commented on GitHub (Sep 16, 2019): Oh so it does not matter the total score of the matchings? I would assume that it should return the best matching available and not the first one..
Author
Owner

@StefH commented on GitHub (Sep 16, 2019):

@gregoks
Can you try version WireMock.Net.1.0.30-ci-11883 on MyGet?

@StefH commented on GitHub (Sep 16, 2019): @gregoks Can you try version `WireMock.Net.1.0.30-ci-11883` on MyGet?
Author
Owner

@gregoks commented on GitHub (Sep 16, 2019):

Ill try. Does it include the other bug fixes? Because I already use the WireMock.Net.1.0.31-ci-11865 version.

@gregoks commented on GitHub (Sep 16, 2019): Ill try. Does it include the other bug fixes? Because I already use the WireMock.Net.1.0.31-ci-11865 version.
Author
Owner

@StefH commented on GitHub (Sep 17, 2019):

No, this one is only this fix.

The https://github.com/WireMock-Net/WireMock.Net/pull/339 is not included here.

@StefH commented on GitHub (Sep 17, 2019): No, this one is only this fix. The https://github.com/WireMock-Net/WireMock.Net/pull/339 is not included here.
Author
Owner

@gregoks commented on GitHub (Sep 17, 2019):

I've tested and its working in WireMock.Net.1.0.30-ci-11883 version. Thanks!!

Do you have an ETA for version that will include all of the current open bug fixes?

Thanks,

Greg

@gregoks commented on GitHub (Sep 17, 2019): I've tested and its working in WireMock.Net.1.0.30-ci-11883 version. Thanks!! Do you have an ETA for version that will include all of the current open bug fixes? Thanks, Greg
Author
Owner

@StefH commented on GitHub (Sep 17, 2019):

No ETA, yet.

Please keep a watch on this project + Nuget.

@StefH commented on GitHub (Sep 17, 2019): No ETA, yet. Please keep a watch on this project + Nuget.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#213