Skip to content

Commit 0f18786

Browse files
tjgqcopybara-github
authored andcommitted
Do not crash on URIs without a host component.
URIs such as `unix://...` (Unix domain socket) may legitimately be missing a host component. We should gracefully handle them when looking for a credential helper (no such helper can exist for them since the lookup is host-based, but this could change in the future). Fixes bazelbuild#16171 which is a regression in 5.3. We had some tests for this in remote_execution_test.sh, but they were disabled due to flakiness in 8e3c0df. I've filed bazelbuild#16185 to reenable them. Closes bazelbuild#16184. PiperOrigin-RevId: 470724658 Change-Id: Ibd7203546f00fe2335c14e7a5fa6d5bf64868bac
1 parent e8278ed commit 0f18786

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper/CredentialHelperProvider.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.common.annotations.VisibleForTesting;
1818
import com.google.common.base.Preconditions;
19+
import com.google.common.base.Strings;
1920
import com.google.common.collect.ImmutableMap;
2021
import com.google.devtools.build.lib.vfs.Path;
2122
import com.google.errorprone.annotations.Immutable;
@@ -66,7 +67,12 @@ private CredentialHelperProvider(
6667
public Optional<CredentialHelper> findCredentialHelper(URI uri) {
6768
Preconditions.checkNotNull(uri);
6869

69-
String host = Preconditions.checkNotNull(uri.getHost());
70+
String host = uri.getHost();
71+
if (Strings.isNullOrEmpty(host)) {
72+
// Some URIs (e.g. unix://) legitimately have no host component.
73+
return Optional.empty();
74+
}
75+
7076
Optional<Path> credentialHelper =
7177
findHostCredentialHelper(host)
7278
.or(() -> findWildcardCredentialHelper(host))

src/test/java/com/google/devtools/build/lib/authandtls/credentialhelper/CredentialHelperProviderTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ public void invalidPattern() throws Exception {
104104
assertInvalidPattern("foo-*.münchen.de");
105105
}
106106

107+
@Test
108+
public void uriWithoutHostComponent() throws Exception {
109+
Path helper = fileSystem.getPath(EXAMPLE_COM_HELPER_PATH);
110+
CredentialHelperProvider provider =
111+
CredentialHelperProvider.builder().add("example.com", helper).build();
112+
113+
assertThat(provider.findCredentialHelper(URI.create("unix:///path/to/socket"))).isEmpty();
114+
}
115+
107116
@Test
108117
public void addNonExecutableDefaultHelper() throws Exception {
109118
Path helper = fileSystem.getPath("/path/to/non/executable");

0 commit comments

Comments
 (0)