Search in sources :

Example 1 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project neo4j by neo4j.

the class XForwardFilterTest method shouldSetTheBaseUriToTheSameProtocolAsTheXForwardProtoHeader.

@Test
public void shouldSetTheBaseUriToTheSameProtocolAsTheXForwardProtoHeader() 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 2 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.

the class APIEndpointParserTest method testAPIEndpointParserNoCategoryV2.

@Test
public void testAPIEndpointParserNoCategoryV2() {
    ContainerRequest request = getRequest("https://localhost:8443/orcid-api-web/v2.0/1234-4321-1234-4321");
    APIEndpointParser parser = new APIEndpointParser(request);
    assertEquals("v2.0", parser.getApiVersion());
    assertEquals("record", parser.getCategory());
    assertEquals("1234-4321-1234-4321", parser.getOrcidId());
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 3 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.

the class APIEndpointParserTest method getRequest.

private ContainerRequest getRequest(String url) {
    InBoundHeaders headers = new InBoundHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "application/xml");
    headers.add(HttpHeaders.USER_AGENT, "blah");
    headers.add("X-FORWARDED-FOR", "37.14.150.83");
    return new ContainerRequest(new WebApplicationImpl(), "POST", URI.create("https://localhost:8443/orcid-api-web/"), URI.create(url), headers, null);
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) WebApplicationImpl(com.sun.jersey.server.impl.application.WebApplicationImpl) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest)

Example 4 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.

the class APIEndpointParserTest method testAPIEndpointParserNoCategoryOrVersion.

@Test
public void testAPIEndpointParserNoCategoryOrVersion() {
    ContainerRequest request = getRequest("https://localhost:8443/orcid-api-web/1234-4321-1234-4321");
    APIEndpointParser parser = new APIEndpointParser(request);
    assertNotNull(parser.getApiVersion());
    assertEquals("", parser.getApiVersion());
    assertEquals("orcid-bio", parser.getCategory());
    assertEquals("1234-4321-1234-4321", parser.getOrcidId());
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 5 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project ORCID-Source by ORCID.

the class TokenTargetFilterTest method tokenUsedOnTheRightUserTest.

@Test
public void tokenUsedOnTheRightUserTest() {
    setUpSecurityContext(ORCID1, CLIENT_ID, ScopePathType.READ_LIMITED);
    ContainerRequest request = Mockito.mock(ContainerRequest.class);
    Mockito.when(request.getPath()).thenReturn("http://api.test.orcid.org/v2.0/" + ORCID1);
    TokenTargetFilter filter = new TokenTargetFilter();
    filter.filter(request);
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)81 Test (org.junit.Test)62 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)29 ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)19 WebApplicationImpl (com.sun.jersey.server.impl.application.WebApplicationImpl)15 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 FF4jSecurityContextFilter (org.ff4j.web.api.security.FF4jSecurityContextFilter)6 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)6 THttpClient (org.apache.thrift.transport.THttpClient)5 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 XForwardFilter (org.neo4j.server.web.XForwardFilter)4 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)4 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)4