Search in sources :

Example 1 with ContainerRequestBuilderForTests

use of org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests 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 ContainerRequestBuilderForTests

use of org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests in project simba-os by cegeka.

the class SimbaCredentialsFactoryTest method create_NeitherSSOTokenNorBasicAuthentication_Throws401.

@Test
public void create_NeitherSSOTokenNorBasicAuthentication_Throws401() throws Exception {
    ContainerRequest containerRequest = new ContainerRequestBuilderForTests().withRequestUri(URI.create("http://rest.wayneindustries.com/v1/bats?format=timeseries")).withHttpMethod(HttpMethods.GET).build();
    expectedException.expect(WebApplicationExceptionMatcher.webApplicationException(UNAUTHORIZED));
    factory.create(containerRequest);
}
Also used : ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 3 with ContainerRequestBuilderForTests

use of org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests 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);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 4 with ContainerRequestBuilderForTests

use of org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests 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);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)4 Test (org.junit.Test)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3 Before (org.junit.Before)1