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
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
Show a warning message when the credential helper invocation fails
Fixes #20146.

PiperOrigin-RevId: 581891244
Change-Id: Ifbcdba69b731c0a4e3d8f3e45184054b4e52b62e
Wyverald committed Jan 23, 2024
commit b0d099925c9a4a95bd9434181869f25d1aa90ecc
Original file line number Diff line number Diff line change
@@ -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,
@@ -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);

@@ -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);
};
Original file line number Diff line number Diff line change
@@ -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")))
@@ -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")))
Loading