Search in sources :

Example 16 with EventSinkHubEvent

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

the class AttributeQueryRequestRunnableTest method run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceRequestIsNotProperlySigned.

@Test
public void run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceRequestIsNotProperlySigned() {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid Saml", 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).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).contains("Incorrect message provided by caller");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).contains("Incorrect message provided by caller");
}
Also used : InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) 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)

Example 17 with EventSinkHubEvent

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

the class ExternalCommunicationEventLoggerTest method logMatchingServiceRequest_shouldPassHubEventToEventSinkProxy.

@Test
public void logMatchingServiceRequest_shouldPassHubEventToEventSinkProxy() {
    externalCommunicationEventLogger.logMatchingServiceRequest(MESSAGE_ID, SESSION_ID, ENDPOINT_URL);
    final EventSinkHubEvent expectedEvent = new EventSinkHubEvent(SERVICE_INFO, SESSION_ID, EXTERNAL_COMMUNICATION_EVENT, Map.of(external_communication_type, MATCHING_SERVICE_REQUEST, message_id, MESSAGE_ID, external_endpoint, ENDPOINT_URL.toString(), external_ip_address, ENDPOINT_IP_ADDRESS));
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 18 with EventSinkHubEvent

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

the class ExternalCommunicationEventLogger method logExternalCommunicationEvent.

private void logExternalCommunicationEvent(String messageId, SessionId sessionId, URI targetUrl, String externalCommunicationType, IncludeIpAddressState includeIpAddressState, Map<EventDetailsKey, String> details) {
    details.put(external_communication_type, externalCommunicationType);
    details.put(message_id, messageId);
    details.put(external_endpoint, targetUrl.toString());
    if (includeIpAddressState == IncludeIpAddressState.WITH_RESOLVED_IP_ADDRESS) {
        details.put(external_ip_address, ipAddressResolver.lookupIpAddress(targetUrl));
    }
    final EventSinkHubEvent hubEvent = new EventSinkHubEvent(serviceInfo, sessionId, EXTERNAL_COMMUNICATION_EVENT, details);
    eventSinkProxy.logHubEvent(hubEvent);
    eventEmitter.record(hubEvent);
}
Also used : EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)

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