Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping adding order matters for multiple mappings? #344

Closed
gregoks opened this issue Sep 15, 2019 · 9 comments
Closed

Mapping adding order matters for multiple mappings? #344

gregoks opened this issue Sep 15, 2019 · 9 comments
Labels

Comments

@gregoks
Copy link

gregoks commented 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:https://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:https://tempuri.org/IService/DecryptByKeyType",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"http:https://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:https://tempuri.org/IService/DecryptByKeyType",
              "IgnoreCase": true
            },
            {
              "Name": "WildcardMatcher",
              "Pattern": "\"http:https://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:https://localhost:5566/",
      "AbsoluteUrl": "http:https://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:https://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:https://localhost:5566/",
      "AbsoluteUrl": "http:https://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:https://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?

@gregoks gregoks changed the title Wrong mapping is taking for multiple mappings? Mapping adding order matters for multiple mappings? Sep 15, 2019
@StefH
Copy link
Collaborator

StefH commented Sep 15, 2019

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

@gregoks
Copy link
Author

gregoks commented 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

@StefH
Copy link
Collaborator

StefH commented 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.

@gregoks
Copy link
Author

gregoks commented 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..

@StefH
Copy link
Collaborator

StefH commented Sep 16, 2019

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

@gregoks
Copy link
Author

gregoks commented 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.

@StefH
Copy link
Collaborator

StefH commented Sep 17, 2019

No, this one is only this fix.

The #339 is not included here.

@gregoks
Copy link
Author

gregoks commented 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

@StefH
Copy link
Collaborator

StefH commented Sep 17, 2019

No ETA, yet.

Please keep a watch on this project + Nuget.

@StefH StefH closed this as completed Sep 17, 2019
StefH added a commit that referenced this issue Sep 17, 2019
* Fix CompareTo in RequestMatchResult
#344

* fix test
@StefH StefH added the bug label Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants