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