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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations