Search in sources :

Example 46 with SessionId

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

the class PolicyApplicationExceptionMapperTest method toResponse_shouldAuditErrorIfUnaudited.

@Test
public void toResponse_shouldAuditErrorIfUnaudited() {
    final SessionId sessionId = aSessionId().build();
    final UUID errorId = UUID.randomUUID();
    when(servletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn(sessionId.toString());
    ApplicationException exception = createUnauditedException(ExceptionType.IDP_DISABLED, errorId);
    mapper.toResponse(exception);
    // detailsCaptor.capture());
    verify(eventLogger).logErrorEvent(eq(errorId), eq(sessionId), eq("Exception of type [IDP_DISABLED] "), eq("uri-not-present"));
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) UUID(java.util.UUID) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) Test(org.junit.Test)

Example 47 with SessionId

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

the class Cycle3ServiceTest method shouldSendEidasRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived.

@Test
public void shouldSendEidasRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived() {
    final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto().build();
    final Cycle3AttributeRequestData attributeRequestData = new Cycle3AttributeRequestData("attribute-name", "issuer-id");
    final SessionId eidasSessionId = SessionIdBuilder.aSessionId().build();
    when(eidasAwaitingCycle3DataStateController.getCycle3AttributeRequestData()).thenReturn(attributeRequestData);
    when(sessionRepository.getStateController(eidasSessionId, AbstractAwaitingCycle3DataState.class)).thenReturn(eidasAwaitingCycle3DataStateController);
    when(eidasAwaitingCycle3DataStateController.createAttributeQuery(Matchers.any(Cycle3Dataset.class))).thenReturn(eidasAttributeQueryRequestDto);
    service.sendCycle3MatchingRequest(eidasSessionId, cycle3UserInput);
    verify(eidasAwaitingCycle3DataStateController).createAttributeQuery(Matchers.any(Cycle3Dataset.class));
    verify(attributeQueryService).sendAttributeQueryRequest(eidasSessionId, eidasAttributeQueryRequestDto);
    verify(eidasAwaitingCycle3DataStateController).handleCycle3DataSubmitted("principal-ip-address-as-seen-by-hub");
}
Also used : Cycle3Dataset(uk.gov.ida.hub.policy.domain.Cycle3Dataset) Cycle3AttributeRequestData(uk.gov.ida.hub.policy.domain.Cycle3AttributeRequestData) SessionId(uk.gov.ida.hub.policy.domain.SessionId) EidasAttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto) Test(org.junit.Test)

Example 48 with SessionId

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

the class SessionServiceTest method shouldGetACountryAuthnRequestWithOverriddenSsoUrl.

@Test
public void shouldGetACountryAuthnRequestWithOverriddenSsoUrl() throws Exception {
    // Given
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    when(sessionRepository.isSessionInState(sessionId, CountrySelectedState.class)).thenReturn(true);
    AuthnRequestFromHub authnRequestFromHub = anAuthnRequestFromHub().withSsoUrl(URI.create("/theSsoUri")).build();
    when(authnRequestHandler.getIdaAuthnRequestFromHub(sessionId)).thenReturn(authnRequestFromHub);
    URI ssoUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    SamlRequestDto samlRequest = new SamlRequestDto("samlRequest", ssoUri);
    when(samlEngineProxy.generateCountryAuthnRequestFromHub(any(IdaAuthnRequestFromHubDto.class))).thenReturn(samlRequest);
    // When
    AuthnRequestFromHubContainerDto countryAuthnRequest = service.getIdpAuthnRequest(sessionId);
    // Then
    AuthnRequestFromHubContainerDto expected = new AuthnRequestFromHubContainerDto(samlRequest.getSamlRequest(), ssoUri, authnRequestFromHub.getRegistering());
    assertThat(countryAuthnRequest).isEqualToComparingFieldByField(expected);
    ArgumentCaptor<IdaAuthnRequestFromHubDto> requestFromHubDtoArgumentCaptor = ArgumentCaptor.forClass(IdaAuthnRequestFromHubDto.class);
    verify(samlEngineProxy).generateCountryAuthnRequestFromHub(requestFromHubDtoArgumentCaptor.capture());
    assertThat(requestFromHubDtoArgumentCaptor.getValue().getOverriddenSsoUrl(), notNullValue());
}
Also used : IdaAuthnRequestFromHubDto(uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto) SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) AuthnRequestFromHubBuilder.anAuthnRequestFromHub(uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) URI(java.net.URI) Test(org.junit.Test)

