Search in sources :

Example 1 with IdpSelectedState

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

the class ErrorStateControllerTests method shouldReturnErrorResponseWhenAskedAndInIdpSelectedState.

@Test
public void shouldReturnErrorResponseWhenAskedAndInIdpSelectedState() {
    IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().build();
    StateController stateController = new IdpSelectedStateController(state, hubEventLogger, stateTransitionAction, identityProvidersConfigProxy, transactionsConfigProxy, responseFromHubFactory, policyConfiguration, assertionRestrictionFactory, matchingServiceConfigProxy);
    when(sessionRepository.getStateController(sessionId, ErrorResponsePreparedState.class)).thenReturn(stateController);
    ResponseFromHub responseFromHub = authnRequestFromTransactionHandler.getErrorResponseFromHub(sessionId);
    assertThat(responseFromHub.getStatus()).isEqualTo(TransactionIdaStatus.NoAuthenticationContext);
}
Also used : IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) StateController(uk.gov.ida.hub.policy.domain.StateController) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 2 with IdpSelectedState

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

the class IdpSelectorTest method buildIdpSelectedState_shouldReturnStateWithNewIdpForIdpSelectedState.

@Test
public void buildIdpSelectedState_shouldReturnStateWithNewIdpForIdpSelectedState() {
    IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().withRelayState("relay-state").withIdpEntityId("idp-b").withAvailableIdentityProviders(ImmutableList.of(IDP_ENTITY_ID, OTHER_IDP_ENTITY_ID)).withRegistration(true).build();
    IdpConfigDto idpConfigDto = new IdpConfigDto(IDP_ENTITY_ID, true, ImmutableList.of(LevelOfAssurance.LEVEL_2, LevelOfAssurance.LEVEL_1));
    when(identityProvidersConfigProxy.getIdpConfig("idp-b")).thenReturn(idpConfigDto);
    when(transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId())).thenReturn(asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2));
    when(transactionsConfigProxy.getMatchingServiceEntityId(state.getRequestIssuerEntityId())).thenReturn(state.getMatchingServiceEntityId());
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(state.getRequestIssuerEntityId(), state.isRegistering(), REQUESTED_LOA)).thenReturn(asList(IDP_ENTITY_ID, OTHER_IDP_ENTITY_ID));
    IdpSelectedState idpSelectedState = IdpSelector.buildIdpSelectedState(state, "idp-b", true, REQUESTED_LOA, transactionsConfigProxy, identityProvidersConfigProxy);
    assertThat(idpSelectedState).isEqualToComparingFieldByField(state);
}
Also used : IdpConfigDto(uk.gov.ida.hub.policy.domain.IdpConfigDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) Test(org.junit.Test)

Example 3 with IdpSelectedState

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

the class IdpSelectorTest method shouldRaiseAnExceptionWhenSelectedIDPDoesNotHaveRequestedLevelOfAssurance.

@Test(expected = StateProcessingValidationException.class)
public void shouldRaiseAnExceptionWhenSelectedIDPDoesNotHaveRequestedLevelOfAssurance() {
    IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().withIdpEntityId(IDP_ENTITY_ID).withAvailableIdentityProviders(ImmutableList.of(IDP_ENTITY_ID)).build();
    when(transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId())).thenReturn(asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2));
    when(identityProvidersConfigProxy.getIdpConfig(IDP_ENTITY_ID)).thenReturn(new IdpConfigDto(IDP_ENTITY_ID, true, ImmutableList.of(LevelOfAssurance.LEVEL_1)));
    when(identityProvidersConfigProxy.getIdpConfig(OTHER_IDP_ENTITY_ID)).thenReturn(new IdpConfigDto(OTHER_IDP_ENTITY_ID, true, ImmutableList.of(REQUESTED_LOA)));
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(state.getRequestIssuerEntityId(), state.isRegistering(), REQUESTED_LOA)).thenReturn(singletonList(OTHER_IDP_ENTITY_ID));
    IdpSelector.buildIdpSelectedState(state, IDP_ENTITY_ID, true, REQUESTED_LOA, transactionsConfigProxy, identityProvidersConfigProxy);
}
Also used : IdpConfigDto(uk.gov.ida.hub.policy.domain.IdpConfigDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) Test(org.junit.Test)

Example 4 with IdpSelectedState

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

the class IdpSelectorTest method buildIdpSelectedState_shouldReturnStateWithSessionStartedState.

@Test
public void buildIdpSelectedState_shouldReturnStateWithSessionStartedState() {
    SessionStartedState state = SessionStartedStateBuilder.aSessionStartedState().build();
    when(transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId())).thenReturn(asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2));
    when(transactionsConfigProxy.getMatchingServiceEntityId(state.getRequestIssuerEntityId())).thenReturn("matching-service-id");
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(state.getRequestIssuerEntityId(), true, REQUESTED_LOA)).thenReturn(singletonList(IDP_ENTITY_ID));
    IdpSelectedState idpSelectedState = IdpSelector.buildIdpSelectedState(state, IDP_ENTITY_ID, true, REQUESTED_LOA, transactionsConfigProxy, identityProvidersConfigProxy);
    assertThat(idpSelectedState.getRelayState()).isEqualTo(state.getRelayState());
    assertThat(idpSelectedState.getIdpEntityId()).isEqualTo(IDP_ENTITY_ID);
    assertThat(idpSelectedState.getRequestIssuerEntityId()).isEqualTo(state.getRequestIssuerEntityId());
    assertThat(idpSelectedState.getAvailableIdentityProviderEntityIds()).isEqualTo(singletonList(IDP_ENTITY_ID));
    assertThat(idpSelectedState.getMatchingServiceEntityId()).isEqualTo("matching-service-id");
    assertThat(idpSelectedState.getForceAuthentication()).isEqualTo(state.getForceAuthentication());
    assertThat(idpSelectedState.getLevelsOfAssurance()).containsSequence(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2);
    assertThat(idpSelectedState.getSessionExpiryTimestamp()).isEqualTo(state.getSessionExpiryTimestamp());
}
Also used : IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 5 with IdpSelectedState

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

the class IdpSelectorTest method shouldRaiseAnExceptionWhenTransactionEntityDoesNotHaveRequestedLevelOfAssurance.

@Test(expected = StateProcessingValidationException.class)
public void shouldRaiseAnExceptionWhenTransactionEntityDoesNotHaveRequestedLevelOfAssurance() {
    IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().withIdpEntityId(IDP_ENTITY_ID).withAvailableIdentityProviders(ImmutableList.of(IDP_ENTITY_ID)).build();
    when(transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId())).thenReturn(singletonList(LevelOfAssurance.LEVEL_1));
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(state.getRequestIssuerEntityId(), state.isRegistering(), REQUESTED_LOA)).thenReturn(singletonList(IDP_ENTITY_ID));
    IdpSelector.buildIdpSelectedState(state, IDP_ENTITY_ID, true, REQUESTED_LOA, transactionsConfigProxy, identityProvidersConfigProxy);
}
Also used : IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) Test(org.junit.Test)

Aggregations

IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)17 Test (org.junit.Test)10 IdpConfigDto (uk.gov.ida.hub.policy.domain.IdpConfigDto)4 IdpSelectedStateBuilder.anIdpSelectedState (uk.gov.ida.hub.policy.builder.state.IdpSelectedStateBuilder.anIdpSelectedState)2 EventDetailsKey (uk.gov.ida.eventsink.EventDetailsKey)1 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)1 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)1 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1 StateController (uk.gov.ida.hub.policy.domain.StateController)1 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1 AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto (uk.gov.ida.integrationtest.hub.policy.builders.AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto)1