Unverified Commit dfbfcfec by Will Tran Committed by Spencer Gibb

Without explicit client config of IsSecure, lookup from registration

instead of defaulting to false. Fixes gh-1126
parent 7ac81f8f
...@@ -114,7 +114,10 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -114,7 +114,10 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
private boolean isSecure(Server server, String serviceId) { private boolean isSecure(Server server, String serviceId) {
IClientConfig config = this.clientFactory.getClientConfig(serviceId); IClientConfig config = this.clientFactory.getClientConfig(serviceId);
if (config != null) { if (config != null) {
return config.get(CommonClientConfigKey.IsSecure, false); Boolean isSecure = config.get(CommonClientConfigKey.IsSecure);
if (isSecure != null) {
return isSecure;
}
} }
return serverIntrospector(serviceId).isSecure(server); return serverIntrospector(serviceId).isSecure(server);
......
...@@ -112,7 +112,7 @@ public class RibbonLoadBalancerClientTests { ...@@ -112,7 +112,7 @@ public class RibbonLoadBalancerClientTests {
public void testReconstructUriWithSecureClientConfig() { public void testReconstructUriWithSecureClientConfig() {
RibbonServer server = getRibbonServer(); RibbonServer server = getRibbonServer();
IClientConfig config = mock(IClientConfig.class); IClientConfig config = mock(IClientConfig.class);
when(config.get(CommonClientConfigKey.IsSecure, false)).thenReturn(true); when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(true);
when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config); when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server); RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
...@@ -125,6 +125,33 @@ public class RibbonLoadBalancerClientTests { ...@@ -125,6 +125,33 @@ public class RibbonLoadBalancerClientTests {
} }
@Test @Test
@SneakyThrows
public void testReconstructSecureUriWithoutScheme() {
testReconstructSchemelessUriWithoutClientConfig(getSecureRibbonServer(), "https");
}
@Test
@SneakyThrows
public void testReconstructUnsecureSchemelessUri() {
testReconstructSchemelessUriWithoutClientConfig(getRibbonServer(), "http");
}
@SneakyThrows
public void testReconstructSchemelessUriWithoutClientConfig(RibbonServer server, String expectedScheme) {
IClientConfig config = mock(IClientConfig.class);
when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(null);
when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
ServiceInstance serviceInstance = client.choose(server.getServiceId());
URI uri = client.reconstructURI(serviceInstance,
new URI("//" + server.getServiceId()));
assertEquals(server.getHost(), uri.getHost());
assertEquals(server.getPort(), uri.getPort());
assertEquals(expectedScheme, uri.getScheme());
}
@Test
public void testChoose() { public void testChoose() {
RibbonServer server = getRibbonServer(); RibbonServer server = getRibbonServer();
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server); RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
...@@ -206,6 +233,11 @@ public class RibbonLoadBalancerClientTests { ...@@ -206,6 +233,11 @@ public class RibbonLoadBalancerClientTests {
Collections.singletonMap("mykey", "myvalue")); Collections.singletonMap("mykey", "myvalue"));
} }
protected RibbonServer getSecureRibbonServer() {
return new RibbonServer("testService", new Server("myhost", 8443), false,
Collections.singletonMap("mykey", "myvalue"));
}
protected void verifyServerStats() { protected void verifyServerStats() {
verify(this.serverStats).incrementActiveRequestsCount(); verify(this.serverStats).incrementActiveRequestsCount();
verify(this.serverStats).decrementActiveRequestsCount(); verify(this.serverStats).decrementActiveRequestsCount();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment