Search in sources :

Example 11 with ApplicationException

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");
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 12 with ApplicationException

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));
    }
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 13 with ApplicationException

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;
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) ApplicationException(uk.gov.ida.exceptions.ApplicationException) MatchingServiceHealthCheckerResponseDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)

Example 14 with ApplicationException

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());
}
Also used : Response(javax.ws.rs.core.Response) ExceptionType(uk.gov.ida.common.ExceptionType) ApplicationException(uk.gov.ida.exceptions.ApplicationException) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 15 with ApplicationException

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"));
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) UUID(java.util.UUID) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationException (uk.gov.ida.exceptions.ApplicationException)27 Test (org.junit.jupiter.api.Test)20 UUID (java.util.UUID)8 Response (javax.ws.rs.core.Response)7 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)6 URI (java.net.URI)4 SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)4 EventDetails (uk.gov.ida.hub.shared.eventsink.EventDetails)4 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)3 SessionId (uk.gov.ida.common.SessionId)2 ApplicationException.createAuditedException (uk.gov.ida.exceptions.ApplicationException.createAuditedException)2 ApplicationException.createUnauditedException (uk.gov.ida.exceptions.ApplicationException.createUnauditedException)2 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)2 Timer (com.codahale.metrics.Timer)1 Timed (com.codahale.metrics.annotation.Timed)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DateTime (org.joda.time.DateTime)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1