use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto 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.hub.samlsoapproxy.contract.SamlMessageDto 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");
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto 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());
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto 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");
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckerTest method handle_shouldReturnFailureWithMessageFromMatchingServiceThatCannotBeParsed.
@Test
public void handle_shouldReturnFailureWithMessageFromMatchingServiceThatCannotBeParsed() throws Exception {
MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("samSamSaml"));
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("Unable to convert saml request to XML element: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.");
}
Aggregations