Search in sources :

Example 11 with ResponseAction

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

the class AuthnResponseFromIdpServiceTest method shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived.

@Test
public void shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived() {
    // Given
    final String msaEntityId = "a-msa-entity-id";
    LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    when(idpSelectedStateController.getMatchingServiceEntityId()).thenReturn(msaEntityId);
    InboundResponseFromIdpDto successResponseFromIdp = InboundResponseFromIdpDtoBuilder.successResponse(UUID.randomUUID().toString(), loaAchieved);
    SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto().build();
    when(samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId)).thenReturn(samlAuthnResponseTranslatorDto);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(successResponseFromIdp);
    AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
    stub(idpSelectedStateController.createAttributeQuery(any(SuccessFromIdp.class))).toReturn(attributeQueryRequestDto);
    AttributeQueryContainerDto msaRequest = AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build();
    stub(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).toReturn(msaRequest);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlAuthnResponseTranslatorDtoFactory).fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId);
    verify(attributeQueryService).sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
    verifyIdpStateControllerIsCalledWithRightDataOnSuccess(successResponseFromIdp);
    ResponseAction expectedResponseAction = ResponseAction.success(sessionId, REGISTERING, loaAchieved);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) SuccessFromIdp(uk.gov.ida.hub.policy.domain.SuccessFromIdp) AttributeQueryContainerDto(uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto) InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 12 with ResponseAction

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

the class AuthnResponseFromIdpServiceTest method shouldOnlyUpdateSessionStateWhenANonFraudAuthenticationFailedResponseIsReceived.

@Test
public void shouldOnlyUpdateSessionStateWhenANonFraudAuthenticationFailedResponseIsReceived() {
    // Given
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    InboundResponseFromIdpDto authenticationFailedResponse = InboundResponseFromIdpDtoBuilder.errorResponse(UUID.randomUUID().toString(), IdpIdaStatus.Status.AuthenticationFailed);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(authenticationFailedResponse);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    verifyNoMoreInteractions(samlEngineProxy);
    ResponseAction expectedResponseAction = ResponseAction.other(sessionId, REGISTERING);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnNonFraudAuthenticationFailed(authenticationFailedResponse);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 13 with ResponseAction

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

the class EidasSessionResourceIntegrationTest method shouldReturnPackagedFailureResponseWhenTranslationFails.

@Test
public void shouldReturnPackagedFailureResponseWhenTranslationFails() throws Exception {
    stubSamlEngineTranslationToFailForCountry(NETHERLANDS);
    SessionId sessionId = selectACountry(NETHERLANDS);
    Response response = postAuthnResponseToPolicy(sessionId);
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    ResponseAction responseAction = response.readEntity(ResponseAction.class);
    assertThat(responseAction.getResult()).isEqualTo(OTHER);
}
Also used : Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.hub.policy.domain.SessionId) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 14 with ResponseAction

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

the class AuthnResponseFromIdpService method receiveAuthnResponseFromIdp.

public ResponseAction receiveAuthnResponseFromIdp(SessionId sessionId, SamlAuthnResponseContainerDto samlResponseDto) {
    IdpSelectedStateController idpSelectedController = (IdpSelectedStateController) sessionRepository.getStateController(sessionId, IdpSelectedState.class);
    String matchingServiceEntityId = idpSelectedController.getMatchingServiceEntityId();
    final SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlResponseDto, matchingServiceEntityId);
    final InboundResponseFromIdpDto idaResponseFromIdpDto = samlEngineProxy.translateAuthnResponseFromIdp(samlAuthnResponseTranslatorDto);
    final String principalIPAddressAsSeenByHub = samlResponseDto.getPrincipalIPAddressAsSeenByHub();
    ResponseAction responseAction;
    if (isFraudulent(idaResponseFromIdpDto)) {
        responseAction = handleFraudResponse(idaResponseFromIdpDto, sessionId, principalIPAddressAsSeenByHub, idpSelectedController);
    } else {
        responseAction = handleNonFraudResponse(idaResponseFromIdpDto, sessionId, principalIPAddressAsSeenByHub, idpSelectedController);
    }
    return responseAction;
}
Also used : IdpSelectedStateController(uk.gov.ida.hub.policy.domain.controller.IdpSelectedStateController) InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction)

Example 15 with ResponseAction

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldHandleRequesterErrorResponse.

@Test
public void responsePost_shouldHandleRequesterErrorResponse() throws Exception {
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.errorResponse(idpEntityId, IdpIdaStatus.Status.RequesterError));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    ResponseAction expected = ResponseAction.other(sessionId, true);
    ResponseAction actualResponseAction = response.readEntity(ResponseAction.class);
    assertThat(actualResponseAction).isEqualToComparingFieldByField(expected);
}
Also used : Response(javax.ws.rs.core.Response) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Aggregations

ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)18 Test (org.junit.Test)16 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto)10 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)9 Response (javax.ws.rs.core.Response)8 AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse (uk.gov.ida.hub.policy.builder.domain.AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse)3 AuthenticationErrorResponse (uk.gov.ida.hub.policy.domain.AuthenticationErrorResponse)3 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)3 SessionId (uk.gov.ida.hub.policy.domain.SessionId)3 URI (java.net.URI)1 RequesterErrorResponseBuilder.aRequesterErrorResponse (uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse)1 AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)1 AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)1 RequesterErrorResponse (uk.gov.ida.hub.policy.domain.RequesterErrorResponse)1 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)1 IdpSelectedStateController (uk.gov.ida.hub.policy.domain.controller.IdpSelectedStateController)1 Cycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1