Search in sources :

Example 1 with SimbaCredentialsBuilderForTests

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);
}
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 2 with SimbaCredentialsBuilderForTests

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();
}
Also used : TException(org.apache.thrift.TException) 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 3 with SimbaCredentialsBuilderForTests

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);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) Test(org.junit.Test)

Example 4 with SimbaCredentialsBuilderForTests

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);
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) RequestDataBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) Test(org.junit.Test)

Example 5 with SimbaCredentialsBuilderForTests

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);
}
Also used : RequestDataBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) Test(org.junit.Test)

Aggregations

SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)10 Test (org.junit.Test)8 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)3 RequestDataBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests)3 THttpClient (org.apache.thrift.transport.THttpClient)2 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)2 TException (org.apache.thrift.TException)1 Before (org.junit.Before)1 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)1 SimbaAuthenticator (org.simbasecurity.dwclient.dropwizard.authenticator.SimbaAuthenticator)1 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)1 SimbaCredentialsFactory (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsFactory)1 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)1 SimbaAuthenticatedProvider (org.simbasecurity.dwclient.dropwizard.provider.SimbaAuthenticatedProvider)1 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)1