Search in sources :

Example 1 with MatchingServiceHealthCheckResponseDto

use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.

the class MatchingServiceHealthChecker method performHealthCheck.

public MatchingServiceHealthCheckResult performHealthCheck(final MatchingServiceConfigEntityDataDto configEntity) {
    MatchingServiceHealthCheckerRequestDto matchingServiceHealthCheckerRequestDto = new MatchingServiceHealthCheckerRequestDto(configEntity.getTransactionEntityId(), configEntity.getEntityId());
    MatchingServiceHealthCheckResponseDto response;
    try {
        SamlMessageDto samlMessageDto = samlEngineProxy.generateHealthcheckAttributeQuery(matchingServiceHealthCheckerRequestDto);
        final Element matchingServiceHealthCheckRequest = XmlUtils.convertToElement(samlMessageDto.getSamlMessage());
        validateRequestSignature(matchingServiceHealthCheckRequest);
        response = matchingServiceHealthCheckClient.sendHealthCheckRequest(matchingServiceHealthCheckRequest, configEntity.getUri());
        if (response.getResponse().isPresent()) {
            final Optional<String> msaVersion = extractVersionFromResponseId(response.getResponse().get());
            if (msaVersion.isPresent()) {
                // if we have conflicting return values, lets trust the one from the ID a little bit more
                response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
                if (!response.getVersionNumber().get().equals(msaVersion.get())) {
                    response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
                    LOG.warn("MSA healthcheck response with two version numbers: {0} & {1}", response.getVersionNumber().get(), msaVersion.get());
                }
            }
        }
    } catch (ApplicationException e) {
        final String message = format("Saml-engine was unable to generate saml to send to MSA: {0}", e);
        eventLogger.logException(e, message);
        return logAndCreateUnhealthyResponse(configEntity, message);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        final String message = format("Unable to convert saml request to XML element: {0}", e);
        return logAndCreateUnhealthyResponse(configEntity, message);
    }
    if (isHealthyResponse(response, configEntity.getUri())) {
        return healthy(generateHealthCheckDescription("responded successfully", configEntity.getUri(), response.getVersionNumber(), configEntity.isOnboarding()));
    } else {
        return unhealthy(generateHealthCheckFailureDescription(response, configEntity.getUri(), configEntity.isOnboarding()));
    }
}
Also used : MatchingServiceHealthCheckerRequestDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto) SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) ApplicationException(uk.gov.ida.exceptions.ApplicationException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) SAXException(org.xml.sax.SAXException)

Example 2 with MatchingServiceHealthCheckResponseDto

use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.

the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnOptionalAbsentIfNoResponseReceived.

@Test
public void sendHealthCheckRequest_shouldReturnOptionalAbsentIfNoResponseReceived() {
    when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenThrow(ApplicationException.createUnauditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID()));
    final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
    assertThat(matchingServiceHealthCheckResponseDto.getResponse()).isEqualTo(Optional.<String>absent());
}
Also used : MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.Test)

Example 3 with MatchingServiceHealthCheckResponseDto

use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.

the class MatchingServiceHealthCheckerTest method prepareForResponse.

private void prepareForResponse(MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto, MatchingServiceIdaStatus status, Optional<String> msaVersion) {
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
    final MatchingServiceHealthCheckerResponseDto inboundResponseFromMatchingServiceDto = anInboundResponseFromMatchingServiceDto().withStatus(status).build();
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of("<saml/>"), msaVersion));
    when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenReturn(inboundResponseFromMatchingServiceDto);
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto) MatchingServiceHealthCheckerResponseDto(uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)

Example 4 with MatchingServiceHealthCheckResponseDto

use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.

the class MatchingServiceHealthCheckClient method sendHealthCheckRequest.

public MatchingServiceHealthCheckResponseDto sendHealthCheckRequest(final Element matchingServiceHealthCheckRequest, final URI matchingServiceUri) {
    // Use a custom timer so that we get separate metrics for each matching service
    final String scope = matchingServiceUri.toString().replace(':', '_').replace('/', '_');
    final Timer timer = metricsRegistry.timer(MetricRegistry.name(MatchingServiceHealthCheckClient.class, "sendHealthCheckRequest", scope));
    final Timer.Context context = timer.time();
    HealthCheckResponse healthCheckResponse;
    try {
        healthCheckResponse = client.makeSoapRequestForHealthCheck(matchingServiceHealthCheckRequest, matchingServiceUri);
    } catch (ApplicationException ex) {
        final String errorMessage = MessageFormat.format("Failed to complete matching service health check to {0}.", matchingServiceUri);
        LOG.warn(errorMessage, ex);
        return new MatchingServiceHealthCheckResponseDto(Optional.<String>absent(), Optional.<String>absent());
    } finally {
        context.stop();
    }
    return new MatchingServiceHealthCheckResponseDto(Optional.of(XmlUtils.writeToString(healthCheckResponse.getResponseElement())), healthCheckResponse.getVersionNumber());
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) Timer(com.codahale.metrics.Timer) HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)

Example 5 with MatchingServiceHealthCheckResponseDto

use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.

the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnTrueIfResponseReceived.

@Test
public void sendHealthCheckRequest_shouldReturnTrueIfResponseReceived() {
    HealthCheckResponse healthCheckResponse = aHealthCheckResponse().withElement(healthCheckResponseElement).build();
    when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenReturn(healthCheckResponse);
    final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
    assertThat(matchingServiceHealthCheckResponseDto.getResponse()).isEqualTo(Optional.of(XmlUtils.writeToString(healthCheckResponseElement)));
}
Also used : HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) HealthCheckResponseBuilder.aHealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.builders.HealthCheckResponseBuilder.aHealthCheckResponse) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.Test)

Aggregations

MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)11 Test (org.junit.Test)8 SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)7 MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.builders.MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto)5 MatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceConfigEntityDataDto)5 ApplicationException (uk.gov.ida.exceptions.ApplicationException)3 HealthCheckResponse (uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse)3 HealthCheckResponseBuilder.aHealthCheckResponse (uk.gov.ida.hub.samlsoapproxy.builders.HealthCheckResponseBuilder.aHealthCheckResponse)2 Timer (com.codahale.metrics.Timer)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1 MatchingServiceHealthCheckerRequestDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto)1 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)1