Skip to content
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

[7.1.0] Show a warning message when the credential helper invocation fails #20992

Merged
merged 1 commit into from
Jan 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public HttpStream connect(
baseHeaders.putAll(REQUEST_HEADERS);

Function<URL, ImmutableMap<String, List<String>>> headerFunction =
getHeaderFunction(baseHeaders.buildKeepingLast(), credentials);
getHeaderFunction(baseHeaders.buildKeepingLast(), credentials, eventHandler);
URLConnection connection = connector.connect(url, headerFunction);
return httpStreamFactory.create(
connection,
Expand All @@ -134,7 +134,7 @@ public HttpStream connect(

@VisibleForTesting
static Function<URL, ImmutableMap<String, List<String>>> getHeaderFunction(
Map<String, List<String>> baseHeaders, Credentials credentials) {
Map<String, List<String>> baseHeaders, Credentials credentials, EventHandler eventHandler) {
Preconditions.checkNotNull(baseHeaders);
Preconditions.checkNotNull(credentials);

Expand All @@ -146,6 +146,8 @@ static Function<URL, ImmutableMap<String, List<String>>> getHeaderFunction(
// If we can't convert the URL to a URI (because it is syntactically malformed), or fetching
// credentials fails for any other reason, still try to do the connection, not adding
// authentication information as we cannot look it up.
eventHandler.handle(
Event.warn("Error retrieving auth headers, continuing without: " + e.getMessage()));
}
return ImmutableMap.copyOf(headers);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testHeaderComputationFunction() throws Exception {

Function<URL, ImmutableMap<String, List<String>>> headerFunction =
HttpConnectorMultiplexer.getHeaderFunction(
baseHeaders, new StaticCredentials(additionalHeaders));
baseHeaders, new StaticCredentials(additionalHeaders), eventHandler);

// Unrelated URL
assertThat(headerFunction.apply(new URL("http://example.org/some/path/file.txt")))
Expand Down Expand Up @@ -218,7 +218,7 @@ public void testHeaderComputationFunction() throws Exception {
ImmutableMap.of("Authentication", ImmutableList.of("YW5vbnltb3VzOmZvb0BleGFtcGxlLm9yZw=="));
Function<URL, ImmutableMap<String, List<String>>> combinedHeaders =
HttpConnectorMultiplexer.getHeaderFunction(
annonAuth, new StaticCredentials(additionalHeaders));
annonAuth, new StaticCredentials(additionalHeaders), eventHandler);
assertThat(combinedHeaders.apply(new URL("http://hosting.example.com/user/foo/file.txt")))
.containsExactly("Authentication", ImmutableList.of("Zm9vOmZvb3NlY3JldA=="));
assertThat(combinedHeaders.apply(new URL("http://unreleated.example.org/user/foo/file.txt")))
Expand Down
Loading