Search in sources :

Example 11 with AttributeQueryRequestDto

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);
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) State(uk.gov.ida.hub.policy.domain.State) Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) Matchers.anyString(org.mockito.Matchers.anyString) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Example 12 with AttributeQueryRequestDto

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());
    });
}
Also used : AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) Test(org.junit.jupiter.api.Test)

Example 13 with AttributeQueryRequestDto

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));
    }
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) SuccessFromIdp(uk.gov.ida.hub.policy.domain.SuccessFromIdp) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) PersistentId(uk.gov.ida.hub.policy.domain.PersistentId)

Example 14 with AttributeQueryRequestDto

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());
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)

Example 15 with AttributeQueryRequestDto

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());
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)

Aggregations

AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)15 UserAccountCreationAttribute (uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute)8 Test (org.junit.jupiter.api.Test)6 URI (java.net.URI)4 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)4 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)4 UserAccountCreationRequestSentState (uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState)4 Test (org.junit.Test)3 AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)3 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)2 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)2 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)2 MatchingProcess (uk.gov.ida.hub.policy.domain.MatchingProcess)2 PersistentId (uk.gov.ida.hub.policy.domain.PersistentId)2 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)2 State (uk.gov.ida.hub.policy.domain.State)2 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)2 NoMatchState (uk.gov.ida.hub.policy.domain.state.NoMatchState)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Matchers.anyString (org.mockito.Matchers.anyString)1