WM is matching during proxy (recording) mode - why? #412

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

Originally created by @PrzemekScott on GitHub (Mar 29, 2022).

Hey @StefH we have some issue with a working flow for WM. As you may remember from my previous messages, we want to use WM in proxy mode for recording only, so then we could run our tests against that mappings created when the WM is run only in matching mode.

But what we experienced is that when we are trying to prepare mappings, WM running on proxy mode, the WM is also doing matching with mappings which were created a moment ago. So basically this blocks us totally from recording proper mappings, and with continuing of our testing with the use of WM.

So can you please specify if there is any setting that we need to put a flag on which will block the matching when WM is run in proxy mode, so it will only record mappings.

If there is no such a setting. Can you please develop it and add, cause it would make the WM more dynamic for different usage scenarios. Thx

Originally created by @PrzemekScott on GitHub (Mar 29, 2022). Hey @StefH we have some issue with a working flow for WM. As you may remember from my previous messages, we want to use WM in proxy mode for recording only, so then we could run our tests against that mappings created when the WM is run only in matching mode. But what we experienced is that when we are trying to prepare mappings, WM running on proxy mode, the WM is also doing matching with mappings which were created a moment ago. So basically this blocks us totally from recording proper mappings, and with continuing of our testing with the use of WM. So can you please specify if there is any setting that we need to put a flag on which will block the matching when WM is run in proxy mode, so it will only record mappings. If there is no such a setting. Can you please develop it and add, cause it would make the WM more dynamic for different usage scenarios. Thx
adam added the question label 2025-12-29 08:27:39 +01:00
adam closed this issue 2025-12-29 08:27:39 +01:00
Author
Owner

@PrzemekScott commented on GitHub (Mar 30, 2022):

I think, our needs are partially similar to this previous question https://github.com/WireMock-Net/WireMock.Net/issues/632

@PrzemekScott commented on GitHub (Mar 30, 2022): I think, our needs are partially similar to this previous question https://github.com/WireMock-Net/WireMock.Net/issues/632
Author
Owner

@StefH commented on GitHub (Mar 30, 2022):

I understand your question.

I'll try to investigate the issue.

But please keep in mind that I'm also working on other issues and other projects.

@StefH commented on GitHub (Mar 30, 2022): I understand your question. I'll try to investigate the issue. But please keep in mind that I'm also working on other issues and other projects.
Author
Owner

@PrzemekScott commented on GitHub (Mar 30, 2022):

Sure! Thanks for giving the sign :)

@PrzemekScott commented on GitHub (Mar 30, 2022): Sure! Thanks for giving the sign :)
Author
Owner

@StefH commented on GitHub (Apr 3, 2022):

@PrzemekScott
About this specific question, I tested this code:

var server = WireMockServer.Start(new WireMockServerSettings
        {
            Urls = new[] { "http://localhost:9091/", "https://localhost:9443/" },
            StartAdminInterface = true,
            ReadStaticMappings = false,
            ProxyAndRecordSettings = new ProxyAndRecordSettings
            {
                Url = "http://postman-echo.com/post",
                SaveMapping = true,
                SaveMappingToFile = true
            }
        });

And when I do a call to WireMock.Net (using postman to post a body), everytime the proxied endpoint (http://postman-echo.com/post) is hit.

The internal saved mapping is not used it seems?

Can you tell me your setup ?
Or provide an example program?

@StefH commented on GitHub (Apr 3, 2022): @PrzemekScott About this specific question, I tested this code: ``` c# var server = WireMockServer.Start(new WireMockServerSettings { Urls = new[] { "http://localhost:9091/", "https://localhost:9443/" }, StartAdminInterface = true, ReadStaticMappings = false, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true } }); ``` And when I do a call to WireMock.Net (using postman to post a body), everytime the proxied endpoint (http://postman-echo.com/post) is hit. The internal saved mapping is not used it seems? Can you tell me your setup ? Or provide an example program?
Author
Owner

@PrzemekScott commented on GitHub (Apr 3, 2022):

@StefH

This is how the settings looks like:

"WireMockServerSettings": {
  "StartAdminInterface": true,
  "Urls": [
    "http://localhost:8080/"
  ],
  "AllowPartialMapping": false,
  "HandleRequestsSynchronously": true,
  "ThrowExceptionWhenMatcherFails": true,
  "ProxyAndRecordSettings": {
    "Url": "https://loremipsum",
    "SaveMapping": true
  }
}

And this is how we handel WireMock as a web app:

{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        private static IHostBuilder CreateHostBuilder(string[] args)
            => Host.CreateDefaultBuilder(args)
                .ConfigureServices((host, services) => ConfigureServices(services, host.Configuration));

        private static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddLogging(logging => logging.AddConsole().AddDebug());

            services.AddTransient<IWireMockService, WireMockService>();
            services.Configure<WireMockServerSettings>(configuration.GetSection("WireMockServerSettings"));

            services.AddHostedService<App>();
        }
    }
}

