use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class Cycle3MatchRequestSentStateControllerTest method getNextStateForNoMatch_shouldReturnUserAccountCreationRequestSentStateWhenAttributesArePresent.
@Test
public void getNextStateForNoMatch_shouldReturnUserAccountCreationRequestSentStateWhenAttributesArePresent() {
// Given
URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().build();
ImmutableList<UserAccountCreationAttribute> userAccountCreationAttributes = ImmutableList.of(UserAccountCreationAttribute.DATE_OF_BIRTH);
String transactionEntityId = "request issuer id";
when(transactionsConfigProxy.getUserAccountCreationAttributes(transactionEntityId)).thenReturn(userAccountCreationAttributes);
when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
Cycle3MatchRequestSentStateController controller = new Cycle3MatchRequestSentStateController(state, hubEventLogger, null, policyConfiguration, null, null, transactionsConfigProxy, matchingServiceConfigProxy, assertionRestrictionFactory, attributeQueryService);
// When
State nextState = controller.getNextStateForNoMatch();
// Then
ArgumentCaptor<EventSinkHubEvent> eventSinkArgumentCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
verify(eventSinkProxy, times(1)).logHubEvent(eventSinkArgumentCaptor.capture());
assertThat(eventSinkArgumentCaptor.getValue().getEventType()).isEqualTo(EventSinkHubEventConstants.EventTypes.SESSION_EVENT);
assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.session_event_type)).isEqualTo(USER_ACCOUNT_CREATION_REQUEST_SENT);
assertThat(eventSinkArgumentCaptor.getValue().getSessionId()).isEqualTo(state.getSessionId().toString());
assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.request_id)).isEqualTo(state.getRequestId());
assertThat(eventSinkArgumentCaptor.getValue().getOriginatingService()).isEqualTo(serviceInfo.getName());
verify(attributeQueryService).sendAttributeQueryRequest(eq(nextState.getSessionId()), attributeQueryRequestCaptor.capture());
AttributeQueryRequestDto actualAttributeQueryRequestDto = attributeQueryRequestCaptor.getValue();
assertThat(actualAttributeQueryRequestDto.getAttributeQueryUri()).isEqualTo(userAccountCreationUri);
assertThat(actualAttributeQueryRequestDto.getUserAccountCreationAttributes()).isEqualTo(Optional.fromNullable(userAccountCreationAttributes));
assertThat(actualAttributeQueryRequestDto.getEncryptedMatchingDatasetAssertion()).isEqualTo(state.getEncryptedMatchingDatasetAssertion());
assertThat(nextState).isInstanceOf(UserAccountCreationRequestSentState.class);
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class AttributeQueryServiceTest method shouldPropagateExceptionThrownBySamlEngineAndNotSendAttributeQuery.
@Test
public void shouldPropagateExceptionThrownBySamlEngineAndNotSendAttributeQuery() {
Assertions.assertThrows(ApplicationException.class, () -> {
// Given
AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
when(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).thenThrow(ApplicationException.createAuditedException(INVALID_SAML, UUID.randomUUID()));
// When
service.sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
// Then
verify(samlEngineProxy, times(1)).generateAttributeQuery(attributeQueryRequestDto);
verify(samlSoapProxyProxy, times(0)).sendHubMatchingServiceRequest(eq(sessionId), any());
});
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class AuthnResponseFromIdpService method handleSuccessResponse.
private ResponseAction handleSuccessResponse(InboundResponseFromIdpDto inboundResponseFromIdpDto, SessionId sessionId, String principalIPAddressAsSeenByHub, boolean matchingJourney, IdpSelectedStateController idpSelectedStateController, String analyticsSessionId, String journeyType) {
LevelOfAssurance loaAchieved = inboundResponseFromIdpDto.getLevelOfAssurance().get();
SuccessFromIdp successFromIdp = new SuccessFromIdp(inboundResponseFromIdpDto.getIssuer(), inboundResponseFromIdpDto.getEncryptedMatchingDatasetAssertion().get(), inboundResponseFromIdpDto.getEncryptedAuthnAssertion().get(), new PersistentId(inboundResponseFromIdpDto.getPersistentId().get()), loaAchieved, principalIPAddressAsSeenByHub, inboundResponseFromIdpDto.getPrincipalIpAddressAsSeenByIdp(), analyticsSessionId, journeyType);
if (matchingJourney) {
idpSelectedStateController.handleMatchingJourneySuccessResponseFromIdp(successFromIdp);
AttributeQueryRequestDto attributeQuery = idpSelectedStateController.createAttributeQuery(successFromIdp);
attributeQueryService.sendAttributeQueryRequest(sessionId, attributeQuery);
return success(sessionId, idpSelectedStateController.isRegistrationContext(), loaAchieved, inboundResponseFromIdpDto.getNotOnOrAfter().orElse(null));
} else {
idpSelectedStateController.handleNonMatchingJourneySuccessResponseFromIdp(successFromIdp);
return nonMatchingJourneySuccess(sessionId, idpSelectedStateController.isRegistrationContext(), loaAchieved, inboundResponseFromIdpDto.getNotOnOrAfter().orElse(null));
}
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class Cycle0And1MatchRequestSentStateController method transitionToNextStateForNoMatchResponse.
@Override
protected void transitionToNextStateForNoMatchResponse() {
Optional<String> selfAssertedAttributeName = transactionsConfigProxy.getMatchingProcess(state.getRequestIssuerEntityId()).getAttributeName();
if (selfAssertedAttributeName.isPresent()) {
hubEventLogger.logWaitingForCycle3AttributesEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
stateTransitionAction.transitionTo(createAwaitingCycle3DataState());
return;
}
List<UserAccountCreationAttribute> userAccountCreationAttributes = transactionsConfigProxy.getUserAccountCreationAttributes(state.getRequestIssuerEntityId());
if (!userAccountCreationAttributes.isEmpty()) {
AttributeQueryRequestDto attributeQueryRequestDto = createAttributeQuery(userAccountCreationAttributes, state.getEncryptedMatchingDatasetAssertion(), state.getAuthnStatementAssertion(), state.getPersistentId(), assertionRestrictionFactory.getAssertionExpiry());
transitionToUserAccountCreationRequestSentState(attributeQueryRequestDto);
return;
}
hubEventLogger.logCycle01NoMatchEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
stateTransitionAction.transitionTo(createNoMatchState());
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class Cycle3MatchRequestSentStateController method transitionToNextStateForNoMatchResponse.
@Override
protected void transitionToNextStateForNoMatchResponse() {
List<UserAccountCreationAttribute> userAccountCreationAttributes = transactionsConfigProxy.getUserAccountCreationAttributes(state.getRequestIssuerEntityId());
if (!userAccountCreationAttributes.isEmpty()) {
AttributeQueryRequestDto attributeQueryRequestDto = createAttributeQuery(userAccountCreationAttributes, state.getEncryptedMatchingDatasetAssertion(), state.getAuthnStatementAssertion(), state.getPersistentId(), assertionRestrictionFactory.getAssertionExpiry());
transitionToUserAccountCreationRequestSentState(attributeQueryRequestDto);
return;
}
hubEventLogger.logCycle3NoMatchEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getRequestId());
stateTransitionAction.transitionTo(createNoMatchState());
}
Aggregations