Skip to content

Commit ddfaf56

Browse files
authored
Relax protocol check in DefaultDockerClientConfig (docker-java#1818)
1 parent 8fd8953 commit ddfaf56

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.URI;
2323
import java.util.HashSet;
2424
import java.util.Map;
25-
import java.util.Objects;
2625
import java.util.Properties;
2726
import java.util.Set;
2827

@@ -106,14 +105,7 @@ private URI checkDockerHostScheme(URI dockerHost) {
106105
if (dockerHost == null) {
107106
throw new DockerClientException("'dockerHost' is null");
108107
}
109-
switch (Objects.toString(dockerHost.getScheme())) {
110-
case "tcp":
111-
case "unix":
112-
case "npipe":
113-
return dockerHost;
114-
default:
115-
throw new DockerClientException("Unsupported protocol scheme found: '" + dockerHost);
116-
}
108+
return dockerHost;
117109
}
118110

119111
private static Properties loadIncludedDockerProperties(Properties systemProperties) {

docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ protected ApacheDockerHttpClientImpl(
8080
);
8181
break;
8282
default:
83-
pathPrefix = "";
84-
host = HttpHost.create(dockerHost);
83+
throw new IllegalArgumentException("Unsupported protocol scheme: " + dockerHost);
8584
}
8685

8786
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(

docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/OkDockerHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private OkDockerHttpClient(
175175
}
176176
break;
177177
default:
178-
baseUrlBuilder = HttpUrl.get(dockerHost.toString()).newBuilder();
178+
throw new IllegalArgumentException("Unsupported protocol scheme: " + dockerHost);
179179
}
180180
baseUrl = baseUrlBuilder.build();
181181
}

docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.HashMap;
1616
import java.util.Map;
1717
import java.util.Properties;
18+
import java.util.UUID;
1819

1920
import static org.hamcrest.MatcherAssert.assertThat;
2021
import static org.hamcrest.Matchers.equalTo;
@@ -172,28 +173,11 @@ public void testTlsVerifyAndCertPath() throws Exception {
172173
new LocalDirectorySSLConfig(dockerCertPath()));
173174
}
174175

175-
@Test(expected = DockerClientException.class)
176-
public void testWrongHostScheme() throws Exception {
177-
new DefaultDockerClientConfig(URI.create("http://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
178-
null);
179-
}
180-
181176
@Test()
182-
public void testTcpHostScheme() throws Exception {
183-
new DefaultDockerClientConfig(URI.create("tcp://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
184-
null);
185-
}
186-
187-
@Test()
188-
public void testUnixHostScheme() throws Exception {
189-
new DefaultDockerClientConfig(URI.create("unix://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
190-
null);
191-
}
192-
193-
@Test()
194-
public void testNpipeHostScheme() throws Exception {
195-
new DefaultDockerClientConfig(URI.create("npipe://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
196-
null);
177+
public void testAnyHostScheme() throws Exception {
178+
URI dockerHost = URI.create(UUID.randomUUID().toString().replace("-", "") + "://foo");
179+
new DefaultDockerClientConfig(dockerHost, "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
180+
null);
197181
}
198182

199183
@Test

0 commit comments

Comments
 (0)