Search in sources :

Example 36 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.

the class RpErrorResponseFromHubIntegrationTest method shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry.

@Test
public void shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry() throws Exception {
    final SessionId sessionId = aSessionIsCreated();
    samlEngineStub.setUpStubForErrorResponseGenerateErrorOccurring();
    URI uri = UriBuilder.fromPath(Urls.PolicyUrls.RP_ERROR_RESPONSE_RESOURCE).build(sessionId.getSessionId());
    Response response = get(uri);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = response.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 37 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.

the class SessionResourceIntegrationTest method shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn.

@Test
public void shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn() throws Exception {
    // Given
    final SamlRequestDto samlRequestDto = new SamlRequestDto("coffee-pasta", idpSsoUri);
    samlEngineStub.setupStubForIdpAuthnRequestGenerate(samlRequestDto);
    configStub.setupStubForEnabledIdps(rpEntityId, false, REQUESTED_LOA, singletonList(idpEntityId));
    SessionId sessionId = aSessionIsCreated();
    anIdpIsSelectedForSignIn(sessionId, idpEntityId);
    final AuthnRequestFromHubContainerDto expectedResult = anAuthnRequestFromHubContainerDtoWithRegistering(samlRequestDto, false);
    // When
    AuthnRequestFromHubContainerDto result = getEntity(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build(sessionId), AuthnRequestFromHubContainerDto.class);
    // Then
    assertThat(result).isEqualToComparingFieldByField(expectedResult);
    IdpSelectedState sessionState = policy.getSessionState(sessionId, IdpSelectedState.class);
    assertThat(sessionState.getMatchingServiceEntityId()).isEqualTo(msEntityId);
}
Also used : SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Example 38 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.

the class SessionResourceIntegrationTest method shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists.

@Test
public void shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists() throws JsonProcessingException {
    SessionId sessionId = SessionId.createNewSessionId();
    Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInEidasSuccessfulMatchState(sessionId, rpEntityId, countryEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + EIDAS_SUCCESSFUL_MATCH_STATE).build().toASCIIString()));
    assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto expectedAuthnResponseFromHub = anAuthnResponseFromHubContainerDto().build();
    samlEngineStub.setUpStubForAuthnResponseGenerate(expectedAuthnResponseFromHub);
    URI rpAuthResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.RP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
    Response responseForRp = client.target(policy.uri(rpAuthResponseUri.toASCIIString())).request().get();
    assertThat(responseForRp.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto authnResponseFromHub = responseForRp.readEntity(AuthnResponseFromHubContainerDto.class);
    assertThat(authnResponseFromHub).isEqualToComparingFieldByField(expectedAuthnResponseFromHub);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 39 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.

the class SessionResourceIntegrationTest method shouldCreateSession.

@Test
public void shouldCreateSession() throws Exception {
    configStub.setUpStubForAssertionConsumerServiceUri(rpEntityId);
    samlEngineStub.setupStubForAuthnRequestTranslate(translatedAuthnRequest);
    Response responseFromPost = createASession(rpSamlRequest);
    assertThat(responseFromPost.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
    final SessionId postSessionId = responseFromPost.readEntity(SessionId.class);
    URI getUri = UriBuilder.fromUri(Urls.PolicyUrls.SESSION_RESOURCE_ROOT).path(Urls.SharedUrls.SESSION_ID_PARAM_PATH).build(postSessionId);
    final SessionId getSessionId = getEntity(getUri, SessionId.class);
    assertThat(postSessionId).isEqualTo(getSessionId);
    assertThat(eventSinkStub.getRecordedRequest()).hasSize(1);
    String eventSinkEntity = eventSinkStub.getRecordedRequest().get(0).getEntity();
    assertThat(eventSinkEntity).contains(postSessionId.getSessionId());
    assertThat(eventSinkEntity).contains(EventSinkHubEventConstants.SessionEvents.SESSION_STARTED);
    assertThat(eventSinkEntity).contains(rpSamlRequest.getPrincipalIPAddressAsSeenByHub());
}
Also used : Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 40 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.

the class SessionResourceIntegrationTest method shouldReturnNotFoundWhenSessionDoesNotExistInPolicy.

@Test
public void shouldReturnNotFoundWhenSessionDoesNotExistInPolicy() throws Exception {
    // Given
    SessionId sessionId = aSessionIsCreated();
    anIdpIsSelectedForSignIn(sessionId, idpEntityId);
    // When
    Response response = get(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build("this-session-totally-does-not-exist"));
    // Then
    checkException(response, ExceptionType.SESSION_NOT_FOUND);
}
Also used : Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Aggregations

SessionId (uk.gov.ida.hub.policy.domain.SessionId)92 Test (org.junit.Test)83 Response (javax.ws.rs.core.Response)41 URI (java.net.URI)33 ResponseProcessingDetails (uk.gov.ida.hub.policy.domain.ResponseProcessingDetails)14 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)13 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)12 Matchers.anyString (org.mockito.Matchers.anyString)9 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)9 InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.policy.contracts.InboundResponseFromMatchingServiceDto)6 MatchingServiceRequestErrorState (uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState)6 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)5 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto)5 Cycle3AttributeRequestData (uk.gov.ida.hub.policy.domain.Cycle3AttributeRequestData)5 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)5 NoMatchFromMatchingService (uk.gov.ida.hub.policy.domain.NoMatchFromMatchingService)5 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)5 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)4 SamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto)4 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)4