Example 49 with SessionId

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

the class SessionServiceTest method shouldThrowSessionCreationFailureExceptionIfProvidedAssertionConsumerServiceUrlDoesntMatch.

@Test(expected = SessionCreationFailureException.class)
public void shouldThrowSessionCreationFailureExceptionIfProvidedAssertionConsumerServiceUrlDoesntMatch() throws Exception {
    SamlResponseWithAuthnRequestInformationDto samlResponse = aSamlResponseWithAuthnRequestInformationDto().withAssertionConsumerServiceUrl(URI.create("http://wrongurl")).build();
    URI assertionConsumerServiceUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    final SessionId sessionId = SessionIdBuilder.aSessionId().with("coffee-pasta").build();
    givenSamlEngineTranslatesRequest(samlResponse);
    givenConfigReturnsAssertionConsumerServiceURLFor(samlResponse, assertionConsumerServiceUri);
    givenSessionIsCreated(samlResponse, assertionConsumerServiceUri, sessionId, false);
    service.create(requestDto);
}
Also used : SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto) SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) URI(java.net.URI) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) Test(org.junit.Test)

Example 50 with SessionId

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

the class SessionServiceTest method shouldGetIdpAuthnRequest.

@Test
public void shouldGetIdpAuthnRequest() throws Exception {
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    AuthnRequestFromHub authnRequestFromHub = anAuthnRequestFromHub().build();
    when(authnRequestHandler.getIdaAuthnRequestFromHub(sessionId)).thenReturn(authnRequestFromHub);
    URI ssoUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    SamlRequestDto samlRequest = new SamlRequestDto("samlRequest", ssoUri);
    when(samlEngineProxy.generateIdpAuthnRequestFromHub(any(IdaAuthnRequestFromHubDto.class))).thenReturn(samlRequest);
    AuthnRequestFromHubContainerDto idpAuthnRequest = service.getIdpAuthnRequest(sessionId);
    AuthnRequestFromHubContainerDto expected = new AuthnRequestFromHubContainerDto(samlRequest.getSamlRequest(), ssoUri, authnRequestFromHub.getRegistering());
    assertThat(idpAuthnRequest).isEqualToComparingFieldByField(expected);
}
Also used : IdaAuthnRequestFromHubDto(uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto) SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) AuthnRequestFromHubBuilder.anAuthnRequestFromHub(uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) URI(java.net.URI) Test(org.junit.Test)

Aggregations

SessionId (uk.gov.ida.hub.policy.domain.SessionId)92 Test (org.junit.Test)83 Response (javax.ws.rs.core.Response)41 URI (java.net.URI)33 ResponseProcessingDetails (uk.gov.ida.hub.policy.domain.ResponseProcessingDetails)14 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)13 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)12 Matchers.anyString (org.mockito.Matchers.anyString)9 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)9 InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.policy.contracts.InboundResponseFromMatchingServiceDto)6 MatchingServiceRequestErrorState (uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState)6 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)5 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto)5 Cycle3AttributeRequestData (uk.gov.ida.hub.policy.domain.Cycle3AttributeRequestData)5 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)5 NoMatchFromMatchingService (uk.gov.ida.hub.policy.domain.NoMatchFromMatchingService)5 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)5 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)4 SamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto)4 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)4