Skip to content

fix #1928 bad auth response misses status code #1952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,17 @@ public void BadResponse<TReturn>(ref ElasticsearchResponse<TReturn> response, Re

if (response == null)
{
response = new ResponseBuilder<TReturn>(data) { Exception = clientException }.ToResponse();
response = new ResponseBuilder<TReturn>(data)
{
StatusCode = callDetails?.HttpStatusCode,
Exception = clientException
}.ToResponse();
}
if (callDetails?.ResponseBodyInBytes != null && response.ResponseBodyInBytes == null)
response.ResponseBodyInBytes = callDetails.ResponseBodyInBytes;

if (callDetails?.ServerError != null && response.ServerError == null)
response.ServerError = callDetails.ServerError;

response.AuditTrail = this.AuditTrail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ [U] public async Task BadAuthenticationHtmlResponseIsIgnored()
(e) =>
{
e.FailureReason.Should().Be(PipelineFailure.BadAuthentication);
e.Response.HttpStatusCode.Should().Be(401);
e.Response.ResponseBodyInBytes.Should().BeNull();
}
);
Expand All @@ -112,6 +113,7 @@ [U] public async Task BadAuthenticationHtmlResponseStillExposedWhenUsingDisableD
(e) =>
{
e.FailureReason.Should().Be(PipelineFailure.BadAuthentication);
e.Response.HttpStatusCode.Should().Be(401);
e.Response.ResponseBodyInBytes.Should().NotBeNull();
var responseString = Encoding.UTF8.GetString(e.Response.ResponseBodyInBytes);
responseString.Should().Contain("nginx/");
Expand Down Expand Up @@ -142,6 +144,7 @@ [U] public async Task BadAuthOnGetClientCallDoesNotThrowSerializationException()
(e) =>
{
e.FailureReason.Should().Be(PipelineFailure.BadAuthentication);
e.Response.HttpStatusCode.Should().Be(401);
e.Response.ResponseBodyInBytes.Should().NotBeNull();
var responseString = Encoding.UTF8.GetString(e.Response.ResponseBodyInBytes);
responseString.Should().Contain("nginx/");
Expand Down
13 changes: 11 additions & 2 deletions src/Tests/Reproduce/GithubIssue1901.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ private class Example
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->";

[U]
public async Task BadAuthResponseDoesNotThrowExceptionWhenAttemptingToDeserializeResponse()
[U] public async Task BadAuthResponseDoesNotThrowExceptionWhenAttemptingToDeserializeResponse()
{
var client = TestClient.GetFixedReturnClient(ProxyAuthResponse, 401, contentType: "text/html", exception: new Exception("problem with the request as a result of 401"));
var source = await client.LowLevel.GetSourceAsync<Example>("examples", "example", "1");
source.Success.Should().BeFalse();
}

[U] public async Task BadAuthCarriesStatusCodeAndResponseBodyOverToResponse()
{
var client = TestClient.GetFixedReturnClient(ProxyAuthResponse, 401, contentType: "text/html", exception: new Exception("problem with the request as a result of 401"),
modifySettings: (s) => s.DisableDirectStreaming());
var response = await client.LowLevel.GetAsync<Example>("examples", "example", "1");
response.Success.Should().BeFalse();
response.ResponseBodyInBytes.Should().NotBeNullOrEmpty();
response.HttpStatusCode.Should().Be(401);
}
}
}