Search in sources :

Example 6 with EventSinkHubEvent

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

the class ExternalCommunicationEventLoggerTest method logResponseFromHub_shouldPassHubEventToEventSinkProxy.

@Test
public void logResponseFromHub_shouldPassHubEventToEventSinkProxy() {
    externalCommunicationEventLogger.logResponseFromHub(MESSAGE_ID, SESSION_ID, ENDPOINT_URL, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_HUB);
    final Map<EventDetailsKey, String> details = Maps.newHashMap();
    details.put(external_communication_type, RESPONSE_FROM_HUB);
    details.put(message_id, MESSAGE_ID);
    details.put(external_endpoint, ENDPOINT_URL.toString());
    details.put(principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_HUB);
    final EventSinkHubEvent expectedEvent = new EventSinkHubEvent(SERVICE_INFO, SESSION_ID, EXTERNAL_COMMUNICATION_EVENT, details);
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 7 with EventSinkHubEvent

use of uk.gov.ida.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);
    ImmutableMap<EventDetailsKey, String> details = ImmutableMap.of(downstream_uri, unauditedException.getUri().or(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.eventsink.EventDetailsKey) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 8 with EventSinkHubEvent

use of uk.gov.ida.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.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 9 with EventSinkHubEvent

use of uk.gov.ida.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.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 10 with EventSinkHubEvent

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

the class AttributeQueryRequestRunnableTest method run_shouldNotifySamlEngineAndLogErrorWhenACertificateCannotBeChainedToThoseInTheTrustStore.

@Test
public void run_shouldNotifySamlEngineAndLogErrorWhenACertificateCannotBeChainedToThoseInTheTrustStore() throws IOException, SAXException, ParserConfigurationException {
    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.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Aggregations

EventSinkHubEvent (uk.gov.ida.eventsink.EventSinkHubEvent)18 Test (org.junit.Test)13 EventDetailsKey (uk.gov.ida.eventsink.EventDetailsKey)10 AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)5 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 Element (org.w3c.dom.Element)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 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1