Search in sources :

Example 11 with InBoundHeaders

use of com.sun.jersey.core.header.InBoundHeaders in project ORCID-Source by ORCID.

the class ApiVersionCheckFilterTest method setup.

@Before
public void setup() {
    WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
    InBoundHeaders headers = new InBoundHeaders();
    headers.add("X-Forwarded-Proto", "https");
    request = new ContainerRequest(webApp, "GET", URI.create("https://localhost:8443/orcid-api-web/"), URI.create("https://localhost:8443/orcid-api-web/v2.0_rc1/0000-0001-7510-9252/activities"), headers, new ByteArrayInputStream(new byte[0]));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) Before(org.junit.Before)

Example 12 with InBoundHeaders

use of com.sun.jersey.core.header.InBoundHeaders in project ORCID-Source by ORCID.

the class ApiVersionCheckFilterTest method invalidWebhooksShouldNotWork.

@Test
public void invalidWebhooksShouldNotWork() {
    WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
    URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
    URI requestUri = URI.create("http://localhost:8443/orcid-api-web/0000-0001-7510-9252/webhook/");
    InBoundHeaders headers = new InBoundHeaders();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) ByteArrayInputStream(java.io.ByteArrayInputStream) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 13 with InBoundHeaders

use of com.sun.jersey.core.header.InBoundHeaders in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheRequestUriToTheSameProtocolAsTheXForwardProtoHeader.

@Test
public void shouldSetTheRequestUriToTheSameProtocolAsTheXForwardProtoHeader() throws Exception {
    // given
    final String theProtocol = "https";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_PROTO_HEADER_KEY, theProtocol);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://jimwebber.org:1234"), URI.create("http://jimwebber.org:1234/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertThat(result.getBaseUri().getScheme(), containsString(theProtocol));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with InBoundHeaders

use of com.sun.jersey.core.header.InBoundHeaders in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader.

@Test
public void shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader() throws Exception {
    // given
    final String xForwardHostAndPort = "jimwebber.org:1234";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://iansrobinson.com"), URI.create("http://iansrobinson.com/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertThat(result.getBaseUri().toString(), containsString(xForwardHostAndPort));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 15 with InBoundHeaders

use of com.sun.jersey.core.header.InBoundHeaders in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader.

@Test
public void shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader() throws Exception {
    // given
    final String xForwardHostAndPort = "jimwebber.org:1234";
    XForwardFilter filter = new XForwardFilter();
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort);
    ContainerRequest request = new ContainerRequest(WEB_APPLICATION, "GET", URI.create("http://iansrobinson.com"), URI.create("http://iansrobinson.com/foo/bar"), headers, INPUT_STREAM);
    // when
    ContainerRequest result = filter.filter(request);
    // then
    assertTrue(result.getRequestUri().toString().startsWith("http://" + xForwardHostAndPort));
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) XForwardFilter(org.neo4j.server.web.XForwardFilter) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)16 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)16 Test (org.junit.Test)13 WebApplication (com.sun.jersey.spi.container.WebApplication)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 URI (java.net.URI)9 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 XForwardFilter (org.neo4j.server.web.XForwardFilter)4 WebApplicationImpl (com.sun.jersey.server.impl.application.WebApplicationImpl)2 Before (org.junit.Before)1