Search in sources :

Example 1 with SamlMessageDto

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);
}
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 2 with SamlMessageDto

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);
    }
}
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 3 with SamlMessageDto

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.");
}
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) Test(org.junit.jupiter.api.Test)

Example 4 with SamlMessageDto

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);
}
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 5 with SamlMessageDto

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());
}
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.jupiter.api.Test)

Aggregations

SamlMessageDto (uk.gov.ida.hub.samlsoapproxy.contract.SamlMessageDto)18 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)11 MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.builders.MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto)9 MatchingServiceConfigEntityDataDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceConfigEntityDataDto)9 Test (org.junit.jupiter.api.Test)5 Test (org.junit.Test)4 ApplicationException (uk.gov.ida.exceptions.ApplicationException)4 MatchingServiceHealthCheckerResponseDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerResponseDto)4 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)3 Element (org.w3c.dom.Element)2 MatchingServiceHealthCheckerRequestDto (uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto)2 AttributeQueryBuilder.anAttributeQuery (uk.gov.ida.saml.core.test.builders.AttributeQueryBuilder.anAttributeQuery)2 RequestAndResponse (httpstub.RequestAndResponse)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SAXException (org.xml.sax.SAXException)1 MatchingServiceDetails (uk.gov.ida.integrationtest.hub.samlsoapproxy.apprule.support.MatchingServiceDetails)1