use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests 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();
}
use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal.
@Test
public void authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal() throws Exception {
SimbaCredentials credentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
when(credentials.asRequestData()).thenReturn(requestData);
Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
String principal = "simbaUsername";
String ssoToken = "ssotoken";
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.ADD_PARAMETER_TO_TARGET).withPrincipal(principal).withSsoToken(new SSOToken(ssoToken)).build();
when(authenticationServiceMock.processRequest(requestData, SimbaGateway.SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
assertThat(simbaPrincipal.isPresent()).isFalse();
}
use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.
the class SimbaGatewayTest method login_WithUsernameAndPassword.
@Test
public void login_WithUsernameAndPassword() throws Exception {
String username = "appUser";
String password = "appPassword";
Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
SSOToken ssoToken = new SSOToken("token");
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(ssoToken).build();
when(simbaCredentialsFactoryMock.createForLogin(username, password)).thenReturn(simbaCredentials);
when(simbaCredentials.asRequestData()).thenReturn(requestData);
when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<String> actual = simbaGateway.login(username, password);
assertThat(actual.get()).isEqualTo(ssoToken.getToken());
}
use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests 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();
}
use of org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_WhenPrincipalWasSet_ReturnPrincipal.
@Test
public void authenticate_WhenPrincipalWasSet_ReturnPrincipal() throws Exception {
SimbaCredentials credentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
when(credentials.asRequestData()).thenReturn(requestData);
Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
String principal = "simbaUsername";
String token = "token";
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.DO_FILTER_AND_SET_PRINCIPAL).withPrincipal(principal).withSsoToken(new SSOToken(token)).build();
when(authenticationServiceMock.processRequest(requestData, SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
assertThat(simbaPrincipal.get()).isEqualTo(new SimbaPrincipal(principal, token));
}
Aggregations