Search in sources :

Example 6 with MatchingServiceHealthCheckResponseDto

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

the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnSuccessResponseWithVersionNumber.

@Test
public void sendHealthCheckRequest_shouldReturnSuccessResponseWithVersionNumber() {
    String expectedVersion = "someVersion";
    HealthCheckResponse responseMessageThatHasAVersion = aHealthCheckResponse().withElement(healthCheckResponseElement).withVersionNumber(expectedVersion).build();
    when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenReturn(responseMessageThatHasAVersion);
    final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
    assertThat(matchingServiceHealthCheckResponseDto.getVersionNumber()).isEqualTo(Optional.of(expectedVersion));
}
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)

Example 7 with MatchingServiceHealthCheckResponseDto

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

the class MatchingServiceHealthCheckerTest method shouldLogExceptionsWhenAFailureOccursInTranslatingHealthCheckRequest.

@Test
public void shouldLogExceptionsWhenAFailureOccursInTranslatingHealthCheckRequest() throws Exception {
    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/>"), Optional.of("version1")));
    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.Test)

Example 8 with MatchingServiceHealthCheckResponseDto

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

the class MatchingServiceHealthCheckerTest method handle_shouldReturnReportWhenHubFailsToPerformHealthCheck.

@Test
public void handle_shouldReturnReportWhenHubFailsToPerformHealthCheck() {
    final String expectedFailureDetails = "no response";
    MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.<String>absent(), Optional.<String>absent()));
    MatchingServiceHealthCheckResult result = matchingServiceHealthChecker.performHealthCheck(matchingServiceConfigEntityDataDto);
    assertThat(result.isHealthy()).isFalse();
    assertThat(result.getDetails()).isEqualToComparingOnlyGivenFields(aMatchingServiceHealthCheckDetails().withDetails(expectedFailureDetails).build(), "details");
}
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) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.Test)

Example 9 with MatchingServiceHealthCheckResponseDto

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

the class MatchingServiceHealthCheckerTest method handle_shouldBase64EncodeSamlToBeSentToSamlEngine.

@Test
public void handle_shouldBase64EncodeSamlToBeSentToSamlEngine() throws Exception {
    final String saml = "<samlsamlsamlsamlsamlsamlsamlsamlsaml/>";
    MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
    prepareForHealthyResponse(matchingServiceConfigEntityDataDto, Optional.<String>absent());
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of(saml), Optional.of("101010")));
    matchingServiceHealthChecker.performHealthCheck(aMatchingServiceConfigEntityDataDto().build());
    ArgumentCaptor<SamlMessageDto> argumentCaptor = ArgumentCaptor.forClass(SamlMessageDto.class);
    verify(samlEngineProxy, times(1)).translateHealthcheckMatchingServiceResponse(argumentCaptor.capture());
    assertThat(Base64.encodeAsString(saml)).isEqualTo(argumentCaptor.getValue().getSamlMessage());
}
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) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.Test)

Example 10 with MatchingServiceHealthCheckResponseDto

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

the class MatchingServiceHealthCheckerTest method handle_shouldReturnFailureWithMessageForMatchingServiceThatCannotBeTransformed.

@Test
public void handle_shouldReturnFailureWithMessageForMatchingServiceThatCannotBeTransformed() throws Exception {
    MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
    when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
    when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of("<saml/>"), Optional.<String>absent()));
    when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenThrow(ApplicationException.createAuditedException(ExceptionType.INVALID_SAML, UUID.randomUUID()));
    MatchingServiceHealthCheckResult result = matchingServiceHealthChecker.performHealthCheck(matchingServiceConfigEntityDataDto);
    assertThat(result.isHealthy()).isEqualTo(false);
    assertThat(result.getDetails().getDetails()).isEqualTo("responded with non-healthy status");
}
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) 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