Search in sources :

Example 6 with ResponseAction

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

the class AuthnResponseFromIdpServiceTest method shouldOnlyUpdateSessionStateWhenAFraudSuccessfulResponseIsReceived.

@Test
public void shouldOnlyUpdateSessionStateWhenAFraudSuccessfulResponseIsReceived() {
    // Given
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    InboundResponseFromIdpDto fraudResponseFromIdp = InboundResponseFromIdpDtoBuilder.fraudResponse(UUID.randomUUID().toString());
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(fraudResponseFromIdp);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    ResponseAction expectedResponseAction = ResponseAction.other(sessionId, REGISTERING);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnFraud(fraudResponseFromIdp);
}
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 7 with ResponseAction

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

the class AuthnResponseFromIdpServiceTest method mapAuthnContextResponseFromIdpAsOther.

@Test
public void mapAuthnContextResponseFromIdpAsOther() {
    // Given
    final boolean isRegistration = true;
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(isRegistration);
    InboundResponseFromIdpDto noAuthenticationContextResponse = InboundResponseFromIdpDtoBuilder.errorResponse(UUID.randomUUID().toString(), IdpIdaStatus.Status.NoAuthenticationContext);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(noAuthenticationContextResponse);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    verifyNoMoreInteractions(samlEngineProxy);
    verify(idpSelectedStateController).handleNoAuthenticationContextResponseFromIdp(any(AuthenticationErrorResponse.class));
    ResponseAction expectedResponseAction = ResponseAction.other(sessionId, isRegistration);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnNonFraudNoAuthenticationContext(noAuthenticationContextResponse);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) AuthenticationErrorResponse(uk.gov.ida.hub.policy.domain.AuthenticationErrorResponse) AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse(uk.gov.ida.hub.policy.builder.domain.AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 8 with ResponseAction

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldHandleAuthnFailedResponse.

@Test
public void responsePost_shouldHandleAuthnFailedResponse() throws Exception {
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.failedResponse(idpEntityId));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    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)

Example 9 with ResponseAction

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldHandAuthnSuccessResponse.

@Test
public void responsePost_shouldHandAuthnSuccessResponse() throws Exception {
    LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.successResponse(idpEntityId, loaAchieved));
    samlEngineStub.setupStubForAttributeQueryRequest(AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build());
    samlSoapProxyStub.setUpStubForSendHubMatchingServiceRequest(sessionId);
    Response response = postIdpResponse(sessionId, samlResponseDto);
    ResponseAction expected = ResponseAction.success(sessionId, true, loaAchieved);
    ResponseAction actualResponseAction = response.readEntity(ResponseAction.class);
    assertThat(actualResponseAction).isEqualToComparingFieldByField(expected);
    SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = samlEngineStub.getSamlAuthnResponseTranslatorDto(policy.getObjectMapper());
    assertThat(samlAuthnResponseTranslatorDto.getMatchingServiceEntityId()).isEqualTo(matchingServiceEntityId);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Response(javax.ws.rs.core.Response) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 10 with ResponseAction

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

the class AuthnResponseFromIdpServiceTest method mapFailedUpliftResponseFromIDP.

@Test
public void mapFailedUpliftResponseFromIDP() {
    // Given
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    InboundResponseFromIdpDto noAuthenticationContextResponse = InboundResponseFromIdpDtoBuilder.errorResponse(UUID.randomUUID().toString(), IdpIdaStatus.Status.UpliftFailed);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(noAuthenticationContextResponse);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    verifyNoMoreInteractions(samlEngineProxy);
    verify(idpSelectedStateController).handleNoAuthenticationContextResponseFromIdp(any(AuthenticationErrorResponse.class));
    ResponseAction expectedResponseAction = ResponseAction.failedUplift(sessionId, REGISTERING);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnNonFraudNoAuthenticationContext(noAuthenticationContextResponse);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) AuthenticationErrorResponse(uk.gov.ida.hub.policy.domain.AuthenticationErrorResponse) AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse(uk.gov.ida.hub.policy.builder.domain.AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) 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