Skip to content

Commit 2d2d3b7

Browse files
jared2501Robert Fink
authored andcommitted
Fix MESH ProxyConfiguration (#58)
1 parent 9d280a9 commit 2d2d3b7

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

service-config/src/main/java/com/palantir/remoting/api/config/service/ProxyConfiguration.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public Type type() {
7676
@Value.Check
7777
protected final void check() {
7878
switch (type()) {
79+
case MESH:
7980
case HTTP:
8081
Preconditions.checkArgument(hostAndPort().isPresent(), "host-and-port must be "
8182
+ "configured for an HTTP proxy");
@@ -92,16 +93,24 @@ protected final void check() {
9293
}
9394

9495
if (credentials().isPresent()) {
95-
Preconditions.checkArgument(type() == Type.HTTP, "credentials only valid for http proxies");
96+
Preconditions.checkArgument(type() == Type.HTTP, "credentials only valid for HTTP proxies");
9697
}
9798
}
9899

99100
public static ProxyConfiguration of(String hostAndPort) {
100-
return new ProxyConfiguration.Builder().hostAndPort(hostAndPort).build();
101+
return builder().hostAndPort(hostAndPort).build();
101102
}
102103

103104
public static ProxyConfiguration of(String hostAndPort, BasicCredentials credentials) {
104-
return new ProxyConfiguration.Builder().hostAndPort(hostAndPort).credentials(credentials).build();
105+
return builder().hostAndPort(hostAndPort).credentials(credentials).build();
106+
}
107+
108+
public static ProxyConfiguration mesh(String hostAndPort) {
109+
return builder().type(Type.MESH).hostAndPort(hostAndPort).build();
110+
}
111+
112+
public static Builder builder() {
113+
return new Builder();
105114
}
106115

107116
// TODO(jnewman): #317 - remove kebab-case methods when Jackson 2.7 is picked up

service-config/src/test/java/com/palantir/remoting/api/config/service/ProxyConfigurationTests.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ public void testDeserializationDirect() throws Exception {
6060
}
6161

6262
@Test
63-
public void testDirectProxyWithHostAndPort() {
63+
public void testDeserializationMesh() throws Exception {
64+
URL resource = Resources.getResource("configs/proxy-config-mesh.yml");
65+
ProxyConfiguration config = mapper.readValue(resource, ProxyConfiguration.class);
66+
assertEquals(config,
67+
ProxyConfiguration.builder().type(ProxyConfiguration.Type.MESH).hostAndPort("localhost:123").build());
68+
}
69+
70+
@Test
71+
public void testNonHttpProxyWithHostAndPort() {
6472
assertThatThrownBy(() -> new ProxyConfiguration.Builder()
6573
.hostAndPort("squid:3128")
6674
.type(ProxyConfiguration.Type.DIRECT)
@@ -69,6 +77,23 @@ public void testDirectProxyWithHostAndPort() {
6977
.hasMessage("Neither credential nor host-and-port may be configured for DIRECT proxies");
7078
}
7179

80+
@Test
81+
public void credentialsWithNonHttp() {
82+
assertThatThrownBy(() -> ProxyConfiguration.builder()
83+
.credentials(BasicCredentials.of("foo", "bar"))
84+
.type(ProxyConfiguration.Type.DIRECT)
85+
.build())
86+
.isInstanceOf(IllegalArgumentException.class)
87+
.hasMessage("Neither credential nor host-and-port may be configured for DIRECT proxies");
88+
assertThatThrownBy(() -> ProxyConfiguration.builder()
89+
.type(ProxyConfiguration.Type.MESH)
90+
.credentials(BasicCredentials.of("foo", "bar"))
91+
.hostAndPort("localhost:1234")
92+
.build())
93+
.isInstanceOf(IllegalArgumentException.class)
94+
.hasMessage("credentials only valid for HTTP proxies");
95+
}
96+
7297
@Test
7398
public void serDe() throws Exception {
7499
ProxyConfiguration config = ProxyConfiguration.of("host:80", BasicCredentials.of("username", "password"));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type: MESH
2+
hostAndPort: localhost:123

0 commit comments

Comments
 (0)