use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto 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);
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto 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 responseDto;
try {
SamlMessageDto samlMessageDto = samlEngineProxy.generateHealthcheckAttributeQuery(matchingServiceHealthCheckerRequestDto);
final Element matchingServiceHealthCheckRequest = XmlUtils.convertToElement(samlMessageDto.getSamlMessage());
validateRequestSignature(matchingServiceHealthCheckRequest);
responseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(matchingServiceHealthCheckRequest, configEntity.getUri());
return buildMatchingServiceHealthCheckResult(configEntity, responseDto.getResponse());
} 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);
}
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckerTest method shouldReturnFailureWithMessageFromMatchingServiceThatCannotBeParsed.
@Test
public void shouldReturnFailureWithMessageFromMatchingServiceThatCannotBeParsed() {
MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("samSamSaml"));
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.");
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckerTest method prepareForResponse.
private void prepareForResponse(MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto, MatchingServiceIdaStatus status) {
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/>")));
when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenReturn(inboundResponseFromMatchingServiceDto);
}
use of uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckerTest method shouldBase64EncodeSamlToBeSentToSamlEngine.
@Test
public void shouldBase64EncodeSamlToBeSentToSamlEngine() {
final String saml = "<samlsamlsamlsamlsamlsamlsamlsamlsaml/>";
MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().build();
prepareForHealthyResponse(matchingServiceConfigEntityDataDto);
when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of(saml)));
matchingServiceHealthChecker.performHealthCheck(aMatchingServiceConfigEntityDataDto().build());
ArgumentCaptor<SamlMessageDto> argumentCaptor = ArgumentCaptor.forClass(SamlMessageDto.class);
verify(samlEngineProxy, times(1)).translateHealthcheckMatchingServiceResponse(argumentCaptor.capture());
assertThat(Base64.getEncoder().encodeToString(saml.getBytes())).isEqualTo(argumentCaptor.getValue().getSamlMessage());
}
Aggregations