From a96c652b5a9c39b91e7257c3d5230bbfd1ba88f3 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 29 Oct 2019 19:01:28 +0100 Subject: [PATCH 1/8] webproxy part 1 --- src/WireMock.Net/Compatibility/WebProxy.cs | 28 +++++++++++++++ src/WireMock.Net/Http/HttpClientHelper.cs | 18 ++++++++-- .../ResponseBuilders/Response.WithProxy.cs | 36 +++++++++++++++++++ src/WireMock.Net/ResponseBuilders/Response.cs | 26 -------------- .../Server/FluentMockServer.Admin.cs | 2 +- .../Settings/IProxyAndRecordSettings.cs | 5 +++ .../Settings/IWebProxySettings.cs | 26 ++++++++++++++ .../Settings/ProxyAndRecordSettings.cs | 4 +++ 8 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 src/WireMock.Net/Compatibility/WebProxy.cs create mode 100644 src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs create mode 100644 src/WireMock.Net/Settings/IWebProxySettings.cs diff --git a/src/WireMock.Net/Compatibility/WebProxy.cs b/src/WireMock.Net/Compatibility/WebProxy.cs new file mode 100644 index 000000000..538c9c140 --- /dev/null +++ b/src/WireMock.Net/Compatibility/WebProxy.cs @@ -0,0 +1,28 @@ +#if NETSTANDARD1_3 +using System; +using System.Net; + +namespace System.Net +{ + internal class WebProxy : IWebProxy + { + private readonly string _proxy; + public ICredentials Credentials { get; set; } + + public WebProxy(string proxy) + { + _proxy = proxy; + } + + public Uri GetProxy(Uri destination) + { + return new Uri(_proxy); + } + + public bool IsBypassed(Uri host) + { + return true; + } + } +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net/Http/HttpClientHelper.cs b/src/WireMock.Net/Http/HttpClientHelper.cs index 4b5b05e33..f5eaab57f 100644 --- a/src/WireMock.Net/Http/HttpClientHelper.cs +++ b/src/WireMock.Net/Http/HttpClientHelper.cs @@ -4,13 +4,14 @@ using System.Threading.Tasks; using JetBrains.Annotations; using WireMock.HttpsCertificate; +using WireMock.Settings; using WireMock.Validation; namespace WireMock.Http { internal static class HttpClientHelper { - public static HttpClient CreateHttpClient(string clientX509Certificate2ThumbprintOrSubjectName = null) + public static HttpClient CreateHttpClient(IProxyAndRecordSettings settings) { #if NETSTANDARD var handler = new HttpClientHandler @@ -36,11 +37,11 @@ public static HttpClient CreateHttpClient(string clientX509Certificate2Thumbprin ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; #endif - if (!string.IsNullOrEmpty(clientX509Certificate2ThumbprintOrSubjectName)) + if (!string.IsNullOrEmpty(settings.ClientX509Certificate2ThumbprintOrSubjectName)) { handler.ClientCertificateOptions = ClientCertificateOption.Manual; - var x509Certificate2 = ClientCertificateHelper.GetCertificate(clientX509Certificate2ThumbprintOrSubjectName); + var x509Certificate2 = ClientCertificateHelper.GetCertificate(settings.ClientX509Certificate2ThumbprintOrSubjectName); handler.ClientCertificates.Add(x509Certificate2); } @@ -50,6 +51,17 @@ public static HttpClient CreateHttpClient(string clientX509Certificate2Thumbprin // If UseCookies enabled, httpClient ignores Cookie header handler.UseCookies = false; + if (settings.WebProxySettings != null) + { + handler.UseProxy = true; + + handler.Proxy = new WebProxy(settings.WebProxySettings.Address); + if (settings.WebProxySettings.UserName != null && settings.WebProxySettings.Password != null) + { + handler.Proxy.Credentials = new NetworkCredential(settings.WebProxySettings.UserName, settings.WebProxySettings.Password); + } + } + var client = new HttpClient(handler); #if NET452 || NET46 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; diff --git a/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs b/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs new file mode 100644 index 000000000..f3cdaad80 --- /dev/null +++ b/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs @@ -0,0 +1,36 @@ +using System.Net.Http; +using WireMock.Http; +using WireMock.Settings; +using WireMock.Validation; + +namespace WireMock.ResponseBuilders +{ + public partial class Response + { + private HttpClient _httpClientForProxy; + + /// + public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null) + { + Check.NotNullOrEmpty(proxyUrl, nameof(proxyUrl)); + + var settings = new ProxyAndRecordSettings + { + Url = proxyUrl, + ClientX509Certificate2ThumbprintOrSubjectName = clientX509Certificate2ThumbprintOrSubjectName + }; + + return WithProxy(settings); + } + + /// + public IResponseBuilder WithProxy(IProxyAndRecordSettings settings) + { + Check.NotNull(settings, nameof(settings)); + + ProxyUrl = settings.Url; + _httpClientForProxy = HttpClientHelper.CreateHttpClient(settings); + return this; + } + } +} \ No newline at end of file diff --git a/src/WireMock.Net/ResponseBuilders/Response.cs b/src/WireMock.Net/ResponseBuilders/Response.cs index 7b703bf1a..894cc7c0a 100644 --- a/src/WireMock.Net/ResponseBuilders/Response.cs +++ b/src/WireMock.Net/ResponseBuilders/Response.cs @@ -21,8 +21,6 @@ namespace WireMock.ResponseBuilders /// public partial class Response : IResponseBuilder { - private HttpClient _httpClientForProxy; - /// /// The delay /// @@ -38,11 +36,6 @@ public partial class Response : IResponseBuilder /// public string ProxyUrl { get; private set; } - /// - /// The client X509Certificate2 Thumbprint or SubjectName to use. - /// - public string ClientX509Certificate2ThumbprintOrSubjectName { get; private set; } - /// /// Gets the response message. /// @@ -333,25 +326,6 @@ public IResponseBuilder WithDelay(int milliseconds) return WithDelay(TimeSpan.FromMilliseconds(milliseconds)); } - /// - public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null) - { - Check.NotNullOrEmpty(proxyUrl, nameof(proxyUrl)); - - ProxyUrl = proxyUrl; - ClientX509Certificate2ThumbprintOrSubjectName = clientX509Certificate2ThumbprintOrSubjectName; - _httpClientForProxy = HttpClientHelper.CreateHttpClient(clientX509Certificate2ThumbprintOrSubjectName); - return this; - } - - /// - public IResponseBuilder WithProxy(IProxyAndRecordSettings settings) - { - Check.NotNull(settings, nameof(settings)); - - return WithProxy(settings.Url, settings.ClientX509Certificate2ThumbprintOrSubjectName); - } - /// public IResponseBuilder WithCallback(Func callbackHandler) { diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs index 36c55ab7e..134b51deb 100644 --- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs +++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs @@ -248,7 +248,7 @@ public bool ReadStaticMappingAndAddOrUpdate([NotNull] string path) private void InitProxyAndRecord(IFluentMockServerSettings settings) { - _httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ProxyAndRecordSettings.ClientX509Certificate2ThumbprintOrSubjectName); + _httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ProxyAndRecordSettings); var respondProvider = Given(Request.Create().WithPath("/*").UsingAnyMethod()); if (settings.StartAdminInterface == true) diff --git a/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs b/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs index 2e1735532..28a66bb4e 100644 --- a/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs +++ b/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs @@ -44,5 +44,10 @@ public interface IProxyAndRecordSettings /// Defines a list of cookies which will excluded from the saved mappings. /// string[] BlackListedCookies { get; set; } + + /// + /// Defines the WebProxySettings. + /// + IWebProxySettings WebProxySettings { get; set; } } } diff --git a/src/WireMock.Net/Settings/IWebProxySettings.cs b/src/WireMock.Net/Settings/IWebProxySettings.cs new file mode 100644 index 000000000..76634d035 --- /dev/null +++ b/src/WireMock.Net/Settings/IWebProxySettings.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WireMock.Settings +{ + public interface IWebProxySettings + { + /// + /// A string instance that contains the address of the proxy server. + /// + string Address { get; set; } + + /// + /// The user name associated with the credentials. + /// + string UserName { get; set; } + + /// + /// The password for the user name associated with the credentials. + /// + string Password { get; set; } + } +} diff --git a/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs b/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs index 09c7a48e9..959c5145d 100644 --- a/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs +++ b/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs @@ -34,5 +34,9 @@ public class ProxyAndRecordSettings : IProxyAndRecordSettings /// [PublicAPI] public string[] BlackListedCookies { get; set; } + + /// + [PublicAPI] + public IWebProxySettings WebProxySettings { get; set; } } } \ No newline at end of file From 25cac67ed536b2fa96c1ca484f6f4b6dd2a6f90f Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 30 Oct 2019 08:50:46 +0100 Subject: [PATCH 2/8] fixed --- .../MainApp.cs | 18 +++++++++++++++ .../Admin/Mappings/ResponseModel.cs | 5 ++++ .../Admin/Mappings/WebProxyModel.cs | 23 +++++++++++++++++++ .../ResponseBuilders/Response.WithProxy.cs | 12 ++++++++++ src/WireMock.Net/ResponseBuilders/Response.cs | 5 ---- .../Serialization/MappingConverter.cs | 22 ++++++++++++++---- .../Server/FluentMockServer.Admin.cs | 15 ++++++++---- .../Settings/IWebProxySettings.cs | 8 +------ src/WireMock.Net/Settings/WebProxySettings.cs | 19 +++++++++++++++ .../ResponseWithProxyTests.cs | 23 +++++++++++++++++++ 10 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 src/WireMock.Net/Admin/Mappings/WebProxyModel.cs create mode 100644 src/WireMock.Net/Settings/WebProxySettings.cs diff --git a/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs b/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs index 9c80f6cdc..2b038d78e 100644 --- a/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs +++ b/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs @@ -104,6 +104,24 @@ public static void Run() .WithProxy(new ProxyAndRecordSettings { Url = "http://postman-echo.com/get" }) ); + server + .Given(Request.Create() + .UsingGet() + .WithHeader("postmanecho", "get2") + ) + .RespondWith(Response.Create() + .WithProxy(new ProxyAndRecordSettings + { + Url = "http://postman-echo.com/get", + WebProxySettings = new WebProxySettings + { + Address = "http://company", + UserName = "test", + Password = "pwd" + } + }) + ); + server .Given(Request.Create() .UsingGet() diff --git a/src/WireMock.Net/Admin/Mappings/ResponseModel.cs b/src/WireMock.Net/Admin/Mappings/ResponseModel.cs index d7725263d..5369ca789 100644 --- a/src/WireMock.Net/Admin/Mappings/ResponseModel.cs +++ b/src/WireMock.Net/Admin/Mappings/ResponseModel.cs @@ -91,5 +91,10 @@ public class ResponseModel /// Gets or sets the fault. /// public FaultModel Fault { get; set; } + + /// + /// Gets or sets the WebProxy settings. + /// + public WebProxyModel WebProxy { get; set; } } } \ No newline at end of file diff --git a/src/WireMock.Net/Admin/Mappings/WebProxyModel.cs b/src/WireMock.Net/Admin/Mappings/WebProxyModel.cs new file mode 100644 index 000000000..a05591188 --- /dev/null +++ b/src/WireMock.Net/Admin/Mappings/WebProxyModel.cs @@ -0,0 +1,23 @@ +namespace WireMock.Admin.Mappings +{ + /// + /// WebProxy settings + /// + public class WebProxyModel + { + /// + /// A string instance that contains the address of the proxy server. + /// + public string Address { get; set; } + + /// + /// The user name associated with the credentials. + /// + public string UserName { get; set; } + + /// + /// The password for the user name associated with the credentials. + /// + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs b/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs index f3cdaad80..b43880cbc 100644 --- a/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs +++ b/src/WireMock.Net/ResponseBuilders/Response.WithProxy.cs @@ -9,6 +9,16 @@ public partial class Response { private HttpClient _httpClientForProxy; + /// + /// The Proxy URL to use. + /// + public string ProxyUrl { get; private set; } + + /// + /// The WebProxy settings. + /// + public IWebProxySettings WebProxySettings { get; private set; } + /// public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null) { @@ -29,6 +39,8 @@ public IResponseBuilder WithProxy(IProxyAndRecordSettings settings) Check.NotNull(settings, nameof(settings)); ProxyUrl = settings.Url; + WebProxySettings = settings.WebProxySettings; + _httpClientForProxy = HttpClientHelper.CreateHttpClient(settings); return this; } diff --git a/src/WireMock.Net/ResponseBuilders/Response.cs b/src/WireMock.Net/ResponseBuilders/Response.cs index 894cc7c0a..c1e80c376 100644 --- a/src/WireMock.Net/ResponseBuilders/Response.cs +++ b/src/WireMock.Net/ResponseBuilders/Response.cs @@ -31,11 +31,6 @@ public partial class Response : IResponseBuilder /// public bool UseTransformer { get; private set; } - /// - /// The Proxy URL to use. - /// - public string ProxyUrl { get; private set; } - /// /// Gets the response message. /// diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs index ae6ee3544..d9185cbd7 100644 --- a/src/WireMock.Net/Serialization/MappingConverter.cs +++ b/src/WireMock.Net/Serialization/MappingConverter.cs @@ -4,6 +4,7 @@ using WireMock.Matchers.Request; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; +using WireMock.Settings; using WireMock.Util; using WireMock.Validation; @@ -115,12 +116,14 @@ public MappingModel ToMappingModel(IMapping mapping) mappingModel.Response.BodyEncoding = null; mappingModel.Response.ProxyUrl = response.ProxyUrl; mappingModel.Response.Fault = null; + mappingModel.Response.WebProxy = MapWebProxy(response.WebProxySettings); } else { + mappingModel.Response.WebProxy = null; mappingModel.Response.BodyDestination = response.ResponseMessage.BodyDestination; mappingModel.Response.StatusCode = response.ResponseMessage.StatusCode; - mappingModel.Response.Headers = Map(response.ResponseMessage.Headers); + mappingModel.Response.Headers = MapHeaders(response.ResponseMessage.Headers); if (response.UseTransformer) { mappingModel.Response.UseTransformer = response.UseTransformer; @@ -176,14 +179,25 @@ public MappingModel ToMappingModel(IMapping mapping) return mappingModel; } - private static IDictionary Map(IDictionary> dictionary) + private static WebProxyModel MapWebProxy(IWebProxySettings settings) { + return settings != null ? new WebProxyModel + { + Address = settings.Address, + UserName = settings.UserName, + Password = settings.Password + } : null; + } + + private static IDictionary MapHeaders(IDictionary> dictionary) + { + var newDictionary = new Dictionary(); + if (dictionary == null || dictionary.Count == 0) { - return null; + return newDictionary; } - var newDictionary = new Dictionary(); foreach (var entry in dictionary) { object value = entry.Value.Count == 1 ? (object)entry.Value.ToString() : entry.Value; diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs index 134b51deb..622276f2a 100644 --- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs +++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs @@ -766,12 +766,19 @@ private IResponseBuilder InitResponseBuilder(ResponseModel responseModel) if (!string.IsNullOrEmpty(responseModel.ProxyUrl)) { - if (string.IsNullOrEmpty(responseModel.X509Certificate2ThumbprintOrSubjectName)) + var proxyAndRecordSettings = new ProxyAndRecordSettings { - return responseBuilder.WithProxy(responseModel.ProxyUrl); - } + Url = responseModel.ProxyUrl, + ClientX509Certificate2ThumbprintOrSubjectName = responseModel.X509Certificate2ThumbprintOrSubjectName, + WebProxySettings = responseModel.WebProxy != null ? new WebProxySettings + { + Address = responseModel.WebProxy.Address, + UserName = responseModel.WebProxy.UserName, + Password = responseModel.WebProxy.Password + } : null + }; - return responseBuilder.WithProxy(responseModel.ProxyUrl, responseModel.X509Certificate2ThumbprintOrSubjectName); + return responseBuilder.WithProxy(proxyAndRecordSettings); } if (responseModel.StatusCode.HasValue) diff --git a/src/WireMock.Net/Settings/IWebProxySettings.cs b/src/WireMock.Net/Settings/IWebProxySettings.cs index 76634d035..3cdbe172d 100644 --- a/src/WireMock.Net/Settings/IWebProxySettings.cs +++ b/src/WireMock.Net/Settings/IWebProxySettings.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WireMock.Settings +namespace WireMock.Settings { public interface IWebProxySettings { diff --git a/src/WireMock.Net/Settings/WebProxySettings.cs b/src/WireMock.Net/Settings/WebProxySettings.cs new file mode 100644 index 000000000..1de8b380c --- /dev/null +++ b/src/WireMock.Net/Settings/WebProxySettings.cs @@ -0,0 +1,19 @@ +using JetBrains.Annotations; + +namespace WireMock.Settings +{ + public class WebProxySettings : IWebProxySettings + { + /// + [PublicAPI] + public string Address { get; set; } + + /// + [PublicAPI] + public string UserName { get; set; } + + /// + [PublicAPI] + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs index 733ed7528..d25b4680b 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithProxyTests.cs @@ -2,6 +2,7 @@ using NFluent; using System; using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; using WireMock.Models; using WireMock.RequestBuilders; @@ -45,6 +46,28 @@ public async Task Response_WithProxy() Check.That(responseMessage.Headers["Content-Type"].ToString()).IsEqualTo("application/json"); } + [Fact] + public void Response_WithProxy_WebProxySettings() + { + // Assign + var settings = new ProxyAndRecordSettings + { + Url = "http://test.nl", + WebProxySettings = new WebProxySettings + { + Address = "http://company", + UserName = "x", + Password = "y" + } + }; + var response = Response.Create().WithProxy(settings); + + // Act + var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "GET", "::1"); + + Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settingsMock.Object)).Throws(); + } + public void Dispose() { _server?.Dispose(); From 2b0ed2010b9dc4cbc4401a354c7811d8f0e981c3 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 30 Oct 2019 09:35:24 +0100 Subject: [PATCH 3/8] Push to MyGet --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c02c9dde0..ab38d5c4d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -82,4 +82,4 @@ steps: inputs: command: custom custom: nuget - arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg --no-symbols --source https://www.myget.org/F/wiremock-net/api/v3/index.json --no-service-endpoint --api-key $(MyGetKey) \ No newline at end of file + arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -s https://www.myget.org/F/wiremock-net/api/v3/index.json -k $(MyGetKey) \ No newline at end of file From 5b481b756d3f69c59627f8f50bea00e3b0a4fdc9 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 31 Oct 2019 07:47:22 +0100 Subject: [PATCH 4/8] WebProxy standalone --- src/WireMock.Net.StandAlone/StandAloneApp.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/WireMock.Net.StandAlone/StandAloneApp.cs b/src/WireMock.Net.StandAlone/StandAloneApp.cs index b49bb88f2..9c36801c2 100644 --- a/src/WireMock.Net.StandAlone/StandAloneApp.cs +++ b/src/WireMock.Net.StandAlone/StandAloneApp.cs @@ -1,6 +1,5 @@ -using System; +using JetBrains.Annotations; using System.Linq; -using JetBrains.Annotations; using WireMock.Logging; using WireMock.Server; using WireMock.Settings; @@ -86,8 +85,19 @@ public static FluentMockServer Start([NotNull] string[] args, [CanBeNull] IWireM SaveMappingForStatusCodePattern = parser.GetStringValue("SaveMappingForStatusCodePattern"), ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"), BlackListedHeaders = parser.GetValues("BlackListedHeaders"), - BlackListedCookies = parser.GetValues("BlackListedCookies") + BlackListedCookies = parser.GetValues("BlackListedCookies") }; + + string proxyAddress = parser.GetStringValue("WebProxyAddress"); + if (!string.IsNullOrEmpty(proxyAddress)) + { + settings.ProxyAndRecordSettings.WebProxySettings = new WebProxySettings + { + Address = proxyAddress, + UserName = parser.GetStringValue("WebProxyUserName"), + Password = parser.GetStringValue("WebProxyPassword") + }; + } } settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'"))); From 4c56debb581e73767a9dbf76b205b63d7a99bb9c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 31 Oct 2019 08:18:00 +0100 Subject: [PATCH 5/8] -n true --- azure-pipelines.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 51c9319b2..676c02f40 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -79,10 +79,11 @@ steps: inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' +# https://github.com/NuGet/Home/issues/8148 - task: DotNetCoreCLI@2 displayName: Push to MyGet condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests inputs: command: custom custom: nuget - arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -s https://www.myget.org/F/wiremock-net/api/v3/index.json -k $(MyGetKey) \ No newline at end of file + arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -n true -s https://www.myget.org/F/wiremock-net/api/v3/index.json -k $(MyGetKey) \ No newline at end of file From 3ef640b5d3a481d245e54d4f1880b354c06716d2 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 31 Oct 2019 08:34:13 +0100 Subject: [PATCH 6/8] nuget --- "-n true" --- azure-pipelines-nuget.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-nuget.yml b/azure-pipelines-nuget.yml index d07adf018..8288110eb 100644 --- a/azure-pipelines-nuget.yml +++ b/azure-pipelines-nuget.yml @@ -43,4 +43,4 @@ steps: inputs: command: custom custom: nuget - arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg --source https://api.nuget.org/v3/index.json --no-service-endpoint --api-key $(NuGetKey) \ No newline at end of file + arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -n true -s https://api.nuget.org/v3/index.json -k $(NuGetKey) \ No newline at end of file From c748f14e0f7a006e8e2145cee832437d22de7fd0 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 18 Nov 2019 13:27:29 +0100 Subject: [PATCH 7/8] AllowAutoRedirect --- src/WireMock.Net/Http/HttpClientHelper.cs | 7 +++---- src/WireMock.Net/Settings/IProxyAndRecordSettings.cs | 7 ++++++- src/WireMock.Net/Settings/ProxyAndRecordSettings.cs | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/WireMock.Net/Http/HttpClientHelper.cs b/src/WireMock.Net/Http/HttpClientHelper.cs index f5eaab57f..296cdabc9 100644 --- a/src/WireMock.Net/Http/HttpClientHelper.cs +++ b/src/WireMock.Net/Http/HttpClientHelper.cs @@ -1,8 +1,8 @@ -using System; +using JetBrains.Annotations; +using System; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using JetBrains.Annotations; using WireMock.HttpsCertificate; using WireMock.Settings; using WireMock.Validation; @@ -45,8 +45,7 @@ public static HttpClient CreateHttpClient(IProxyAndRecordSettings settings) handler.ClientCertificates.Add(x509Certificate2); } - // For proxy we shouldn't follow auto redirects - handler.AllowAutoRedirect = false; + handler.AllowAutoRedirect = settings.AllowAutoRedirect == true; // If UseCookies enabled, httpClient ignores Cookie header handler.UseCookies = false; diff --git a/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs b/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs index 28a66bb4e..26b93b5df 100644 --- a/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs +++ b/src/WireMock.Net/Settings/IProxyAndRecordSettings.cs @@ -49,5 +49,10 @@ public interface IProxyAndRecordSettings /// Defines the WebProxySettings. /// IWebProxySettings WebProxySettings { get; set; } + + /// + /// Proxy requests should follow redirection (30x). + /// + bool? AllowAutoRedirect { get; set; } } -} +} \ No newline at end of file diff --git a/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs b/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs index 959c5145d..a4be77766 100644 --- a/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs +++ b/src/WireMock.Net/Settings/ProxyAndRecordSettings.cs @@ -38,5 +38,9 @@ public class ProxyAndRecordSettings : IProxyAndRecordSettings /// [PublicAPI] public IWebProxySettings WebProxySettings { get; set; } + + /// + [PublicAPI] + public bool? AllowAutoRedirect { get; set; } } } \ No newline at end of file From 6c8319cd816df20a43ca09ed9b48eafb40099641 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 18 Nov 2019 15:34:57 +0100 Subject: [PATCH 8/8] . --- src/WireMock.Net.StandAlone/StandAloneApp.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WireMock.Net.StandAlone/StandAloneApp.cs b/src/WireMock.Net.StandAlone/StandAloneApp.cs index 1d0ca7cba..21c597c6f 100644 --- a/src/WireMock.Net.StandAlone/StandAloneApp.cs +++ b/src/WireMock.Net.StandAlone/StandAloneApp.cs @@ -86,7 +86,8 @@ public static FluentMockServer Start([NotNull] string[] args, [CanBeNull] IWireM SaveMappingForStatusCodePattern = parser.GetStringValue("SaveMappingForStatusCodePattern"), ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"), BlackListedHeaders = parser.GetValues("BlackListedHeaders"), - BlackListedCookies = parser.GetValues("BlackListedCookies") + BlackListedCookies = parser.GetValues("BlackListedCookies"), + AllowAutoRedirect = parser.GetBoolValue("AllowAutoRedirect") }; string proxyAddress = parser.GetStringValue("WebProxyAddress");