Search in sources :

Example 16 with EventSinkHubEvent

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

the class ExternalCommunicationEventLoggerTest method logAuthenticationRequest_shouldPassHubEventToEventSinkProxy.

@Test
public void logAuthenticationRequest_shouldPassHubEventToEventSinkProxy() {
    externalCommunicationEventLogger.logIdpAuthnRequest(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, AUTHN_REQUEST);
    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 17 with EventSinkHubEvent

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

Example 18 with EventSinkHubEvent

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

the class AttributeQueryRequestRunnableTest method run_shouldSayIfTimeoutWasBeforeSendingMessage.

@Test
public void run_shouldSayIfTimeoutWasBeforeSendingMessage() throws Exception {
    final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
    doThrow(new AttributeQueryTimeoutException()).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().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
}
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)

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