From 04320b1bd6eb771f8e57db0602de730b766bd339 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 11 Jul 2023 10:18:10 +0200 Subject: [PATCH] Bring default for IsBypassed inline with actual implementation (#88) * Bring default for IsBypassed inline with actual implementation * make proxy setting conditional --- .../Components/TransportClient/WebProxy.cs | 2 +- .../DefaultCluster.cs | 24 ++++++++++++------- ...stic.Elasticsearch.IntegrationTests.csproj | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Elastic.Transport/Components/TransportClient/WebProxy.cs b/src/Elastic.Transport/Components/TransportClient/WebProxy.cs index 4a8e1e5..00bd650 100644 --- a/src/Elastic.Transport/Components/TransportClient/WebProxy.cs +++ b/src/Elastic.Transport/Components/TransportClient/WebProxy.cs @@ -18,6 +18,6 @@ internal class WebProxy : IWebProxy public Uri GetProxy(Uri destination) => _uri; - public bool IsBypassed(Uri host) => host.IsLoopback; + public bool IsBypassed(Uri host) => false; } #endif diff --git a/tests/Elastic.Elasticsearch.IntegrationTests/DefaultCluster.cs b/tests/Elastic.Elasticsearch.IntegrationTests/DefaultCluster.cs index 05faf86..529d09e 100644 --- a/tests/Elastic.Elasticsearch.IntegrationTests/DefaultCluster.cs +++ b/tests/Elastic.Elasticsearch.IntegrationTests/DefaultCluster.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using Elastic.Elasticsearch.Ephemeral; +using Elastic.Elasticsearch.Managed; using Elastic.Elasticsearch.Xunit; using Elastic.Transport; using Elastic.Transport.Products.Elasticsearch; @@ -18,24 +19,24 @@ namespace Elastic.Elasticsearch.IntegrationTests; public class DefaultCluster : XunitClusterBase { protected static string Version = "8.7.0"; - public DefaultCluster() : this(new XunitClusterConfiguration(Version) { StartingPortNumber = 9202 }) { } + + public DefaultCluster() : this(new XunitClusterConfiguration(Version) { StartingPortNumber = 9202, AutoWireKnownProxies = true }) { } + public DefaultCluster(XunitClusterConfiguration xunitClusterConfiguration) : base(xunitClusterConfiguration) { } public DefaultHttpTransport CreateClient(ITestOutputHelper output) => - this.GetOrAddClient(_ => + this.GetOrAddClient(cluster => { - var hostName = (System.Diagnostics.Process.GetProcessesByName("mitmproxy").Any() - ? "ipv4.fiddler" - : "localhost"); - var nodes = NodesUris(hostName); + var nodes = NodesUris(); var connectionPool = new StaticNodePool(nodes); var settings = new TransportConfiguration(connectionPool, productRegistration: ElasticsearchProductRegistration.Default) - .Proxy(new Uri("http://ipv4.fiddler:8080"), null!, null!) .RequestTimeout(TimeSpan.FromSeconds(5)) - .ServerCertificateValidationCallback(CertificateValidations.AllowAll) .OnRequestCompleted(d => { - try { output.WriteLine(d.DebugInformation);} + try + { + output.WriteLine(d.DebugInformation); + } catch { // ignored @@ -44,6 +45,11 @@ public DefaultHttpTransport CreateClient(ITestOutputHelper output) => .EnableDebugMode(); if (ClusterConfiguration.Features.HasFlag(ClusterFeatures.Security)) settings = settings.Authentication(new BasicAuthentication(Admin.Username, Admin.Password)); + if (cluster.DetectedProxy != DetectedProxySoftware.None) + settings = settings.Proxy(new Uri("http://localhost:8080")); + if (ClusterConfiguration.Features.HasFlag(ClusterFeatures.SSL)) + settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll); + return new DefaultHttpTransport(settings); }); } diff --git a/tests/Elastic.Elasticsearch.IntegrationTests/Elastic.Elasticsearch.IntegrationTests.csproj b/tests/Elastic.Elasticsearch.IntegrationTests/Elastic.Elasticsearch.IntegrationTests.csproj index c170486..c712764 100644 --- a/tests/Elastic.Elasticsearch.IntegrationTests/Elastic.Elasticsearch.IntegrationTests.csproj +++ b/tests/Elastic.Elasticsearch.IntegrationTests/Elastic.Elasticsearch.IntegrationTests.csproj @@ -9,7 +9,7 @@ - +