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