Search in sources :

Example 16 with ResponseFromHub

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

the class SessionServiceTest method sendErrorResponseFromHub_shouldErrorWhenSamlEngineProxyReturnsAnError.

@Test(expected = ApplicationException.class)
public void sendErrorResponseFromHub_shouldErrorWhenSamlEngineProxyReturnsAnError() throws Exception {
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    ResponseFromHub responseFromHub = aResponseFromHubDto().withRelayState("relayState").build();
    when(authnRequestHandler.getErrorResponseFromHub(sessionId)).thenReturn(responseFromHub);
    when(samlEngineProxy.generateErrorResponseFromHub(any())).thenThrow(ApplicationException.createAuditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID()));
    service.getRpErrorResponse(sessionId);
}
Also used : SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 17 with ResponseFromHub

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

the class SuccessfulMatchStateControllerTest method getPreparedResponse_shouldReturnResponse.

@Test
public void getPreparedResponse_shouldReturnResponse() {
    List<String> enabledIdentityProviders = singletonList(state.getIdentityProviderEntityId());
    ResponseFromHub expectedResponseFromHub = ResponseFromHubBuilder.aResponseFromHubDto().build();
    when(identityProvidersConfigProxy.getEnabledIdentityProviders(eq(state.getRequestIssuerEntityId()), anyBoolean(), any(LevelOfAssurance.class))).thenReturn(enabledIdentityProviders);
    when(responseFromHubFactory.createSuccessResponseFromHub(state.getRequestId(), state.getMatchingServiceAssertion(), state.getRelayState(), state.getRequestIssuerEntityId(), state.getAssertionConsumerServiceUri())).thenReturn(expectedResponseFromHub);
    ResponseFromHub result = controller.getPreparedResponse();
    Assert.assertEquals(result, expectedResponseFromHub);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 18 with ResponseFromHub

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

the class SessionServiceTest method shouldUpdateSessionStateAndCallSamlEngineWhenResponseFromHubIsRequested.

@Test
public void shouldUpdateSessionStateAndCallSamlEngineWhenResponseFromHubIsRequested() {
    // Given
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    ResponseFromHub responseFromHub = aResponseFromHubDto().build();
    when(authnRequestHandler.getResponseFromHub(sessionId)).thenReturn(responseFromHub);
    AuthnResponseFromHubContainerDto expected = anAuthnResponseFromHubContainerDto().build();
    when(samlEngineProxy.generateRpAuthnResponse(responseFromHub)).thenReturn(expected);
    // When
    AuthnResponseFromHubContainerDto actual = service.getRpAuthnResponse(sessionId);
    // Then
    assertThat(actual).isEqualTo(expected);
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.builder.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 19 with ResponseFromHub

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

the class Cycle3MatchRequestSentStateControllerTest method shouldReturnErrorResponseWhenAskedAndInAwaitingCycle3DataState.

@Test
public void shouldReturnErrorResponseWhenAskedAndInAwaitingCycle3DataState() {
    final String requestId = "requestId";
    final SessionId sessionId = SessionId.createNewSessionId();
    Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().withSessionId(sessionId).withRequestId(requestId).build();
    Cycle3MatchRequestSentStateController controller = new Cycle3MatchRequestSentStateController(state, hubEventLogger, null, policyConfiguration, null, responseFromHubFactory, transactionsConfigProxy, matchingServiceConfigProxy, assertionRestrictionFactory, attributeQueryService);
    final ResponseFromHub responseFromHub = controller.getErrorResponse();
    assertThat(responseFromHub.getStatus()).isEqualTo(TransactionIdaStatus.NoAuthenticationContext);
}
Also used : Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) Matchers.anyString(org.mockito.Matchers.anyString) SessionId(uk.gov.ida.hub.policy.domain.SessionId) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 20 with ResponseFromHub

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

the class ErrorStateControllerTests method shouldReturnErrorResponseWhenAskedAndInSessionStartedState.

@Test
public void shouldReturnErrorResponseWhenAskedAndInSessionStartedState() {
    SessionStartedState state = SessionStartedStateBuilder.aSessionStartedState().build();
    StateController stateController = new SessionStartedStateController(state, hubEventLogger, stateTransitionAction, transactionsConfigProxy, responseFromHubFactory, identityProvidersConfigProxy);
    when(sessionRepository.getStateController(sessionId, ErrorResponsePreparedState.class)).thenReturn(stateController);
    ResponseFromHub responseFromHub = authnRequestFromTransactionHandler.getErrorResponseFromHub(sessionId);
    assertThat(responseFromHub.getStatus()).isEqualTo(TransactionIdaStatus.NoAuthenticationContext);
}
Also used : StateController(uk.gov.ida.hub.policy.domain.StateController) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Aggregations

ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)27 Test (org.junit.Test)25 StateController (uk.gov.ida.hub.policy.domain.StateController)16 SessionId (uk.gov.ida.hub.policy.domain.SessionId)5 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto)3 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)3 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)3 Matchers.anyString (org.mockito.Matchers.anyString)2 AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.builder.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto)2 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)2 SamlMessageDto (uk.gov.ida.hub.policy.contracts.SamlMessageDto)2 RequestForErrorResponseFromHubDto (uk.gov.ida.hub.policy.contracts.RequestForErrorResponseFromHubDto)1 EidasCountryDto (uk.gov.ida.hub.policy.domain.EidasCountryDto)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 AuthnFailedErrorState (uk.gov.ida.hub.policy.domain.state.AuthnFailedErrorState)1 AwaitingCycle3DataState (uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState)1 Cycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState)1 Cycle3DataInputCancelledState (uk.gov.ida.hub.policy.domain.state.Cycle3DataInputCancelledState)1 FraudEventDetectedState (uk.gov.ida.hub.policy.domain.state.FraudEventDetectedState)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1