Search in sources :

Example 11 with State

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

the class UserAccountCreationRequestSentStateControllerTest method getNextState_shouldMaintainRelayState.

@Test
public void getNextState_shouldMaintainRelayState() {
    final String relayState = "4x100m";
    UserAccountCreationRequestSentState state = aUserAccountCreationRequestSentState().withRelayState(relayState).build();
    UserAccountCreationRequestSentStateController controller = new UserAccountCreationRequestSentStateController(state, null, hubEventLogger, null, levelOfAssuranceValidator, null, null);
    UserAccountCreatedFromMatchingService userAccountCreatedFromMatchingService = new UserAccountCreatedFromMatchingService("issuer-id", "", "", Optional.absent());
    final State newState = controller.getNextStateForUserAccountCreated(userAccountCreatedFromMatchingService);
    assertThat(newState).isInstanceOf(UserAccountCreatedState.class);
    final UserAccountCreatedState userAccountCreatedState = (UserAccountCreatedState) newState;
    assertThat(userAccountCreatedState.getRelayState()).isNotNull();
    assertThat(userAccountCreatedState.getRelayState().isPresent()).isTrue();
    assertThat(userAccountCreatedState.getRelayState().get()).isEqualTo(relayState);
}
Also used : UserAccountCreatedState(uk.gov.ida.hub.policy.domain.state.UserAccountCreatedState) UserAccountCreationRequestSentStateBuilder.aUserAccountCreationRequestSentState(uk.gov.ida.hub.policy.builder.state.UserAccountCreationRequestSentStateBuilder.aUserAccountCreationRequestSentState) State(uk.gov.ida.hub.policy.domain.State) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) UserAccountCreatedState(uk.gov.ida.hub.policy.domain.state.UserAccountCreatedState) UserAccountCreatedFromMatchingService(uk.gov.ida.hub.policy.domain.UserAccountCreatedFromMatchingService) UserAccountCreationRequestSentStateBuilder.aUserAccountCreationRequestSentState(uk.gov.ida.hub.policy.builder.state.UserAccountCreationRequestSentStateBuilder.aUserAccountCreationRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) Test(org.junit.Test)

Example 12 with State

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

the class Cycle0And1MatchRequestSentStateControllerTest method getNextState_shouldReturnUserAccountCreationRequestSentStateWhenTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation.

@Test
public void getNextState_shouldReturnUserAccountCreationRequestSentStateWhenTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation() {
    // Given
    URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
    List<UserAccountCreationAttribute> userAccountCreationAttributes = singletonList(UserAccountCreationAttribute.DATE_OF_BIRTH);
    when(transactionsConfigProxy.getMatchingProcess(TRANSACTION_ENTITY_ID)).thenReturn(new MatchingProcess(Optional.absent()));
    when(transactionsConfigProxy.getUserAccountCreationAttributes(TRANSACTION_ENTITY_ID)).thenReturn(userAccountCreationAttributes);
    when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
    // When
    final State nextState = controller.getNextStateForNoMatch();
    // Then
    verify(hubEventLogger).logMatchingServiceUserAccountCreationRequestSentEvent(state.getSessionId(), TRANSACTION_ENTITY_ID, state.getSessionExpiryTimestamp(), state.getRequestId());
    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(nextState).isInstanceOf(UserAccountCreationRequestSentState.class);
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) SuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.SuccessfulMatchState) Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState) AwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState) State(uk.gov.ida.hub.policy.domain.State) Cycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) MatchingProcess(uk.gov.ida.hub.policy.domain.MatchingProcess) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) URI(java.net.URI) Test(org.junit.Test)

Example 13 with State

use of uk.gov.ida.hub.policy.domain.State 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 14 with State

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

the class EidasCycle0And1MatchRequestSentStateControllerTest method shouldReturnNoMatchState.

@Test
public void shouldReturnNoMatchState() {
    when(transactionsConfigProxy.getMatchingProcess(state.getRequestIssuerEntityId())).thenReturn(new MatchingProcess(Optional.absent()));
    doNothing().when(hubEventLogger).logCycle01NoMatchEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
    NoMatchState expectedState = new NoMatchState(state.getRequestId(), state.getIdentityProviderEntityId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getAssertionConsumerServiceUri(), state.getRelayState(), state.getSessionId(), state.getTransactionSupportsEidas());
    State actualState = eidasCycle0And1MatchRequestSentStateController.getNextStateForNoMatch();
    assertThat(actualState).isEqualTo(expectedState);
}
Also used : EidasAwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.EidasAwaitingCycle3DataState) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) EidasSuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.EidasSuccessfulMatchState) EidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState) EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState) State(uk.gov.ida.hub.policy.domain.State) MatchingProcess(uk.gov.ida.hub.policy.domain.MatchingProcess) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) Test(org.junit.Test)

Example 15 with State

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

the class AbstractMatchRequestSentStateController method handleUserAccountCreatedResponseFromMatchingService.

@Override
public final void handleUserAccountCreatedResponseFromMatchingService(UserAccountCreatedFromMatchingService userAccountCreatedResponseFromMatchingService) {
    validateResponse(userAccountCreatedResponseFromMatchingService);
    State nextState = getNextStateForUserAccountCreated(userAccountCreatedResponseFromMatchingService);
    stateTransitionAction.transitionTo(nextState);
}
Also used : MatchingServiceRequestErrorState(uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState) AbstractSuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.AbstractSuccessfulMatchState) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) State(uk.gov.ida.hub.policy.domain.State) AbstractMatchRequestSentState(uk.gov.ida.hub.policy.domain.state.AbstractMatchRequestSentState)

Aggregations

State (uk.gov.ida.hub.policy.domain.State)15 Test (org.junit.Test)11 NoMatchState (uk.gov.ida.hub.policy.domain.state.NoMatchState)11 UserAccountCreationRequestSentState (uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState)6 Cycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState)5 MatchingProcess (uk.gov.ida.hub.policy.domain.MatchingProcess)4 Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState)3 EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState)3 UserAccountCreationAttribute (uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute)3 AbstractMatchRequestSentState (uk.gov.ida.hub.policy.domain.state.AbstractMatchRequestSentState)3 AbstractSuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.AbstractSuccessfulMatchState)3 AwaitingCycle3DataState (uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState)3 EidasAwaitingCycle3DataState (uk.gov.ida.hub.policy.domain.state.EidasAwaitingCycle3DataState)3 EidasCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState)3 EidasSuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.EidasSuccessfulMatchState)3 MatchingServiceRequestErrorState (uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState)3 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)3 SuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.SuccessfulMatchState)3 URI (java.net.URI)2 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)2