diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln index 41e1226b..f0ddcdb9 100644 --- a/WireMock.Net Solution.sln +++ b/WireMock.Net Solution.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27130.2020 +VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EF242EDF-7133-4277-9A0C-18744DE08707}" EndProject @@ -23,7 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Tests", "test\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NETCoreApp", "examples\WireMock.Net.Console.NETCoreApp\WireMock.Net.Console.NETCoreApp.csproj", "{FE281639-B014-4C8A-96FA-141164A74713}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Record.NETCoreApp", "examples\WireMock.Net.Console.Record.NETCoreApp\WireMock.Net.Console.Record.NETCoreApp.csproj", "{1995E414-F197-4AB4-90C2-68D806B5AF59}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Proxy.NETCoreApp", "examples\WireMock.Net.Console.Record.NETCoreApp\WireMock.Net.Console.Proxy.NETCoreApp.csproj", "{1995E414-F197-4AB4-90C2-68D806B5AF59}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Client", "examples\WireMock.Net.Client\WireMock.Net.Client.csproj", "{058D4B6C-C03E-49D0-91DB-A535B058FA0D}" EndProject @@ -40,6 +40,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET452 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Proxy.Net452", "examples\WireMock.Net.Console.Proxy.Net452\WireMock.Net.Console.Proxy.Net452.csproj", "{26433A8F-BF01-4962-97EB-81BFFBB61096}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Proxy.NETCoreApp2", "examples\WireMock.Net.Console.Proxy.NETCoreApp2\WireMock.Net.Console.Proxy.NETCoreApp2.csproj", "{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -86,6 +90,14 @@ Global {049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU {049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU {049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Release|Any CPU.Build.0 = Release|Any CPU + {26433A8F-BF01-4962-97EB-81BFFBB61096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26433A8F-BF01-4962-97EB-81BFFBB61096}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26433A8F-BF01-4962-97EB-81BFFBB61096}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26433A8F-BF01-4962-97EB-81BFFBB61096}.Release|Any CPU.Build.0 = Release|Any CPU + {23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -101,6 +113,8 @@ Global {668F689E-57B4-422E-8846-C0FF643CA999} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} {668F689E-57B4-422E-8846-C0FF643CA268} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} {049539C1-7A66-4559-AD7A-B1C73B97CBB0} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} + {26433A8F-BF01-4962-97EB-81BFFBB61096} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} + {23A9AA3C-40FC-42AA-8A5E-05899795A1C6} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BF428BCC-C837-433B-87D2-15C7014B73E9} diff --git a/examples/WireMock.Net.Console.NETCoreApp/WireMock.Net.Console.NETCoreApp.csproj b/examples/WireMock.Net.Console.NETCoreApp/WireMock.Net.Console.NETCoreApp.csproj index 5448a240..37a4ed8d 100644 --- a/examples/WireMock.Net.Console.NETCoreApp/WireMock.Net.Console.NETCoreApp.csproj +++ b/examples/WireMock.Net.Console.NETCoreApp/WireMock.Net.Console.NETCoreApp.csproj @@ -22,7 +22,7 @@ - + diff --git a/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs new file mode 100644 index 00000000..3fa7bf11 --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using WireMock.Server; +using WireMock.Settings; + +namespace WireMock.Net.Console.Proxy.NETCoreApp2 +{ + class Program + { + static void Main(string[] args) + { + var server = FluentMockServer.Start(new FluentMockServerSettings + { + Urls = new[] { "http://localhost:9091", "https://localhost:9443" }, + StartAdminInterface = true, + ReadStaticMappings = false, + ProxyAndRecordSettings = new ProxyAndRecordSettings + { + Url = "https://www.google.com", + //X509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)", + SaveMapping = true, + SaveMappingToFile = false, + BlackListedHeaders = new[] { "dnt", "Content-Length" } + } + }); + + server.LogEntriesChanged += (sender, eventRecordArgs) => + { + System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented)); + }; + + System.Console.WriteLine("Press any key to stop the server"); + System.Console.ReadKey(); + server.Stop(); + } + } +} diff --git a/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Properties/launchSettings.json b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Properties/launchSettings.json new file mode 100644 index 00000000..616b68b0 --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:63377/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WireMock.Net.Console.Proxy.NETCoreApp2": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:63378/" + } + } +} \ No newline at end of file diff --git a/examples/WireMock.Net.Console.Proxy.NETCoreApp2/WireMock.Net.Console.Proxy.NETCoreApp2.csproj b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/WireMock.Net.Console.Proxy.NETCoreApp2.csproj new file mode 100644 index 00000000..08a0483c --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.NETCoreApp2/WireMock.Net.Console.Proxy.NETCoreApp2.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp2.0 + ../../WireMock.Net-Logo.ico + + + + + + + + + + + + diff --git a/examples/WireMock.Net.Console.Proxy.Net452/App.config b/examples/WireMock.Net.Console.Proxy.Net452/App.config new file mode 100644 index 00000000..8227adb9 --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.Net452/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/examples/WireMock.Net.Console.Proxy.Net452/Program.cs b/examples/WireMock.Net.Console.Proxy.Net452/Program.cs new file mode 100644 index 00000000..78df8f0d --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.Net452/Program.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using WireMock.Server; +using WireMock.Settings; + +namespace WireMock.Net.Console.Proxy.Net452 +{ + class Program + { + static void Main(string[] args) + { + var server = FluentMockServer.Start(new FluentMockServerSettings + { + Urls = new[] { "http://localhost:9091/", "https://localhost:9443/" }, + StartAdminInterface = true, + ReadStaticMappings = false, + ProxyAndRecordSettings = new ProxyAndRecordSettings + { + Url = "https://www.google.com", + //X509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)", + SaveMapping = true, + SaveMappingToFile = false, + BlackListedHeaders = new[] { "dnt", "Content-Length" } + } + }); + + server.LogEntriesChanged += (sender, eventRecordArgs) => + { + System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented)); + }; + + System.Console.WriteLine("Press any key to stop the server"); + System.Console.ReadKey(); + server.Stop(); + } + } +} \ No newline at end of file diff --git a/examples/WireMock.Net.Console.Proxy.Net452/Properties/AssemblyInfo.cs b/examples/WireMock.Net.Console.Proxy.Net452/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..60253665 --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.Net452/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WireMock.Net.Console.Proxy.Net452")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WireMock.Net.Console.Proxy.Net452")] +[assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("26433a8f-bf01-4962-97eb-81bffbb61096")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/examples/WireMock.Net.Console.Proxy.Net452/WireMock.Net.Console.Proxy.Net452.csproj b/examples/WireMock.Net.Console.Proxy.Net452/WireMock.Net.Console.Proxy.Net452.csproj new file mode 100644 index 00000000..04605b1a --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.Net452/WireMock.Net.Console.Proxy.Net452.csproj @@ -0,0 +1,105 @@ + + + + + Debug + AnyCPU + {26433A8F-BF01-4962-97EB-81BFFBB61096} + Exe + WireMock.Net.Console.Proxy.Net452 + WireMock.Net.Console.Proxy.Net452 + v4.5.2 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + WireMock.Net.Console.Proxy.Net452.Program + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + PreserveNewest + False + libuv.dll + + + PreserveNewest + False + libuv.dll + + + + + ..\..\packages\Microsoft.Owin.Host.HttpListener.3.1.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll + + + ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + {b6269aac-170a-43d5-8b9a-579ded3d9a95} + WireMock.Net.StandAlone + + + {d3804228-91f4-4502-9595-39584e5a01ad} + WireMock.Net + + + + \ No newline at end of file diff --git a/examples/WireMock.Net.Console.Proxy.Net452/packages.config b/examples/WireMock.Net.Console.Proxy.Net452/packages.config new file mode 100644 index 00000000..524c4b7b --- /dev/null +++ b/examples/WireMock.Net.Console.Proxy.Net452/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/WireMock.Net.Console.Record.NETCoreApp/Program.cs b/examples/WireMock.Net.Console.Record.NETCoreApp/Program.cs index 8f7c3712..f70e493e 100644 --- a/examples/WireMock.Net.Console.Record.NETCoreApp/Program.cs +++ b/examples/WireMock.Net.Console.Record.NETCoreApp/Program.cs @@ -2,7 +2,7 @@ using WireMock.Server; using WireMock.Settings; -namespace WireMock.Net.Console.Record.NETCoreApp +namespace WireMock.Net.Console.Proxy.NETCoreApp { static class Program { diff --git a/examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Record.NETCoreApp.csproj b/examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Proxy.NETCoreApp.csproj similarity index 69% rename from examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Record.NETCoreApp.csproj rename to examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Proxy.NETCoreApp.csproj index 7e9abd17..23d023f3 100644 --- a/examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Record.NETCoreApp.csproj +++ b/examples/WireMock.Net.Console.Record.NETCoreApp/WireMock.Net.Console.Proxy.NETCoreApp.csproj @@ -6,13 +6,9 @@ ../../WireMock.Net-Logo.ico - - - - - + diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj index c1a85fb4..f6b85c9b 100644 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj +++ b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj @@ -1,4 +1,4 @@ - + Lightweight StandAlone Http Mocking Server for .Net. @@ -16,11 +16,17 @@ https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/LICENSE git https://github.com/WireMock-Net/WireMock.Net - True - portable ../../WireMock.Net-Logo.ico WireMock.Net.StandAlone + + + full + True + True + $(MSBuildProjectDirectory)=/ + true + NETSTANDARD diff --git a/src/WireMock.Net/Http/HttpClientHelper.cs b/src/WireMock.Net/Http/HttpClientHelper.cs index 7a7b411f..ffe55f1c 100644 --- a/src/WireMock.Net/Http/HttpClientHelper.cs +++ b/src/WireMock.Net/Http/HttpClientHelper.cs @@ -43,7 +43,11 @@ namespace WireMock.Http // If UseCookies enabled, httpClient ignores Cookie header handler.UseCookies = false; - return new HttpClient(handler); + var client = new HttpClient(handler); +#if NET452 || NET46 + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; +#endif + return client; } public static async Task SendAsync(HttpClient client, RequestMessage requestMessage, string url) diff --git a/src/WireMock.Net/Http/PortUtil.cs b/src/WireMock.Net/Http/PortUtil.cs index 4ebba7df..519a9902 100644 --- a/src/WireMock.Net/Http/PortUtil.cs +++ b/src/WireMock.Net/Http/PortUtil.cs @@ -37,7 +37,7 @@ namespace WireMock.Http public static bool TryExtractProtocolAndPort(string url, out string proto, out int port) { proto = null; - port = -1; + port = 0; Match m = UrlDetailsRegex.Match(url); if (m.Success) diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs index 18e64581..f8e05bac 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs @@ -1,5 +1,8 @@ #if NETSTANDARD +using System; using System.Collections.Generic; +using System.Linq; +using System.Net; using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; @@ -14,7 +17,7 @@ namespace WireMock.Owin { private readonly CancellationTokenSource _cts = new CancellationTokenSource(); private readonly WireMockMiddlewareOptions _options; - private readonly string[] _uriPrefixes; + private readonly string[] _urls; private IWebHost _host; @@ -38,7 +41,7 @@ namespace WireMock.Owin } _options = options; - _uriPrefixes = uriPrefixes; + _urls = uriPrefixes; } public Task StartAsync() @@ -51,12 +54,38 @@ namespace WireMock.Owin appBuilder.UseMiddleware(_options); _options.PostWireMockMiddlewareInit?.Invoke(appBuilder); }) - .UseKestrel() - .UseUrls(_uriPrefixes) + .UseKestrel(options => + { +#if NETSTANDARD1_3 + if (_urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase))) + { + options.UseHttps("self-signed-certificate.pfx"); + } +#else + // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x + foreach (string url in _urls.Where(u => u.StartsWith("http://", StringComparison.OrdinalIgnoreCase))) + { + PortUtil.TryExtractProtocolAndPort(url, out string host, out int port); + options.Listen(IPAddress.Loopback, port); + } + + foreach (string url in _urls.Where(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase))) + { + PortUtil.TryExtractProtocolAndPort(url, out string host, out int port); + options.Listen(IPAddress.Loopback, port, listenOptions => + { + listenOptions.UseHttps("self-signed-certificate.pfx"); + }); + } +#endif + }) +#if NETSTANDARD1_3 + .UseUrls(_urls) +#endif .Build(); #if NETSTANDARD1_3 - System.Console.WriteLine("WireMock.Net server using netstandard1.3"); + Console.WriteLine("WireMock.Net server using netstandard1.3"); return Task.Run(() => { _host.Run(_cts.Token); @@ -65,7 +94,11 @@ namespace WireMock.Owin #else System.Console.WriteLine("WireMock.Net server using netstandard2.0"); IsStarted = true; - return _host.RunAsync(_cts.Token); + return Task.Run(() => + { + _host.Run(); + IsStarted = true; + }, _cts.Token); #endif } diff --git a/src/WireMock.Net/Server/FluentMockServer.cs b/src/WireMock.Net/Server/FluentMockServer.cs index 156d94cb..b2e55cc3 100644 --- a/src/WireMock.Net/Server/FluentMockServer.cs +++ b/src/WireMock.Net/Server/FluentMockServer.cs @@ -157,7 +157,7 @@ namespace WireMock.Server { if (settings.Urls != null) { - Urls = settings.Urls; + Urls = settings.Urls.Select(u => u.EndsWith("/") ? u : $"{u}/").ToArray(); } else { diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index 3cea9b91..22915689 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -16,12 +16,16 @@ https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/LICENSE git https://github.com/WireMock-Net/WireMock.Net - True ../../WireMock.Net-Logo.ico WireMock - full + + + + full True True + $(MSBuildProjectDirectory)=/ + true @@ -33,7 +37,7 @@ All - + @@ -52,6 +56,7 @@ + @@ -61,4 +66,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/src/WireMock.Net/self-signed-certificate.pfx b/src/WireMock.Net/self-signed-certificate.pfx new file mode 100644 index 00000000..a3bf2a05 Binary files /dev/null and b/src/WireMock.Net/self-signed-certificate.pfx differ