use of uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException in project verify-hub by alphagov.
the class ExecuteAttributeQueryRequest method convertToElementAndValidate.
private Element convertToElementAndValidate(AttributeQueryContainerDto attributeQueryContainerDto) {
try {
Element matchingServiceRequest;
matchingServiceRequest = XmlUtils.convertToElement(attributeQueryContainerDto.getSamlRequest());
validateRequestSignature(matchingServiceRequest, attributeQueryContainerDto.getMatchingServiceUri());
return matchingServiceRequest;
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid XML.", e);
} catch (SamlTransformationErrorException e) {
throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid Saml", e);
}
}
use of uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException 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.InvalidSamlRequestInAttributeQueryException 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");
}
Aggregations