Compare commits

..

2 Commits

Author SHA1 Message Date
Stef Heyenrath
13f87a1364 1.5.55 2024-05-22 16:38:30 +02:00
Stef Heyenrath
dd35cea44e When only Port is provided, bind to * (Fixes #1100) (#1107)
* Fix for #1100

* tst
2024-05-22 16:33:35 +02:00
7 changed files with 62 additions and 31 deletions

View File

@@ -1,3 +1,6 @@
# 1.5.55 (22 May 2024)
- [#1107](https://github.com/WireMock-Net/WireMock.Net/pull/1107) - When only Port is provided, bind to * (Fixes #1100) [bug] contributed by [StefH](https://github.com/StefH)
# 1.5.54 (18 May 2024) # 1.5.54 (18 May 2024)
- [#1100](https://github.com/WireMock-Net/WireMock.Net/pull/1100) - Add support to bind to ip-address instead of only localhost [feature] contributed by [StefH](https://github.com/StefH) - [#1100](https://github.com/WireMock-Net/WireMock.Net/pull/1100) - Add support to bind to ip-address instead of only localhost [feature] contributed by [StefH](https://github.com/StefH)
- [#1104](https://github.com/WireMock-Net/WireMock.Net/pull/1104) - Use try..catch to set encoding in WireMockConsoleLogger [feature] contributed by [asherber](https://github.com/asherber) - [#1104](https://github.com/WireMock-Net/WireMock.Net/pull/1104) - Use try..catch to set encoding in WireMockConsoleLogger [feature] contributed by [asherber](https://github.com/asherber)

View File

@@ -4,7 +4,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<VersionPrefix>1.5.54</VersionPrefix> <VersionPrefix>1.5.55</VersionPrefix>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon> <PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl> <PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

View File

@@ -1,6 +1,6 @@
rem https://github.com/StefH/GitHubReleaseNotes rem https://github.com/StefH/GitHubReleaseNotes
SET version=1.5.54 SET version=1.5.55
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN% GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%

View File

@@ -1,5 +1,4 @@
# 1.5.54 (18 May 2024) # 1.5.55 (22 May 2024)
- #1100 Add support to bind to ip-address instead of only localhost [feature] - #1107 When only Port is provided, bind to * (Fixes #1100) [bug]
- #1104 Use try..catch to set encoding in WireMockConsoleLogger [feature]
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md

View File

@@ -4,6 +4,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using WireMock.Logging; using WireMock.Logging;
@@ -96,33 +97,61 @@ message HelloReply {
private static void RunOnLocal() private static void RunOnLocal()
{ {
try var localIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList.First(a => a.AddressFamily == AddressFamily.InterNetwork);
{
var serverOnPrivateIPAddress192_168_1 = WireMockServer.Start(new WireMockServerSettings //try
{ //{
Urls = new[] { "http://192.168.1.166:8102" } // var server = WireMockServer.Start(new WireMockServerSettings
}); // {
System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress192_168_1.Urls)}"); // Urls = new[] { $"http://{localIP}:9091" },
serverOnPrivateIPAddress192_168_1.Stop(); // StartAdminInterface = true
} // });
catch (Exception e) // System.Console.WriteLine($"1: {string.Join(", ", server.Urls)}");
{
System.Console.WriteLine("serverOnPrivateIPAddress192: " + e); // System.Console.WriteLine("Press any key to stop...");
} // System.Console.ReadKey();
// server.Stop();
//}
//catch (Exception e)
//{
// System.Console.WriteLine(e);
//}
try try
{ {
var serverOnPrivateIPAddress172_19 = WireMockServer.Start(new WireMockServerSettings var server = WireMockServer.Start(new WireMockServerSettings
{ {
Urls = new[] { "https://172.19.80.1:8103" } Port = 9091,
StartAdminInterface = true
}); });
System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress172_19.Urls)}"); System.Console.WriteLine($"2: {string.Join(", ", server.Urls)}");
serverOnPrivateIPAddress172_19.Stop();
System.Console.WriteLine("Press any key to stop...");
System.Console.ReadKey();
server.Stop();
} }
catch (Exception e) catch (Exception e)
{ {
System.Console.WriteLine("serverOnPrivateIPAddress172_19: " + e); System.Console.WriteLine(e);
} }
//try
//{
// var server = WireMockServer.Start(new WireMockServerSettings
// {
// Urls = new[] { "http://*:9091" },
// StartAdminInterface = true
// });
// System.Console.WriteLine($"3: {string.Join(", ", server.Urls)}");
// System.Console.WriteLine("Press any key to stop...");
// System.Console.ReadKey();
// server.Stop();
//}
//catch (Exception e)
//{
// System.Console.WriteLine(e);
//}
} }
public static void Run() public static void Run()

View File

@@ -6,7 +6,7 @@ namespace WireMock.Owin;
internal class HostUrlOptions internal class HostUrlOptions
{ {
private const string Localhost = "localhost"; private const string Star = "*";
public ICollection<string>? Urls { get; set; } public ICollection<string>? Urls { get; set; }
@@ -25,16 +25,16 @@ internal class HostUrlOptions
{ {
var port = Port > 0 ? Port.Value : FindFreeTcpPort(); var port = Port > 0 ? Port.Value : FindFreeTcpPort();
var scheme = HostingScheme == HostingScheme.Https ? "https" : "http"; var scheme = HostingScheme == HostingScheme.Https ? "https" : "http";
list.Add(new HostUrlDetails { IsHttps = HostingScheme == HostingScheme.Https, IsHttp2 = UseHttp2 == true, Url = $"{scheme}://{Localhost}:{port}", Scheme = scheme, Host = Localhost, Port = port }); list.Add(new HostUrlDetails { IsHttps = HostingScheme == HostingScheme.Https, IsHttp2 = UseHttp2 == true, Url = $"{scheme}://{Star}:{port}", Scheme = scheme, Host = Star, Port = port });
} }
if (HostingScheme == HostingScheme.HttpAndHttps) if (HostingScheme == HostingScheme.HttpAndHttps)
{ {
var httpPort = Port > 0 ? Port.Value : FindFreeTcpPort(); var httpPort = Port > 0 ? Port.Value : FindFreeTcpPort();
list.Add(new HostUrlDetails { IsHttps = false, IsHttp2 = UseHttp2 == true, Url = $"http://{Localhost}:{httpPort}", Scheme = "http", Host = Localhost, Port = httpPort }); list.Add(new HostUrlDetails { IsHttps = false, IsHttp2 = UseHttp2 == true, Url = $"http://{Star}:{httpPort}", Scheme = "http", Host = Star, Port = httpPort });
var httpsPort = FindFreeTcpPort(); // In this scenario, always get a free port for https. var httpsPort = FindFreeTcpPort(); // In this scenario, always get a free port for https.
list.Add(new HostUrlDetails { IsHttps = true, IsHttp2 = UseHttp2 == true, Url = $"https://{Localhost}:{httpsPort}", Scheme = "https", Host = Localhost, Port = httpsPort }); list.Add(new HostUrlDetails { IsHttps = true, IsHttp2 = UseHttp2 == true, Url = $"https://{Star}:{httpsPort}", Scheme = "https", Host = Star, Port = httpsPort });
} }
} }
else else

View File

@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests.Owin;
public class HostUrlOptionsTests public class HostUrlOptionsTests
{ {
[Fact] [Fact]
public void GetDetails_WithNoUrlsAndHttpScheme_ShouldReturnCorrectDetails() public void GetDetails_WithHostingSchemeHttpAndPort_ShouldReturnCorrectDetails()
{ {
// Arrange // Arrange
var options = new HostUrlOptions var options = new HostUrlOptions
@@ -28,14 +28,14 @@ public class HostUrlOptionsTests
var detail = details.Single(); var detail = details.Single();
detail.Should().Match<HostUrlDetails>(d => detail.Should().Match<HostUrlDetails>(d =>
d.Scheme == "http" && d.Scheme == "http" &&
d.Host == "localhost" && d.Host == "*" &&
d.Port == 8080 && d.Port == 8080 &&
d.IsHttps == false d.IsHttps == false
); );
} }
[Fact] [Fact]
public void GetDetails_WithNoUrlsAndHttpsScheme_ShouldReturnCorrectDetails() public void GetDetails_WithHostingSchemeHttpsAndPort_ShouldReturnCorrectDetails()
{ {
// Arrange // Arrange
var options = new HostUrlOptions var options = new HostUrlOptions
@@ -52,7 +52,7 @@ public class HostUrlOptionsTests
var detail = details.Single(); var detail = details.Single();
detail.Should().Match<HostUrlDetails>(d => detail.Should().Match<HostUrlDetails>(d =>
d.Scheme == "https" && d.Scheme == "https" &&
d.Host == "localhost" && d.Host == "*" &&
d.Port == 8081 && d.Port == 8081 &&
d.IsHttps == true d.IsHttps == true
); );