use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaAuthRule method before.
protected void before(ResourceTest currentTest) throws AuthenticationException {
SimbaAuthenticator authenticatorMock = mock(SimbaAuthenticator.class);
SimbaCredentialsFactory simbaCredentialsFactoryMock = mock(SimbaCredentialsFactory.class);
SimbaAuthenticatedProvider simbaAuthenticatedProvider = new SimbaAuthenticatedProvider(authenticatorMock, simbaCredentialsFactoryMock, domainProvider);
SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().build();
when(simbaCredentialsFactoryMock.create(any(ContainerRequest.class))).thenReturn(simbaCredentials);
when(authenticatorMock.authenticate(simbaCredentials)).thenReturn(Optional.fromNullable(new SimbaPrincipal("user", "ssoToken")));
currentTest.addProvider(simbaAuthenticatedProvider);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests 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();
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsFactoryTest method create_BasicAuthentication_DecodesAndCreatesCredentials.
@Test
public void create_BasicAuthentication_DecodesAndCreatesCredentials() throws Exception {
String username = "emanresu";
String password = "drowssap";
String digest = username + ":" + password;
byte[] encodedDigest = Base64.encode(digest);
String basicAuthString = "basic " + new String(encodedDigest);
ContainerRequest containerRequest = new ContainerRequestBuilderForTests().addHeader(AUTHORIZATION, basicAuthString).withRequestUri(URI.create("http://rest.wayneindustries.com/v1/bats?format=timeseries")).withHttpMethod(HttpMethods.GET).build();
SimbaCredentials expected = new SimbaCredentialsBuilderForTests().withHttpMethod(HttpMethods.GET).addHeader(AUTHORIZATION, basicAuthString).addParameter(AuthenticationConstants.USERNAME, username).addParameter(AuthenticationConstants.PASSWORD, password).addParameter("format", "timeseries").withRequestUrl("http://rest.wayneindustries.com/v1/bats/").withSimbaWebURL(SIMBA_WEB_URL).withHostServerName(RequestUtil.HOST_SERVER_NAME).withIsLoginRequest(true).build();
SimbaCredentials simbaCredentials = factory.create(containerRequest);
assertThat(simbaCredentials).isEqualTo(expected);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsFactoryTest method create_SSOTokenIsMappedProperly.
@Test
public void create_SSOTokenIsMappedProperly() throws Exception {
String token = "55687";
ContainerRequest containerRequest = new ContainerRequestBuilderForTests().withRequestUri(URI.create(REQUESTURL)).addHeader(X_SSO_TOKEN, token).withHttpMethod(HttpMethods.GET).build();
Map<String, String> requestParameters = Maps.newHashMap();
SimbaCredentials expected = new SimbaCredentialsBuilderForTests().withRequestUrl(REQUESTURL).addHeader(X_SSO_TOKEN, token).withRequestParameters(requestParameters).withHostServerName(RequestUtil.HOST_SERVER_NAME).withSsotoken(token).build();
SimbaCredentials actual = factory.create(containerRequest);
assertThat(actual).isEqualTo(expected);
}
use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests in project simba-os by cegeka.
the class SimbaCredentialsTest method asRequestData_IfEmptySSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull.
@Test
public void asRequestData_IfEmptySSOTokenOnCredentials_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("").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