I will ask my team mate, Jatin, to comment here, cause he was specifically doing this experiment/testing when he noticed 'matching' happening when proxy settings were ON too. @jatin-prusty-travelport

@PrzemekScott commented on GitHub (Apr 3, 2022): @StefH This is how the settings looks like: ```json "WireMockServerSettings": { "StartAdminInterface": true, "Urls": [ "http://localhost:8080/" ], "AllowPartialMapping": false, "HandleRequestsSynchronously": true, "ThrowExceptionWhenMatcherFails": true, "ProxyAndRecordSettings": { "Url": "https://loremipsum", "SaveMapping": true } } ``` And this is how we handel WireMock as a web app: ```cs { public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((host, services) => ConfigureServices(services, host.Configuration)); private static void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddLogging(logging => logging.AddConsole().AddDebug()); services.AddTransient<IWireMockService, WireMockService>(); services.Configure<WireMockServerSettings>(configuration.GetSection("WireMockServerSettings")); services.AddHostedService<App>(); } } } ``` I will ask my team mate, Jatin, to comment here, cause he was specifically doing this experiment/testing when he noticed 'matching' happening when proxy settings were ON too. @jatin-prusty-travelport
Author
Owner

@jatin-prusty-travelport commented on GitHub (Apr 4, 2022):

@StefH I believe everytime you make a request to http://postman-echo.com/post, some header (like requestId or some other token) always changes and hence you are able to capture all the mappings. This can be verified by checking the generated mappings. But if you blacklist those headers then you can see that it first tries to serve the response from the captured mappings, and it goes to the proxy URL only if a matching mapping is not found.

@jatin-prusty-travelport commented on GitHub (Apr 4, 2022): @StefH I believe everytime you make a request to http://postman-echo.com/post, some header (like requestId or some other token) always changes and hence you are able to capture all the mappings. This can be verified by checking the generated mappings. But if you blacklist those headers then you can see that it first tries to serve the response from the captured mappings, and it goes to the proxy URL only if a matching mapping is not found.
Author
Owner

@StefH commented on GitHub (Apr 4, 2022):

Can you try preview version 1.4.40-ci-16009 ?

@StefH commented on GitHub (Apr 4, 2022): Can you try preview version `1.4.40-ci-16009` ?
Author
Owner

@jatin-prusty-travelport commented on GitHub (Apr 5, 2022):

Thanks @StefH! I have checked the preview version and it works exactly as we wanted. So in proxy mode it is not serving from the mapping.
But For wiremock to be more dynamic, I would really like to have a appsetting to define whether we want to enable this feature or not. In some cases people might want it to switch to mock mode when a mapping is captured.
Will leave it upto you to decide. Can you please let us know when you can (update if required and) release this code?

@jatin-prusty-travelport commented on GitHub (Apr 5, 2022): Thanks @StefH! I have checked the preview version and it works exactly as we wanted. So in proxy mode it is not serving from the mapping. But For wiremock to be more dynamic, I would really like to have a appsetting to define whether we want to enable this feature or not. In some cases people might want it to switch to mock mode when a mapping is captured. Will leave it upto you to decide. Can you please let us know when you can (update if required and) release this code?
Author
Owner

@StefH commented on GitHub (Apr 6, 2022):

@jatin-prusty-travelport
I think I get your last question...

My current solution is to make sure that the priority is used --> the priority from the Proxy mapping is defined in such a way that this get preference over the just created mapping.

I need to think on a good way to change the code to make it switch to mock mode when a mapping is captured...

@StefH commented on GitHub (Apr 6, 2022): @jatin-prusty-travelport I think I get your last question... My current solution is to make sure that the priority is used --> the priority from the Proxy mapping is defined in such a way that this get preference over the just created mapping. I need to think on a good way to change the code to make it switch to mock mode when a mapping is captured...
Author
Owner

@StefH commented on GitHub (Apr 21, 2022):

Closing this...

@StefH commented on GitHub (Apr 21, 2022): Closing this...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#412