From e875d741d4270dbad32619c179902547142d1819 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 6 Nov 2018 13:23:06 +0100 Subject: [PATCH 1/3] Fix #3485 Passing username/pass in the node URI directly bleeds into DebugInformation. If you use BasicAuthentication(username, password) on ConnectionSettings which is the recomended route this does not happen. --- .../Responses/ResponseStatics.cs | 21 ++++++++- .../Troubleshooting/DebugInformation.doc.cs | 44 +++++++++++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/Elasticsearch.Net/Responses/ResponseStatics.cs b/src/Elasticsearch.Net/Responses/ResponseStatics.cs index e8914f18f93..0e4cc5fab5f 100644 --- a/src/Elasticsearch.Net/Responses/ResponseStatics.cs +++ b/src/Elasticsearch.Net/Responses/ResponseStatics.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Text; @@ -49,10 +50,26 @@ public static void DebugAuditTrail(List auditTrail, StringBuilder sb) { var audit = a.a; sb.Append($" - [{a.i + 1}] {audit.Event.GetStringValue()}:"); - if (audit.Node?.Uri != null) sb.Append($" Node: {audit.Node.Uri}"); + + AuditNodeUrl(sb, audit); + if (audit.Exception != null) sb.Append($" Exception: {audit.Exception.GetType().Name}"); sb.AppendLine($" Took: {(audit.Ended - audit.Started).ToString()}"); } } + + private static void AuditNodeUrl(StringBuilder sb, Audit audit) + { + var uri = audit.Node?.Uri; + if (uri == null) return; + + if (!string.IsNullOrEmpty(uri.UserInfo)) + { + var builder = new UriBuilder(uri); + builder.Password = "redacted"; + uri = builder.Uri; + } + sb.Append($" Node: {uri}"); + } } } diff --git a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs index d4e9b8933d4..cfedecea0fe 100644 --- a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs +++ b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs @@ -9,6 +9,7 @@ using FluentAssertions; using Nest; using Tests.Core.Client; +using Tests.Core.Client.Settings; using Tests.Core.ManagedElasticsearch.Clusters; using Tests.Domain; using Tests.Framework; @@ -28,11 +29,27 @@ public class DebugInformation : IntegrationDocumentationTestBase, IClusterFixtur { public DebugInformation(ReadOnlyCluster cluster) : base(cluster) {} - [I] - public void DefaultDebug() + [I] public void DefaultDebug() + { + // hide + var client = this.Client; + + var response = client.Search(s => s + .Query(q => q + .MatchAll() + ) + ); + + response.DebugInformation.Should().Contain("Valid NEST response"); + } + //hide + [U] public void PasswordIsNotExposedInDebugInformation() { // hide - var client = this.Client; + var client = new ElasticClient(new AlwaysInMemoryConnectionSettings() + .DefaultIndex("index") + .BasicAuthentication("user1", "pass2") + ); var response = client.Search(s => s .Query(q => q @@ -40,8 +57,27 @@ public void DefaultDebug() ) ); - response.DebugInformation.Should().Contain("Valid NEST response"); + response.DebugInformation.Should().NotContain("pass2"); + } + + //hide + [U] public void PasswordIsNotExposedInDebugInformationWhenPartOfUrl() + { + // hide + var pool = new SingleNodeConnectionPool(new Uri("http://user1:pass2@localhost:9200")); + var client = new ElasticClient(new ConnectionSettings(pool, new InMemoryConnection()) + .DefaultIndex("index") + ); + + var response = client.Search(s => s + .Query(q => q + .MatchAll() + ) + ); + + response.DebugInformation.Should().NotContain("pass2"); } + /** * This can be useful in tracking down numerous problems and can also be useful when filing an * {github}/issues[issue] on our github repository. From 9c52141710712869eff1e75d5d8be7e5ea4429d0 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 6 Nov 2018 15:09:20 +0100 Subject: [PATCH 2/3] fix tabs in DebugInformation.doc.cs --- .../Troubleshooting/DebugInformation.doc.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs index cfedecea0fe..193790bd077 100644 --- a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs +++ b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs @@ -29,10 +29,10 @@ public class DebugInformation : IntegrationDocumentationTestBase, IClusterFixtur { public DebugInformation(ReadOnlyCluster cluster) : base(cluster) {} - [I] public void DefaultDebug() - { - // hide - var client = this.Client; + [I] public void DefaultDebug() + { + // hide + var client = this.Client; var response = client.Search(s => s .Query(q => q @@ -77,7 +77,27 @@ [U] public void PasswordIsNotExposedInDebugInformationWhenPartOfUrl() response.DebugInformation.Should().NotContain("pass2"); } +<<<<<<< HEAD + + /** + * This can be useful in tracking down numerous problems and can also be useful when filing an + * {github}/issues[issue] on our github repository. + * + * By default, the request and response bytes are not available within the debug information, but + * can be enabled globally on Connection Settings + * + */ + public void DisableDirectStreaming() + { + var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); + + var settings = new ConnectionSettings(connectionPool) + .DisableDirectStreaming(); // <1> disable direct streaming for *all* requests + + var client = new ElasticClient(settings); + } +======= /** * This can be useful in tracking down numerous problems and can also be useful when filing an * {github}/issues[issue] on our github repository. @@ -96,6 +116,7 @@ public void DisableDirectStreaming() var client = new ElasticClient(settings); } +>>>>>>> fix tabs in DebugInformation.doc.cs /** * or on a _per request_ basis */ From c1335de99baeedd5be986bde1d70e9f2765e3358 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 14 Nov 2018 12:15:04 +0100 Subject: [PATCH 3/3] bad merge --- .../Troubleshooting/DebugInformation.doc.cs | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs index 193790bd077..b35b5c43af7 100644 --- a/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs +++ b/src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs @@ -77,27 +77,6 @@ [U] public void PasswordIsNotExposedInDebugInformationWhenPartOfUrl() response.DebugInformation.Should().NotContain("pass2"); } -<<<<<<< HEAD - - /** - * This can be useful in tracking down numerous problems and can also be useful when filing an - * {github}/issues[issue] on our github repository. - * - * By default, the request and response bytes are not available within the debug information, but - * can be enabled globally on Connection Settings - * - */ - public void DisableDirectStreaming() - { - var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); - - var settings = new ConnectionSettings(connectionPool) - .DisableDirectStreaming(); // <1> disable direct streaming for *all* requests - - var client = new ElasticClient(settings); - } - -======= /** * This can be useful in tracking down numerous problems and can also be useful when filing an * {github}/issues[issue] on our github repository. @@ -116,7 +95,6 @@ public void DisableDirectStreaming() var client = new ElasticClient(settings); } ->>>>>>> fix tabs in DebugInformation.doc.cs /** * or on a _per request_ basis */