use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto 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);
}
use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto 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);
}
use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto 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);
}
use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto 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;
}
use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto in project verify-hub by alphagov.
the class MatchingServiceResourcesIntegrationTest method anAuthnResponseFromIdpWasReceivedAndMatchingRequestSent.
private void anAuthnResponseFromIdpWasReceivedAndMatchingRequestSent(SessionId sessionId) throws JsonProcessingException {
final URI policyUri = policy.uri(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId).getPath());
SamlAuthnResponseContainerDto samlAuthnResponseContainerDto = new SamlAuthnResponseContainerDto("saml-response", new SessionId(sessionId.getSessionId()), "principal-ip-address");
InboundResponseFromIdpDto inboundResponseFromIdpDto = InboundResponseFromIdpDtoBuilder.successResponse(idpEntityId, LEVEL_2);
configStub.setUpStubForMatchingServiceRequest(rpEntityId, msaEntityId);
samlEngineStub.setupStubForAttributeQueryRequest(AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build());
samlEngineStub.setupStubForIdpAuthnResponseTranslate(inboundResponseFromIdpDto);
samlSoapProxyProxyStubRule.setUpStubForSendHubMatchingServiceRequest(sessionId);
postResponse(policyUri, samlAuthnResponseContainerDto);
}
Aggregations