Search in sources :

Example 1 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException 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 2 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldLogToAudit_ButShouldNotNotifySamlEngine_RequestHasTimedOut_AndWhenMessageFromSamlEngineValidationFailsWithUnexpectedException.

@Test
public void run_shouldLogToAudit_ButShouldNotNotifySamlEngine_RequestHasTimedOut_AndWhenMessageFromSamlEngineValidationFailsWithUnexpectedException() throws Exception {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid XML.", new RuntimeException("test exception")));
    doNothing().doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    // One for the timeout, one for the message error
    verify(eventSinkProxy, times(2)).logHubEvent(isA(EventSinkHubEvent.class));
    verify(eventEmitter, times(2)).record(isA(EventSinkHubEvent.class));
    verify(hubMatchingServiceResponseReceiverProxy, never()).notifyHubOfMatchingServiceRequestFailure(sessionId);
}
Also used : InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 3 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldEvaluateTimeoutBeforeSendingRequest.

@Test
public void run_shouldEvaluateTimeoutBeforeSendingRequest() {
    doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    // This represents the queue being full/slow - so don't make matters worse by doing slow work that's not needed.
    attributeQueryRequestRunnable.run();
    verify(executeAttributeQueryRequest, never()).execute(any(SessionId.class), any(AttributeQueryContainerDto.class));
    verify(eventSinkProxy, times(1)).logHubEvent(isA(EventSinkHubEvent.class));
    verify(eventEmitter, times(1)).record(isA(EventSinkHubEvent.class));
}
Also used : AttributeQueryContainerDto(uk.gov.ida.hub.samlsoapproxy.domain.AttributeQueryContainerDto) AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto(uk.gov.ida.hub.samlsoapproxy.builders.AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) SessionId(uk.gov.ida.common.SessionId) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 4 with AttributeQueryTimeoutException

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

Example 5 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldNotSendResponse_IfAttributeQueryHasTimedOut_AfterSendingMessage.

@Test
public void run_shouldNotSendResponse_IfAttributeQueryHasTimedOut_AfterSendingMessage() throws Exception {
    final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
    doNothing().doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    verify(executeAttributeQueryRequest).execute(sessionId, attributeQueryContainerDto);
    verify(hubMatchingServiceResponseReceiverProxy, never()).notifyHubOfAResponseFromMatchingService(any(SessionId.class), any(String.class));
    verify(eventSinkProxy, times(1)).logHubEvent(isA(EventSinkHubEvent.class));
    verify(eventEmitter, times(1)).record(isA(EventSinkHubEvent.class));
}
Also used : Element(org.w3c.dom.Element) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) SessionId(uk.gov.ida.common.SessionId) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Aggregations

AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)8 Test (org.junit.Test)6 EventSinkHubEvent (uk.gov.ida.eventsink.EventSinkHubEvent)6 Element (org.w3c.dom.Element)4 SessionId (uk.gov.ida.common.SessionId)2 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto (uk.gov.ida.hub.samlsoapproxy.builders.AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto)1 AttributeQueryContainerDto (uk.gov.ida.hub.samlsoapproxy.domain.AttributeQueryContainerDto)1 InvalidSamlRequestInAttributeQueryException (uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException)1