Search in sources :

Example 6 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class HealthCheckEventLoggerTest method shouldLogToEventSinkIfTheExceptionIsUnaudited.

@Test
public void shouldLogToEventSinkIfTheExceptionIsUnaudited() {
    URI uri = URI.create("uri-geller");
    ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID(), uri);
    Map<EventDetailsKey, String> details = Map.of(downstream_uri, unauditedException.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), message, unauditedException.getMessage());
    EventSinkHubEvent event = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details);
    eventLogger.logException(unauditedException, "test error message");
    ArgumentCaptor<EventSinkHubEvent> eventSinkCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    ArgumentCaptor<EventSinkHubEvent> eventEmitterCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy, times(1)).logHubEvent(eventSinkCaptor.capture());
    verify(eventEmitter, times(1)).record(eventEmitterCaptor.capture());
    assertThat(event).isEqualToComparingOnlyGivenFields(eventSinkCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
    assertThat(event).isEqualToComparingOnlyGivenFields(eventEmitterCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 7 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldNotNotifySamlEngineWhenMSAResponseIsReceivedAfterAttributeQueryHasTimedOut.

@Test
public void run_shouldNotNotifySamlEngineWhenMSAResponseIsReceivedAfterAttributeQueryHasTimedOut() throws IOException, SAXException, ParserConfigurationException {
    final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
    // this stubbing does nothing the first time it is called, and throws an exception the second time it is called
    doNothing().doThrow(new AttributeQueryTimeoutException("Attribute Query timed out by 1 seconds.")).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
    verify(eventEmitter).record(emitterLoggedHubEvent.capture());
    assertThat(loggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    assertThat(emitterLoggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    verify(hubMatchingServiceResponseReceiverProxy, times(0)).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).contains("Matching service attribute query has timed out, therefore not sending failure notification to saml engine.");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).contains("Matching service attribute query has timed out, therefore not sending failure notification to saml engine.");
}
Also used : Element(org.w3c.dom.Element) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 8 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceResponseIsNotProperlySigned.

@Test
public void run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceResponseIsNotProperlySigned() {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new SamlTransformationErrorException("Signature was not valid", Level.ERROR));
    attributeQueryRequestRunnable.run();
    final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
    verify(eventEmitter).record(emitterLoggedHubEvent.capture());
    assertThat(loggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    assertThat(emitterLoggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    verify(hubMatchingServiceResponseReceiverProxy).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).doesNotContain("Incorrect message provided by caller");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).doesNotContain("Incorrect message provided by caller");
}
Also used : SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 9 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run__shouldNotNotifySamlEngineWhenAttributeQueryHasTimedOutBeforeBeingSentToMSA.

@Test
public void run__shouldNotNotifySamlEngineWhenAttributeQueryHasTimedOutBeforeBeingSentToMSA() {
    doThrow(new AttributeQueryTimeoutException("Attribute Query timed out by 1 seconds.")).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
    verify(eventEmitter).record(emitterLoggedHubEvent.capture());
    assertThat(loggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    assertThat(emitterLoggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    verify(hubMatchingServiceResponseReceiverProxy, times(0)).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(1)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).contains("Matching service attribute timed out before even being sent.");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).contains("Matching service attribute timed out before even being sent.");
}
Also used : AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 10 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldNotifySamlEngineAndLogErrorWhenACertificateCannotBeChainedToThoseInTheTrustStore.

@Test
public void run_shouldNotifySamlEngineAndLogErrorWhenACertificateCannotBeChainedToThoseInTheTrustStore() {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new CertificateChainValidationException("cert chain validation error", new Exception()));
    attributeQueryRequestRunnable.run();
    final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
    verify(eventEmitter).record(emitterLoggedHubEvent.capture());
    assertThat(loggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    assertThat(emitterLoggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    verify(hubMatchingServiceResponseReceiverProxy, times(1)).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).contains("Problem with the matching service's signing certificate");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).contains("Problem with the matching service's signing certificate");
}
Also used : CertificateChainValidationException(uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException) CertificateChainValidationException(uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Aggregations

EventSinkHubEvent (uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)18 Test (org.junit.jupiter.api.Test)13 AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)5 EventDetailsKey (uk.gov.ida.eventemitter.EventDetailsKey)4 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 CertificateChainValidationException (uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException)2 InvalidSamlRequestInAttributeQueryException (uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException)2 URI (java.net.URI)1 UUID (java.util.UUID)1 Element (org.w3c.dom.Element)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1