use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class HealthCheckEventLoggerTest method shouldLogToEventSinkIfTheExceptionIsUnaudited.
@Test
public void shouldLogToEventSinkIfTheExceptionIsUnaudited() {
URI uri = URI.create("uri-geller");
ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID(), uri);
Map<EventDetailsKey, String> details = Map.of(downstream_uri, unauditedException.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), message, unauditedException.getMessage());
EventSinkHubEvent event = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details);
eventLogger.logException(unauditedException, "test error message");
ArgumentCaptor<EventSinkHubEvent> eventSinkCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
ArgumentCaptor<EventSinkHubEvent> eventEmitterCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
verify(eventSinkProxy, times(1)).logHubEvent(eventSinkCaptor.capture());
verify(eventEmitter, times(1)).record(eventEmitterCaptor.capture());
assertThat(event).isEqualToComparingOnlyGivenFields(eventSinkCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
assertThat(event).isEqualToComparingOnlyGivenFields(eventEmitterCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class EventSinkHttpProxy method logHubEvent.
@Override
@Timed
public void logHubEvent(Event eventSinkHubEvent) {
String path = CommonUrls.HUB_SUPPORT_EVENT_SINK_RESOURCE;
URI uri = UriBuilder.fromUri(eventSinkUri).path(path).build();
try {
jsonClient.post(eventSinkHubEvent, uri);
LOG.info("Sent to Event Sink " + eventSinkHubEvent.getEventType() + " hub event to event-sink on " + uri);
} catch (ApplicationException e) {
LOG.error("Failed to send event to event sink.", e);
LOG.warn("failed event: {}", getEventAsString(eventSinkHubEvent));
}
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class MatchingServiceHealthChecker method isHealthyResponse.
private boolean isHealthyResponse(final MatchingServiceHealthCheckResponseDto responseDto, final URI matchingServiceUri) {
if (!responseDto.getResponse().isPresent()) {
return false;
}
String exceptionMessage = format("Matching service health check failed for URI {0}", matchingServiceUri);
try {
// Saml-engine expects the saml to be base64 encoded
final SamlMessageDto samlMessageDto = new SamlMessageDto(Base64.encodeAsString(responseDto.getResponse().get()));
final MatchingServiceHealthCheckerResponseDto responseFromMatchingService = samlEngineProxy.translateHealthcheckMatchingServiceResponse(samlMessageDto);
if (responseFromMatchingService.getStatus() != MatchingServiceIdaStatus.Healthy) {
return false;
}
} catch (ApplicationException e) {
eventLogger.logException(e, exceptionMessage);
return false;
} catch (RuntimeException e) {
LOG.warn(format("Matching service health check failed for URI {0}", matchingServiceUri), e);
return false;
}
return true;
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class SamlEngineExceptionMapperTest method shouldPassthroughErrorIdAndExceptionType.
@Test
public void shouldPassthroughErrorIdAndExceptionType() throws Exception {
UUID errorId = UUID.randomUUID();
final ExceptionType exceptionType = ExceptionType.IDA_SOAP;
ApplicationException applicationException = createUnauditedException(exceptionType, errorId);
final Response response = samlEngineExceptionMapper.toResponse(applicationException);
assertThat(response.hasEntity()).isTrue();
ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
assertThat(errorStatusDto.getErrorId()).isEqualTo(errorId);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(exceptionType);
checkLogLevel(applicationException.getExceptionType().getLevel());
}
use of uk.gov.ida.exceptions.ApplicationException in project verify-hub by alphagov.
the class PolicyApplicationExceptionMapperTest method toResponse_shouldAuditErrorIfUnaudited.
@Test
public void toResponse_shouldAuditErrorIfUnaudited() {
final SessionId sessionId = aSessionId().build();
final UUID errorId = UUID.randomUUID();
when(servletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn(sessionId.toString());
ApplicationException exception = createUnauditedException(ExceptionType.IDP_DISABLED, errorId);
mapper.toResponse(exception);
// detailsCaptor.capture());
verify(eventLogger).logErrorEvent(eq(errorId), eq(sessionId), eq("Exception of type [IDP_DISABLED] "), eq("uri-not-present"));
}
Aggregations