Search in sources :

Example 6 with ActionDescriptorBuilderForTests

use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.

the class SimbaGatewayTest method authenticate_THttpClientAlwaysGetsClosed.

@Test
public void authenticate_THttpClientAlwaysGetsClosed() throws Exception {
    Client expectedClient = mock(Client.class);
    THttpClient tHttpClientMock = mock(THttpClient.class);
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenReturn(tHttpClientMock);
    when(simbaServiceFactoryMock.createJSONAuthenticationFilterService(tHttpClientMock)).thenReturn(expectedClient);
    Client authenticationServiceMock = expectedClient;
    when(authenticationServiceMock.processRequest(any(RequestData.class), eq(SimbaGateway.SESSION_AUTHENTICATE_CHAIN))).thenReturn(new ActionDescriptorBuilderForTests().withActionTypes().build());
    simbaGateway.authenticate(new SimbaCredentialsBuilderForTests().build());
    verify(tHttpClientMock, times(1)).close();
}
Also used : ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) THttpClient(org.apache.thrift.transport.THttpClient) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 7 with ActionDescriptorBuilderForTests

use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorMissesMAKECOOKIE_ReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorMissesMAKECOOKIE_ReturnsEmptySSOToken() 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(ActionType.REDIRECT).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 8 with ActionDescriptorBuilderForTests

use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.

the class SimbaGatewayTest method login.

@Test
public void login() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    SSOToken expectedSSOToken = new SSOToken("token");
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(expectedSSOToken).build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> actualSSOToken = simbaGateway.login(containerRequestMock);
    assertThat(actualSSOToken.isPresent()).isTrue();
    assertThat(actualSSOToken.get()).isEqualTo(expectedSSOToken.getToken());
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) 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)

Aggregations

THttpClient (org.apache.thrift.transport.THttpClient)8 Test (org.junit.Test)8 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)8 RequestData (org.simbasecurity.api.service.thrift.RequestData)8 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)8 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)7 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)7 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)4 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)4 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)2 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)1