Search in sources :

Example 1 with SessionStartedState

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

the class SessionRepositoryTest method getState_shouldThrowTimeoutStateException_whenStateRequestedIsNotTimeoutStateAndAlreadyTimeout.

@Test(expected = SessionTimeoutException.class)
public void getState_shouldThrowTimeoutStateException_whenStateRequestedIsNotTimeoutStateAndAlreadyTimeout() {
    DateTime now = DateTime.now();
    DateTimeFreezer.freezeTime(now);
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(now).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    DateTimeFreezer.freezeTime(now.plusMinutes(3));
    try {
        sessionRepository.getStateController(sessionId, SessionStartedState.class);
    } catch (Exception e) {
    }
    // it is set to timed out now
    sessionRepository.getStateController(sessionId, SessionStartedState.class);
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) DateTime(org.joda.time.DateTime) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException) InvalidSessionStateException(uk.gov.ida.hub.policy.exception.InvalidSessionStateException) Test(org.junit.Test)

Example 2 with SessionStartedState

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

the class SessionRepositoryTest method getState_shouldThrowTimeoutStateException_whenStateRequestedIsNotTimeoutStateAndTimeout.

@Test(expected = SessionTimeoutException.class)
public void getState_shouldThrowTimeoutStateException_whenStateRequestedIsNotTimeoutStateAndTimeout() {
    DateTime now = DateTime.now();
    DateTimeFreezer.freezeTime(now);
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(now).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    DateTimeFreezer.freezeTime(now.plusMinutes(3));
    sessionRepository.getStateController(sessionId, SessionStartedState.class);
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) DateTime(org.joda.time.DateTime) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 3 with SessionStartedState

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

the class SessionRepositoryTest method shouldThrowExceptionIfStateIsNotWhatIsExpected.

@Test(expected = InvalidSessionStateException.class)
public void shouldThrowExceptionIfStateIsNotWhatIsExpected() {
    SessionId expectedSessionId = aSessionId().build();
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(defaultSessionExpiry).withSessionId(expectedSessionId).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    sessionRepository.getStateController(sessionId, IdpSelectedState.class);
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 4 with SessionStartedState

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

the class SessionRepositoryTest method getLevelOfAssuranceFromIdp.

@Test
public void getLevelOfAssuranceFromIdp() {
    SessionStartedState state = aSessionStartedState().build();
    SessionId sessionId = sessionRepository.createSession(state);
    assertThat(sessionRepository.getLevelOfAssuranceFromIdp(sessionId)).isEqualTo(Optional.absent());
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 5 with SessionStartedState

use of uk.gov.ida.hub.policy.domain.state.SessionStartedState 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)

Aggregations

SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)12 Test (org.junit.Test)11 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)9 SessionStartedStateBuilder.aSessionStartedState (uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState)9 DateTime (org.joda.time.DateTime)5 SessionTimeoutException (uk.gov.ida.hub.policy.exception.SessionTimeoutException)3 InvalidSessionStateException (uk.gov.ida.hub.policy.exception.InvalidSessionStateException)2 Duration (org.joda.time.Duration)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 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1 TimeoutState (uk.gov.ida.hub.policy.domain.state.TimeoutState)1