WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.35k stars 197 forks source link

Should my URL be replaced with 'localhost' #1099

Closed domwvitality closed 1 month ago

domwvitality commented 1 month ago

When I try and configure a my WireMockServer to start with a specific address it is overwritten when created and replaced with 'localhost'.

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

The code above would create a new server with a URL of 'http://localhost:8102' instead of 'http://172.18.0.1:8102'

image

I noticed that version 1.1.10 is the last version which would set the URL to what I provided, anything after this replaced it with 'localhost'.

Is this expected behaviour?

StefH commented 1 month ago

172.18.0.1 is your private local ip-address?

domwvitality commented 1 month ago

Yeah, that's correct. Docker is used to start various services we depend on and they get assigned this address and an available port number

StefH commented 1 month ago

I understand. The logic has been changed indeed. I'll change the code in https://github.com/WireMock-Net/WireMock.Net/pull/1100

And if you want, you can test a preview version 1.5.52-ci-18499, see https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

StefH commented 1 month ago

@domwvitality Did you have time to test the preview version?

domwvitality commented 1 month ago

@StefH Sure, will try and get that tested and confirmed today.

domwvitality commented 1 month ago

Hi @StefH ,

Apologies for the delay. I've just got round to testing that build and it fails for me when starting the server. I'm using the same snippet...

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

but when I execute I get this error...

WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Cannot assign requested address)
 ---> System.AggregateException: One or more errors occurred. (Cannot assign requested address)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at WireMock.Server.WireMockServer..ctor(WireMockServerSettings settings)
   at WireMock.Server.WireMockServer.Start(WireMockServerSettings settings)
StefH commented 1 month ago

On my system:

ipconfig

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::44c8:b60d:87e1:8437%27
   IPv4 Address. . . . . . . . . . . : 172.19.80.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

WireMock.Net

var serverOnPrivateIPAddress172_19 = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "https://172.19.80.1:8103" }
});
System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress172_19.Urls)}");
serverOnPrivateIPAddress172_19.Stop();

This works fine.

Are you sure you that 172.18.0.1 is your local ip-address from your PC?

domwvitality commented 1 month ago

Hi @StefH ,

My apologies, you're right, the IP was wrong. Retested with http://172.19.0.1 and all is working as expected.