Skip to content

Commit 20de56f

Browse files
committed
Unescape credentials on URI before adding basic auth header (ty @Tasteful)
1 parent 1d07da6 commit 20de56f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ private void SetBasicAuthorizationIfNeeded(Uri uri, HttpWebRequest request, IReq
171171
// 2 - Specified at the global IConnectionSettings level
172172
// 3 - Specified with the URI (lowest precedence)
173173

174-
var userInfo = uri.UserInfo;
175-
174+
var userInfo = Uri.UnescapeDataString(uri.UserInfo);
175+
176176
if (this.ConnectionSettings.BasicAuthorizationCredentials != null)
177177
userInfo = this.ConnectionSettings.BasicAuthorizationCredentials.ToString();
178178

src/Tests/Nest.Tests.Integration/Connection/Security/BasicAuthorizationTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public void Credentials_On_URI_Result_In_200()
6060
response.IsValid.Should().BeTrue();
6161
}
6262

63+
[Test]
64+
public void Escaped_Credentials_On_URI_Result_In_200()
65+
{
66+
var settings = new ConnectionSettings(new Uri("http://gmarz:p%40ssword@localhost:9200"));
67+
var client = new ElasticClient(settings);
68+
var response = client.RootNodeInfo();
69+
response.IsValid.Should().BeTrue();
70+
}
71+
6372
[Test]
6473
public void ConnectionSettings_Overrides_URI()
6574
{

0 commit comments

Comments
 (0)