Search in sources :

Example 21 with ApplicationException

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

the class MatchingServiceHealthCheckerTest method shouldLogExceptionsWhenAFailureOccursInGeneratingHealthCheckRequest.

@Test
public void shouldLogExceptionsWhenAFailureOccursInGeneratingHealthCheckRequest() {
    ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID());
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenThrow(unauditedException);
    matchingServiceHealthChecker.performHealthCheck(aMatchingServiceConfigEntityDataDto().build());
    verify(eventLogger).logException(unauditedException, "Saml-engine was unable to generate saml to send to MSA: uk.gov.ida.exceptions.ApplicationException: Exception of type [INVALID_SAML] ");
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) Test(org.junit.jupiter.api.Test)

Example 22 with ApplicationException

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

the class MatchingServiceHealthCheckerTest method shouldLogExceptionsWhenAFailureOccursInTranslatingHealthCheckRequest.

@Test
public void shouldLogExceptionsWhenAFailureOccursInTranslatingHealthCheckRequest() {
    String uri = "http://random";
    ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID());
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
    when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenThrow(unauditedException);
    MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().withUri(uri).build();
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of("<saml/>")));
    matchingServiceHealthChecker.performHealthCheck(matchingServiceConfigEntityDataDto);
    verify(eventLogger).logException(unauditedException, MessageFormat.format("Matching service health check failed for URI {0}", uri));
}
Also used : MatchingServiceConfigEntityDataDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceConfigEntityDataDto) MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto(uk.gov.ida.hub.samlsoapproxy.builders.MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto) SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) ApplicationException(uk.gov.ida.exceptions.ApplicationException) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.jupiter.api.Test)

Example 23 with ApplicationException

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

the class HealthCheckSoapRequestClientTest method makePost_shouldEnsureResponseInputStreamIsClosedWhenResponseCodeIsNot200.

@Test
public void makePost_shouldEnsureResponseInputStreamIsClosedWhenResponseCodeIsNot200() throws URISyntaxException {
    when(response.getStatus()).thenReturn(502);
    URI matchingServiceUri = new URI("http://heyyeyaaeyaaaeyaeyaa.com/abc1");
    try {
        healthCheckSoapRequestClient.makeSoapRequestForHealthCheck(null, matchingServiceUri);
        fail("Exception should have been thrown");
    } catch (ApplicationException e) {
        verify(response).close();
    }
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 24 with ApplicationException

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

the class ExceptionAuditorTest method shouldAuditUnauditedException.

@Test
public void shouldAuditUnauditedException() {
    DateTime expectedTimestamp = DateTime.now();
    DateTimeFreezer.freezeTime(expectedTimestamp);
    final UUID errorId = UUID.randomUUID();
    ApplicationException exception = createUnauditedException(ExceptionType.DUPLICATE_SESSION, errorId, URI.create("/some-uri"));
    exceptionAuditor.auditException(exception, Optional.of(SESSION_ID));
    ArgumentCaptor<EventDetails> argumentCaptor = ArgumentCaptor.forClass(EventDetails.class);
    verify(eventSinkMessageSender).audit(eq(exception), eq(errorId), eq(SESSION_ID), argumentCaptor.capture());
    final EventDetails event = argumentCaptor.getValue();
    assertThat(event.getKey()).isEqualTo(downstream_uri);
    assertThat(event.getValue()).isEqualTo(exception.getUri().get().toASCIIString());
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) EventDetails(uk.gov.ida.hub.shared.eventsink.EventDetails) Test(org.junit.jupiter.api.Test)

Example 25 with ApplicationException

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

the class ExceptionAuditorTest method shouldAuditWithNoSessionContextIfSessionIdIsNotPresent.

@Test
public void shouldAuditWithNoSessionContextIfSessionIdIsNotPresent() {
    final UUID errorId = UUID.randomUUID();
    ApplicationException exception = createUnauditedException(ExceptionType.DUPLICATE_SESSION, errorId, URI.create("/some-uri"));
    exceptionAuditor.auditException(exception, Optional.empty());
    verify(eventSinkMessageSender).audit(eq(exception), eq(errorId), eq(SessionId.NO_SESSION_CONTEXT_IN_ERROR), any(EventDetails.class));
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) UUID(java.util.UUID) EventDetails(uk.gov.ida.hub.shared.eventsink.EventDetails) 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