Browse Source

Fixed double-encoding issue in RibbonClientConfiguration

fixes gh-1241
pull/6/head
Scott Oster 8 years ago committed by Spencer Gibb
parent
commit
5e698278a8
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java
  2. 70
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfigurationTests.java

2
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java

@ -200,7 +200,7 @@ public class RibbonClientConfiguration { @@ -200,7 +200,7 @@ public class RibbonClientConfiguration {
public URI reconstructURIWithServer(Server server, URI original) {
String scheme = original.getScheme();
if (!"https".equals(scheme) && this.serverIntrospector.isSecure(server)) {
original = UriComponentsBuilder.fromUri(original).scheme("https").build()
original = UriComponentsBuilder.fromUri(original).scheme("https").build(true)
.toUri();
}
return super.reconstructURIWithServer(server, original);

70
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfigurationTests.java

@ -16,26 +16,46 @@ @@ -16,26 +16,46 @@
package org.springframework.cloud.netflix.ribbon;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import java.net.URI;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration.OverrideRestClient;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
import org.junit.Test;
import com.netflix.loadbalancer.Server;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
/**
* @author Spencer Gibb
*/
public class RibbonClientConfigurationTests {
@Test
public void restClientInitCalledOnce() {
CountingConfig config = new CountingConfig();
private CountingConfig config;
@Mock
private ServerIntrospector inspector;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
config = new CountingConfig();
config.setProperty(CommonClientConfigKey.ConnectTimeout, "1");
config.setProperty(CommonClientConfigKey.ReadTimeout, "1");
config.setProperty(CommonClientConfigKey.MaxHttpConnectionsPerHost, "1");
config.setClientName("testClient");
}
@Test
public void restClientInitCalledOnce() {
new TestRestClient(config);
assertThat(config.count, is(equalTo(1)));
}
@ -44,7 +64,43 @@ public class RibbonClientConfigurationTests { @@ -44,7 +64,43 @@ public class RibbonClientConfigurationTests {
int count = 0;
}
static class TestRestClient extends RibbonClientConfiguration.OverrideRestClient {
@Test
public void testSecureUriFromClientConfig() throws Exception {
Server server = new Server("foo", 7777);
when(inspector.isSecure(server)).thenReturn(true);
OverrideRestClient overrideRestClient = new OverrideRestClient(this.config,
inspector);
URI uri = overrideRestClient.reconstructURIWithServer(server,
new URI("http://foo/"));
assertThat(uri, is(new URI("https://foo:7777/")));
}
@Test
public void testInSecureUriFromClientConfig() throws Exception {
Server server = new Server("foo", 7777);
when(inspector.isSecure(server)).thenReturn(false);
OverrideRestClient overrideRestClient = new OverrideRestClient(this.config,
inspector);
URI uri = overrideRestClient.reconstructURIWithServer(server,
new URI("http://foo/"));
assertThat(uri, is(new URI("http://foo:7777/")));
}
@Test
public void testNotDoubleEncodedWhenSecure() throws Exception {
Server server = new Server("foo", 7777);
when(inspector.isSecure(server)).thenReturn(true);
OverrideRestClient overrideRestClient = new OverrideRestClient(this.config,
inspector);
URI uri = overrideRestClient.reconstructURIWithServer(server,
new URI("http://foo/%20bar"));
assertThat(uri, is(new URI("https://foo:7777/%20bar")));
}
static class TestRestClient extends OverrideRestClient {
private TestRestClient(IClientConfig ncc) {
super(ncc, new DefaultServerIntrospector());

Loading…
Cancel
Save