Search in sources :

Example 16 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaAuthenticatedInjectableTest method setUp.

@Before
public void setUp() {
    injectable = new SimbaAuthenticatedInjectable<AuthenticatedPrincipal>(authenticatorMock, simbaCredentialsFactoryMock, domainProviderMock, false);
    simbaCredentials = new SimbaCredentialsBuilderForTests().build();
    ContainerRequest containerRequest = new ContainerRequestBuilderForTests().build();
    when(dummyHttpContext.getRequest()).thenReturn(containerRequest);
    when(simbaCredentialsFactoryMock.create(containerRequest)).thenReturn(simbaCredentials);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Before(org.junit.Before)

Example 17 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaGatewayTest method logout.

@Test
public void logout() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    when(simbaCredentialsFactoryMock.create(containerRequestMock, true)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    simbaGateway.logout(containerRequestMock);
    verify(authenticationServicemock).processRequest(requestData, LOGOUT_CHAIN);
}
Also used : SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 18 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorActionTypesIsEmpty_ThenReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorActionTypesIsEmpty_ThenReturnsEmptySSOToken() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes().build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> ssoToken = simbaGateway.login(containerRequestMock);
    assertThat(ssoToken.isPresent()).isFalse();
}
Also used : ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 19 with ContainerRequest

use of com.sun.jersey.spi.container.ContainerRequest in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorActionTypesIsNull_ThenReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorActionTypesIsNull_ThenReturnsEmptySSOToken() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> ssoToken = simbaGateway.login(containerRequestMock);
    assertThat(ssoToken.isPresent()).isFalse();
}
Also used : ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 20 with ContainerRequest

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

the class ApiVersionCheckFilterTest method api2_0_rc2VersionTest.

@Test
public void api2_0_rc2VersionTest() {
    MockHttpServletRequest mockReq = new MockHttpServletRequest();
    mockReq.setAttribute("X-Forwarded-Proto", "https");
    OrcidHttpServletRequestWrapper requestWrapper = new OrcidHttpServletRequestWrapper(mockReq);
    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/v2.0_rc2/0000-0001-7510-9252/activities");
    InBoundHeaders headers = new InBoundHeaders();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = new ApiVersionCheckFilter(requestWrapper);
        filter.filter(containerRequest);
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) 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)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)43 Test (org.junit.Test)37 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)16 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 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)6 ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)5 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 Before (org.junit.Before)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3