Skip to content

Commit

Permalink
Don't log sensitive information from requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed May 31, 2024
1 parent cf0b700 commit 3f3b53e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void execute_fallback_shouldFailAfterAttemptsExpired_whenResponseFails() {
var result = client.execute(request, handleResponse());

assertThat(result).matches(Result::failed).extracting(Result::getFailureMessages).asList()
.first().asString().matches(it -> it.startsWith("unexpected end of stream on"));
.first().asString()
.matches(it -> it.startsWith("unexpected end of stream on"));
}

@Test
Expand All @@ -115,14 +116,18 @@ void execute_fallback_shouldRetryIfStatusIsNot2xxOr4xx() {

var request = new Request.Builder()
.url("http://localhost:" + port)
.header("Authorization", "Sensitive data")
.build();

server.when(request(), unlimited()).respond(new HttpResponse().withStatusCode(500));

var result = client.execute(request, List.of(retryWhenStatusNot2xxOr4xx()), handleResponse());

assertThat(result).matches(Result::failed).extracting(Result::getFailureMessages).asList()
.first().asString().matches(it -> it.startsWith("Server response to"));
.first().asString()
.matches(it -> it.startsWith("Server response to"))
.matches("")
.doesNotMatch(".*Sensitive data.*");
server.verify(request(), exactly(2));
}

Expand All @@ -132,13 +137,16 @@ void execute_fallback_shouldRetryIfStatusIsNotAsExpected() {

var request = new Request.Builder()
.url("http://localhost:" + port)
.header("Authorization", "Sensitive data")
.build();
server.when(request(), unlimited()).respond(new HttpResponse().withStatusCode(200));

var result = client.execute(request, List.of(retryWhenStatusIsNot(204)), handleResponse());

assertThat(result).matches(Result::failed).extracting(Result::getFailureMessages).asList()
.first().asString().matches(it -> it.startsWith("Server response to"));
.first().asString()
.matches(it -> it.startsWith("Server response to"))
.doesNotMatch(".*Sensitive data.*");
server.verify(request(), exactly(2));
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ format.version = "1.1"
[versions]
apacheCommonsPool2 = "2.11.1"
iron-vc = "0.8.1"
assertj = "3.24.2"
assertj = "3.26.0"
atomikos = "6.0.0"
awaitility = "4.2.0"
bouncyCastle-jdk18on = "1.76"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static FallbackFactory retryWhenStatusNot2xxOr4xx() {
if (response == null) {
return new EdcHttpClientException(event.getLastException().getMessage());
} else {
return new EdcHttpClientException(format("Server response to %s was not successful but was %s: %s", request, response.code(), response.body().string()));
return new EdcHttpClientException(format("Server response to [%s, %s] was not successful but was %s: %s", request.method(), request.url(), response.code(), response.body().string()));
}
};
return Fallback.builderOfException(exceptionSupplier)
Expand All @@ -59,7 +59,7 @@ static FallbackFactory retryWhenStatusIsNot(int status) {
if (response == null) {
return new EdcHttpClientException(event.getLastException().getMessage());
} else {
return new EdcHttpClientException(format("Server response to %s was not %s but was %s: %s", request, status, response.code(), response.body().string()));
return new EdcHttpClientException(format("Server response to [%s, %s] was not %s but was %s: %s", request.method(), request.url(), status, response.code(), response.body().string()));
}
};
return Fallback.builderOfException(exceptionSupplier)
Expand Down

0 comments on commit 3f3b53e

Please sign in to comment.