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.");
}
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);
}
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));
}
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.");
}
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));
}
Aggregations