Skip to content

Commit

Permalink
BasicAuthorization should be BasicAuthentication!
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarz committed Dec 9, 2014
1 parent 1ff2e68 commit d0bc85a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,18 @@ public T SetConnectionStatusHandler(Action<IElasticsearchResponse> handler)
}

/// <summary>
/// Basic access authorization credentials to specify with all requests.
/// Basic access authentication credentials to specify with all requests.
/// </summary>
[Obsolete("Scheduled to be removed in 2.0. Use SetBasicAuthentication() instead.")]
public T SetBasicAuthorization(string userName, string password)
{
return this.SetBasicAuthentication(userName, password);
}

/// <summary>
/// Basic access authentication credentials to specify with all requests.
/// </summary>
public T SetBasicAuthentication(string userName, string password)
{
if (this._basicAuthCredentials == null)
this._basicAuthCredentials = new BasicAuthorizationCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public interface IConnectionConfigurationValues
/// <summary>
/// Basic access authorization credentials to specify with all requests.
/// </summary>
/// TODO: Rename to BasicAuthenticationCredentials in 2.0
BasicAuthorizationCredentials BasicAuthorizationCredentials { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public interface IRequestConfiguration
/// Basic access authorization credentials to specify with this request.
/// Overrides any credentials that are set at the global IConnectionSettings level.
/// </summary>
/// TODO: rename to BasicAuthenticationCredentials in 2.0
BasicAuthorizationCredentials BasicAuthorizationCredentials { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public RequestConfigurationDescriptor MaxRetries(int retry)
return this;
}

[Obsolete("Scheduled to be removed in 2.0. Use BasicAuthentication() instead.")]
public RequestConfigurationDescriptor BasicAuthorization(string userName, string password)
{
return this.BasicAuthentication(userName, password);
}

public RequestConfigurationDescriptor BasicAuthentication(string userName, string password)
{
if (Self.BasicAuthorizationCredentials == null)
Self.BasicAuthorizationCredentials = new BasicAuthorizationCredentials();
Expand Down
4 changes: 2 additions & 2 deletions src/Elasticsearch.Net/Connection/HttpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private static void ThreadTimeoutCallback(object state, bool timedOut)
protected virtual HttpWebRequest CreateHttpWebRequest(Uri uri, string method, byte[] data, IRequestConfiguration requestSpecificConfig)
{
var request = this.CreateWebRequest(uri, method, data, requestSpecificConfig);
this.SetBasicAuthorizationIfNeeded(uri, request, requestSpecificConfig);
this.SetBasicAuthenticationIfNeeded(uri, request, requestSpecificConfig);
this.SetProxyIfNeeded(request);
return request;
}
Expand All @@ -164,7 +164,7 @@ private void SetProxyIfNeeded(HttpWebRequest myReq)
}
}

private void SetBasicAuthorizationIfNeeded(Uri uri, HttpWebRequest request, IRequestConfiguration requestSpecificConfig)
private void SetBasicAuthenticationIfNeeded(Uri uri, HttpWebRequest request, IRequestConfiguration requestSpecificConfig)
{
// Basic auth credentials take the following precedence (highest -> lowest):
// 1 - Specified on the request (highest precedence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Elasticsearch.Net.Connection.Security
{
// TODO: Rename to BasicAuthenticationCredentials in 2.0
public class BasicAuthorizationCredentials
{
public string UserName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Tests.Integration.Security.BasicAuthTests
{
[TestFixture]
[Ignore]
public class BasicAuthorizationTests
public class BasicAuthenticationTests
{
[Test]
public void No_Credentials_Result_In_401()
Expand All @@ -27,7 +27,7 @@ public void No_Credentials_Result_In_401()
public void Invalid_Credentials_Result_In_401()
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.SetBasicAuthorization("nestuser", "incorrectpassword");
.SetBasicAuthentication("nestuser", "incorrectpassword");
var client = new ElasticClient(settings);
var response = client.RootNodeInfo();
response.IsValid.Should().BeFalse();
Expand All @@ -38,7 +38,7 @@ public void Invalid_Credentials_Result_In_401()
public void Valid_Credentials_Result_In_200()
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.SetBasicAuthorization("nestuser", "elastic");
.SetBasicAuthentication("nestuser", "elastic");
var client = new ElasticClient(settings);
var response = client.RootNodeInfo();
response.IsValid.Should().BeTrue();
Expand Down Expand Up @@ -66,7 +66,7 @@ public void Escaped_Credentials_On_URI_Result_In_200()
public void ConnectionSettings_Overrides_URI()
{
var settings = new ConnectionSettings(new Uri("http://invalid:user@localhost:9200"))
.SetBasicAuthorization("nestuser", "elastic");
.SetBasicAuthentication("nestuser", "elastic");
var client = new ElasticClient(settings);
var response = client.RootNodeInfo();
response.IsValid.Should().BeTrue();
Expand All @@ -76,11 +76,11 @@ public void ConnectionSettings_Overrides_URI()
public void RequestConfiguration_Overrides_ConnectionSettings()
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.SetBasicAuthorization("invalid", "user");
.SetBasicAuthentication("invalid", "user");
var client = new ElasticClient(settings);
var response = client.RootNodeInfo(c => c
.RequestConfiguration(rc => rc
.BasicAuthorization("nestuser", "elastic")
.BasicAuthentication("nestuser", "elastic")
)
);
response.IsValid.Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static ConnectionSettings Settings(int? port = null, Uri hostOverride = n
.DisableAutomaticProxyDetection(false)
.UsePrettyResponses()
.ExposeRawResponse()
.SetBasicAuthorization("nestuser", "elastic");
.SetBasicAuthentication("nestuser", "elastic");
}

public static readonly Lazy<ElasticClient> Client = new Lazy<ElasticClient>(()=> new ElasticClient(Settings()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<Compile Include="Cluster\StatsTest.cs" />
<Compile Include="Connection\Failover\SniffTests.cs" />
<Compile Include="Connection\HttpClient\HttpClientTests.cs" />
<Compile Include="Connection\Security\BasicAuthorizationTests.cs" />
<Compile Include="Connection\Security\BasicAuthenticationTests.cs" />
<Compile Include="Connection\Security\UnauthorizedRequestTests.cs" />
<Compile Include="Connection\Thrift\ThiftBugReportTests.cs" />
<Compile Include="Core\Analyze\AnalyzeTests.cs" />
Expand Down

0 comments on commit d0bc85a

Please sign in to comment.