Updated mapping is not being picked and responded with the response #57

Closed
opened 2025-12-29 14:21:50 +01:00 by adam · 8 comments
Owner

Originally created by @raghavendrabankapur on GitHub (Dec 19, 2017).

Start the FluentMockServer with below settings

string url = "http://localhost:1111/";
var server = FluentMockServer.Start(new FluentMockServerSettings
            {
                Urls = new[] { url },
                StartAdminInterface = true,
                ReadStaticMappings = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url = "http://www.google.com",
                    SaveMapping = true
                }
            });

Now access /__admin/mappings to get the default mappings in the console application example (having guid 11111110-a633-40e8-a244-5cb80bc0ab66).
Update the pattern to /static/mapping/update
Once the mapping is updated, make a get call to localhost:1111/static/mapping/update, this will return 410 as response.

Possible issue found is when we try to find the matching mappings from the list of mappings we have. In WireMockMiddleWire.cs file in Invoke method we have a condition to to check if it's partial mappings or not. In the else loop, we are sorting the mapping object by priority and then return the IsPerfectMatch first or default value. Here we are finding another mapping with matches the above pattern with /* which is being registered when we add ProxyAndRecordSettings. So when we try to access localhost:1111/static/mapping/update it matches with /* and return 410 rather finding the other matches in the mapping.
If we can parse all the entries in the mappings object we should find the exact match for /static/mapping/update pattern also. Infact we can see in the mappings object and also the value of IsPerfectMatch being set to this result as true, but the first value which matches the pattern /* is being returned.

Originally created by @raghavendrabankapur on GitHub (Dec 19, 2017). Start the FluentMockServer with below settings ``` string url = "http://localhost:1111/"; var server = FluentMockServer.Start(new FluentMockServerSettings { Urls = new[] { url }, StartAdminInterface = true, ReadStaticMappings = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://www.google.com", SaveMapping = true } }); ``` Now access /__admin/mappings to get the default mappings in the console application example (having guid 11111110-a633-40e8-a244-5cb80bc0ab66). Update the pattern to /static/mapping/update Once the mapping is updated, make a get call to localhost:1111/static/mapping/update, this will return 410 as response. Possible issue found is when we try to find the matching mappings from the list of mappings we have. In WireMockMiddleWire.cs file in Invoke method we have a condition to to check if it's partial mappings or not. In the else loop, we are sorting the mapping object by priority and then return the IsPerfectMatch first or default value. Here we are finding another mapping with matches the above pattern with /* which is being registered when we add ProxyAndRecordSettings. So when we try to access localhost:1111/static/mapping/update it matches with /* and return 410 rather finding the other matches in the mapping. If we can parse all the entries in the mappings object we should find the exact match for /static/mapping/update pattern also. Infact we can see in the mappings object and also the value of IsPerfectMatch being set to this result as true, but the first value which matches the pattern /* is being returned.
adam closed this issue 2025-12-29 14:21:50 +01:00
Author
Owner

@raghavendrabankapur commented on GitHub (Dec 19, 2017):

image

The line of code which is commented in the screenshot was causing the problem. I understand this is used to record and proxy the request, but it was failing to map the request and respond accordingly

@raghavendrabankapur commented on GitHub (Dec 19, 2017): ![image](https://user-images.githubusercontent.com/5006495/34142614-2d4457f6-e4ae-11e7-8c76-95d094d6b80b.png) The line of code which is commented in the screenshot was causing the problem. I understand this is used to record and proxy the request, but it was failing to map the request and respond accordingly
Author
Owner

@raghavendrabankapur commented on GitHub (Dec 19, 2017):

image

Above highlighted place is where we find the target mapping. In the else loop we order by priority and return the first element which will be matching the pattern /* because if there is no priority set, then the default list will be present without any sorting

@raghavendrabankapur commented on GitHub (Dec 19, 2017): ![image](https://user-images.githubusercontent.com/5006495/34154715-84077130-e4dc-11e7-9b2e-a51358278498.png) Above highlighted place is where we find the target mapping. In the else loop we order by priority and return the first element which will be matching the pattern /* because if there is no priority set, then the default list will be present without any sorting
Author
Owner

@raghavendrabankapur commented on GitHub (Dec 20, 2017):

@StefH I have found the solution for this. If I could create the pull request, then you can look into the fix and approve.

@raghavendrabankapur commented on GitHub (Dec 20, 2017): @StefH I have found the solution for this. If I could create the pull request, then you can look into the fix and approve.
Author
Owner

@StefH commented on GitHub (Dec 20, 2017):

You can make a PR and check if the unit-tests still work fine and maybe check if more tests are needed to test this scenario.

@StefH commented on GitHub (Dec 20, 2017): You can make a PR and check if the unit-tests still work fine and maybe check if more tests are needed to test this scenario.
Author
Owner

@raghavendrabankapur commented on GitHub (Dec 20, 2017):

All the tests are working fine.
I have committed my changes to master branch itself, but I do not have permissions to push my code for a PR. Could you please provide me permissions? @StefH

@raghavendrabankapur commented on GitHub (Dec 20, 2017): All the tests are working fine. I have committed my changes to master branch itself, but I do not have permissions to push my code for a PR. Could you please provide me permissions? @StefH
Author
Owner

@StefH commented on GitHub (Dec 20, 2017):

You can just fork this project and do your change and create a PR.

@StefH commented on GitHub (Dec 20, 2017): You can just fork this project and do your change and create a PR.
Author
Owner

@raghavendrabankapur commented on GitHub (Dec 20, 2017):

@StefH yes done.

@raghavendrabankapur commented on GitHub (Dec 20, 2017): @StefH yes done.
Author
Owner

@StefH commented on GitHub (Dec 20, 2017):

Thanks.

See new NuGet.

@StefH commented on GitHub (Dec 20, 2017): Thanks. See 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-wiremock#57