Search in sources :

Example 1 with TimeoutState

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

the class ErrorStateControllerTests method shouldReturnErrorResponseWhenAskedAndInTimeoutState.

@Test
public void shouldReturnErrorResponseWhenAskedAndInTimeoutState() {
    TimeoutState state = TimeoutStateBuilder.aTimeoutState().build();
    StateController stateController = new TimeoutStateController(state, responseFromHubFactory);
    when(sessionRepository.getStateController(sessionId, ErrorResponsePreparedState.class)).thenReturn(stateController);
    ResponseFromHub responseFromHub = authnRequestFromTransactionHandler.getErrorResponseFromHub(sessionId);
    assertThat(responseFromHub.getStatus()).isEqualTo(TransactionIdaStatus.NoAuthenticationContext);
}
Also used : TimeoutState(uk.gov.ida.hub.policy.domain.state.TimeoutState) StateController(uk.gov.ida.hub.policy.domain.StateController) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 2 with TimeoutState

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

the class SessionRepository method handleTimeout.

private void handleTimeout(SessionId sessionId, State state, Class<? extends State> stateClass, Class<? extends State> expectedStateClass) {
    boolean needsStateChangedToTimeout = isTimedOut(sessionId) && !stateClass.equals(TimeoutState.class);
    if (needsStateChangedToTimeout) {
        dataStore.replace(sessionId, new TimeoutState(state.getRequestId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getAssertionConsumerServiceUri(), state.getSessionId(), state.getTransactionSupportsEidas()));
    }
    boolean unexpectedErrorState = isErrorState(stateClass) && !isErrorState(expectedStateClass);
    if (needsStateChangedToTimeout || unexpectedErrorState) {
        throw new SessionTimeoutException(format("Session {0} timed out.", sessionId.getSessionId()), sessionId, state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getRequestId());
    }
}
Also used : TimeoutState(uk.gov.ida.hub.policy.domain.state.TimeoutState) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException)

Example 3 with TimeoutState

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

the class SessionRepositoryTest method getState_shouldReturnTimeoutController_whenTimeoutStateRequestedAndStateHasTimedOut.

@Test
public void getState_shouldReturnTimeoutController_whenTimeoutStateRequestedAndStateHasTimedOut() {
    DateTime now = DateTime.now();
    DateTimeFreezer.freezeTime(now);
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(now).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    DateTimeFreezer.freezeTime(now.plusMinutes(3));
    // this action will implicitly move the session state to TimedOut
    try {
        sessionRepository.getStateController(sessionId, SessionStartedState.class);
    } catch (SessionTimeoutException e) {
    }
    sessionRepository.getStateController(sessionId, TimeoutState.class);
    verify(controllerFactory).build(timeoutStateArgumentCaptor.capture(), any(StateTransitionAction.class));
    TimeoutState timeoutState = timeoutStateArgumentCaptor.getValue();
    assertThat(timeoutState.getRequestId()).isEqualTo(sessionStartedState.getRequestId());
    assertThat(timeoutState.getRequestIssuerEntityId()).isEqualTo(sessionStartedState.getRequestIssuerEntityId());
    assertThat(timeoutState.getAssertionConsumerServiceUri()).isEqualTo(sessionStartedState.getAssertionConsumerServiceUri());
}
Also used : TimeoutState(uk.gov.ida.hub.policy.domain.state.TimeoutState) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException) 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)

Aggregations

TimeoutState (uk.gov.ida.hub.policy.domain.state.TimeoutState)3 Test (org.junit.Test)2 SessionTimeoutException (uk.gov.ida.hub.policy.exception.SessionTimeoutException)2 DateTime (org.joda.time.DateTime)1 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)1 SessionStartedStateBuilder.aSessionStartedState (uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState)1 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)1 StateController (uk.gov.ida.hub.policy.domain.StateController)1 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1