Search in sources :

Example 41 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 42 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 43 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 44 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 45 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)162 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)24 HttpEntity (org.springframework.http.HttpEntity)18 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)13 URI (java.net.URI)10 Test (org.junit.jupiter.api.Test)9 HttpHeaders (org.springframework.http.HttpHeaders)9 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)9 ArrayList (java.util.ArrayList)8 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 List (java.util.List)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5