use of org.springframework.web.util.UriComponentsBuilder in project nzbhydra2 by theotherp.
the class UrlCalculatorTest method shouldBuildCorrectlyForReverseProxyWithHttpsAccessedViaNetworkAddress.
@Test
public void shouldBuildCorrectlyForReverseProxyWithHttpsAccessedViaNetworkAddress() {
prepareConfig(false, false, "/nzbhydra2");
prepareHeaders("192.168.1.111:4001", "192.168.1.111:4001", "https", null);
// nginx reports port 80 and scheme in the servlet
prepareServlet("192.168.1.111:4001", "192.168.1.111", 80, "http", "/nzbhydra2");
UriComponentsBuilder builder = testee.buildLocalBaseUriBuilder(requestMock);
assertThat(builder.build().getScheme()).isEqualTo("https");
assertThat(builder.build().getHost()).isEqualTo("192.168.1.111");
assertThat(builder.build().getPort()).isEqualTo(4001);
assertThat(builder.build().getPath()).isEqualTo("/nzbhydra2");
}
use of org.springframework.web.util.UriComponentsBuilder in project nzbhydra2 by theotherp.
the class UrlCalculatorTest method shouldBuildCorrectlyForReverseProxyWithHttpAccessedViaLocalhost.
@Test
public void shouldBuildCorrectlyForReverseProxyWithHttpAccessedViaLocalhost() {
prepareConfig(false, false, "/nzbhydra2");
// nginx doesn't include the port in the "host" header
prepareHeaders("127.0.0.1", "127.0.0.1:4001", null, null);
// nginx reports port 80 in the servlet
prepareServlet("http://127.0.0.1:4001", "127.0.0.1", 80, "http", "/nzbhydra2");
UriComponentsBuilder builder = testee.buildLocalBaseUriBuilder(requestMock);
assertThat(builder.build().getScheme()).isEqualTo("http");
assertThat(builder.build().getHost()).isEqualTo("127.0.0.1");
assertThat(builder.build().getPort()).isEqualTo(4001);
assertThat(builder.build().getPath()).isEqualTo("/nzbhydra2");
}
use of org.springframework.web.util.UriComponentsBuilder in project nzbhydra2 by theotherp.
the class UrlCalculatorTest method shouldBuildCorrectlyForReverseProxyWithHttpsAccessedViaLocalhost.
@Test
public void shouldBuildCorrectlyForReverseProxyWithHttpsAccessedViaLocalhost() {
prepareConfig(false, false, "/nzbhydra2");
prepareHeaders("127.0.0.1:4001", "127.0.0.1:4001", "https", null);
// nginx reports port 80 and scheme http in the servlet
prepareServlet("http://127.0.0.1:4001", "127.0.0.1", 80, "http", "/nzbhydra2");
UriComponentsBuilder builder = testee.buildLocalBaseUriBuilder(requestMock);
assertThat(builder.build().getScheme()).isEqualTo("https");
assertThat(builder.build().getHost()).isEqualTo("127.0.0.1");
assertThat(builder.build().getPort()).isEqualTo(4001);
assertThat(builder.build().getPath()).isEqualTo("/nzbhydra2");
}
use of org.springframework.web.util.UriComponentsBuilder in project nzbhydra2 by theotherp.
the class UrlCalculatorTest method shouldReturnNewBuilderEachTime.
@Test
public void shouldReturnNewBuilderEachTime() {
prepareConfig(false, false, "/");
prepareHeaders("127.0.0.1:5076", null, null, null);
prepareServlet("http://127.0.0.1:5076", "127.0.0.1", 5076, "http", "/");
testee = spy(testee);
doReturn(requestMock).when(testee).getCurrentRequest();
UriComponentsBuilder builder1 = testee.getRequestBasedUriBuilder();
UriComponentsBuilder builder2 = testee.getRequestBasedUriBuilder();
assertThat(builder1).isNotSameAs(builder2);
builder1.path("path1");
builder2.path("path2");
assertThat(builder2.build().toUriString()).doesNotContain("path1");
}
use of org.springframework.web.util.UriComponentsBuilder in project nzbhydra2 by theotherp.
the class UrlCalculatorTest method shouldBuildCorrectlyForReverseProxySendingForwardedPort.
@Test
public void shouldBuildCorrectlyForReverseProxySendingForwardedPort() {
prepareConfig(false, false, "/nzbhydra2");
// x-forwarded-host may not contain the port
prepareHeaders("192.168.1.111", "192.168.1.111", null, "4001");
// nginx reports port 80 in the servlet
prepareServlet("192.168.1.111:4001", "192.168.1.111", 80, "http", "/nzbhydra2");
UriComponentsBuilder builder = testee.buildLocalBaseUriBuilder(requestMock);
assertThat(builder.build().getScheme()).isEqualTo("http");
assertThat(builder.build().getHost()).isEqualTo("192.168.1.111");
assertThat(builder.build().getPort()).isEqualTo(4001);
assertThat(builder.build().getPath()).isEqualTo("/nzbhydra2");
}
Aggregations