Search in sources :

Example 1 with RequesterErrorResponse

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

the class AuthnResponseFromIdpServiceTest method shouldOnlyUpdateSessionStateWhenANonFraudRequesterErrorResponseIsReceived.

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

Example 2 with RequesterErrorResponse

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

the class IdpSelectedStateControllerTest method handleRequesterErrorResponseFromIdp_shouldThrowExceptionWhenIdpIsDisabled.

@Test(expected = IdpDisabledException.class)
public void handleRequesterErrorResponseFromIdp_shouldThrowExceptionWhenIdpIsDisabled() {
    RequesterErrorResponse requesterErrorResponse = aRequesterErrorResponse().build();
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(TRANSACTION_ENTITY_ID, controller.isRegistrationContext(), PROVIDED_LOA)).thenReturn(emptyList());
    controller.handleRequesterErrorResponseFromIdp(requesterErrorResponse);
}
Also used : RequesterErrorResponseBuilder.aRequesterErrorResponse(uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse) RequesterErrorResponse(uk.gov.ida.hub.policy.domain.RequesterErrorResponse) Test(org.junit.Test)

Example 3 with RequesterErrorResponse

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

the class IdpSelectedStateControllerTest method handleRequesterErrorResponseFromIdp_shouldLogEvent.

@Test
public void handleRequesterErrorResponseFromIdp_shouldLogEvent() {
    final String errorMessage = "an-error-message";
    RequesterErrorResponse requesterErrorResponse = aRequesterErrorResponse().withIssuerId(IDP_ENTITY_ID).withErrorMessage(errorMessage).withPrincipalIpAddressAsSeenByHub(PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_HUB).build();
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(TRANSACTION_ENTITY_ID, controller.isRegistrationContext(), PROVIDED_LOA)).thenReturn(singletonList(IDP_ENTITY_ID));
    controller.handleRequesterErrorResponseFromIdp(requesterErrorResponse);
    verify(hubEventLogger).logIdpRequesterErrorEvent(NEW_SESSION_ID, TRANSACTION_ENTITY_ID, SESSION_EXPIRY_TIMESTAMP, REQUEST_ID, Optional.fromNullable(errorMessage), PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_HUB);
}
Also used : RequesterErrorResponseBuilder.aRequesterErrorResponse(uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse) RequesterErrorResponse(uk.gov.ida.hub.policy.domain.RequesterErrorResponse) Test(org.junit.Test)

Example 4 with RequesterErrorResponse

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

the class AuthnResponseFromIdpServiceTest method verifyIdpStateControllerIsCalledWithRightDataOnNonFraudRequesterError.

private void verifyIdpStateControllerIsCalledWithRightDataOnNonFraudRequesterError(InboundResponseFromIdpDto requesterErrorResponse) {
    ArgumentCaptor<RequesterErrorResponse> captor = ArgumentCaptor.forClass(RequesterErrorResponse.class);
    RequesterErrorResponse expectedRequesterErrorResponse = aRequesterErrorResponse().withIssuerId(requesterErrorResponse.getIssuer()).withErrorMessage(requesterErrorResponse.getStatusMessage().get()).withPrincipalIpAddressAsSeenByHub(samlAuthnResponseContainerDto.getPrincipalIPAddressAsSeenByHub()).build();
    verify(idpSelectedStateController).handleRequesterErrorResponseFromIdp(captor.capture());
    RequesterErrorResponse actualRequesterErrorResponse = captor.getValue();
    assertThat(actualRequesterErrorResponse).isEqualToIgnoringGivenFields(expectedRequesterErrorResponse);
}
Also used : RequesterErrorResponseBuilder.aRequesterErrorResponse(uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse) RequesterErrorResponse(uk.gov.ida.hub.policy.domain.RequesterErrorResponse)

Example 5 with RequesterErrorResponse

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

the class AuthnResponseFromIdpService method handleRequesterError.

private ResponseAction handleRequesterError(InboundResponseFromIdpDto idaResponseFromIdp, SessionId sessionId, String principalIPAddressAsSeenByHub, IdpSelectedStateController idpSelectedStateController) {
    RequesterErrorResponse requesterErrorResponse = new RequesterErrorResponse(idaResponseFromIdp.getIssuer(), idaResponseFromIdp.getStatusMessage(), principalIPAddressAsSeenByHub);
    idpSelectedStateController.handleRequesterErrorResponseFromIdp(requesterErrorResponse);
    return other(sessionId, idpSelectedStateController.isRegistrationContext());
}
Also used : RequesterErrorResponse(uk.gov.ida.hub.policy.domain.RequesterErrorResponse)

Aggregations

RequesterErrorResponse (uk.gov.ida.hub.policy.domain.RequesterErrorResponse)5 RequesterErrorResponseBuilder.aRequesterErrorResponse (uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse)4 Test (org.junit.Test)3 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto)1 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)1 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)1