use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests 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);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaGatewayTest method authenticate_THttpClientEvenGetsClosedAfterAnExceptionOccurred.
@Test
public void authenticate_THttpClientEvenGetsClosedAfterAnExceptionOccurred() 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), any(String.class))).thenThrow(new TException());
expectedException.expect(SimbaUnavailableException.class);
simbaGateway.authenticate(new SimbaCredentialsBuilderForTests().build());
verify(tHttpClientMock, times(1)).close();
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsFactoryTest method createForLogin_CreatesCorrectSimbaCredentials.
@Test
public void createForLogin_CreatesCorrectSimbaCredentials() throws Exception {
String username = "username";
String password = "password";
SimbaCredentials expected = new SimbaCredentialsBuilderForTests().addParameter(AuthenticationConstants.USERNAME, username).addParameter(AuthenticationConstants.PASSWORD, password).addHeader("user-agent", "").withIsLoginRequest(true).withIsLogoutRequest(false).withRequestUrl("").withHttpMethod(HttpMethods.POST).withHostServerName(RequestUtil.HOST_SERVER_NAME).build();
SimbaCredentials actual = factory.createForLogin(username, password);
assertThat(actual).isEqualTo(expected);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsTest method asRequestData_ReturnsRequestDataFromInternals.
@Test
public void asRequestData_ReturnsRequestDataFromInternals() throws Exception {
Map<String, String> requestHeaders = Maps.newHashMap();
requestHeaders.put(HttpHeaders.WWW_AUTHENTICATE, "auth-string");
Map<String, String> requestParameters = Maps.newHashMap();
requestParameters.put("format", "timeseries");
SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().withRequestUrl(SimbaCredentialsBuilderForTests.REQUESTURL + "?format=timeseries").withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsotoken("123456").withIsLoginRequest(true).build();
RequestData expected = new RequestDataBuilderForTests().withHostServerName(HOSTSERVERNAME).withRequestMethod(HTTP_METHOD).withRequestUrl(REQUESTURL + "?format=timeseries").withSimbaWebURL(SIMBAWEBURL).withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsoToken(new SSOToken("123456")).withLoginRequest(true).build();
RequestData actual = simbaCredentials.asRequestData();
assertThat(actual).isEqualTo(expected);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsTest method asRequestData_IfNoSSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull.
@Test
public void asRequestData_IfNoSSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull() throws Exception {
Map<String, String> requestHeaders = Maps.newHashMap();
requestHeaders.put(HttpHeaders.WWW_AUTHENTICATE, "auth-string");
Map<String, String> requestParameters = Maps.newHashMap();
requestParameters.put("format", "timeseries");
SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().withRequestUrl(SimbaCredentialsBuilderForTests.REQUESTURL + "?format=timeseries").withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsotoken(null).build();
RequestData expected = new RequestDataBuilderForTests().withHostServerName(HOSTSERVERNAME).withRequestMethod(HTTP_METHOD).withRequestUrl(REQUESTURL + "?format=timeseries").withSimbaWebURL(SIMBAWEBURL).withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsoToken(null).build();
RequestData actual = simbaCredentials.asRequestData();
assertThat(actual).isEqualTo(expected);
}
Aggregations