use of uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldReturnADtoWhenResponseIs_Created.
@Test
public void shouldReturnADtoWhenResponseIs_Created() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.CREATED;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(aValidMatchResponseFromMatchingService(requestId, status).getBytes()), TEST_RP);
Response clientResponse = postToSamlEngine(samlResponseContainerDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.UserAccountCreated.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isTrue();
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().get()).isEqualTo(LevelOfAssurance.LEVEL_2);
assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion().isPresent()).isTrue();
}
use of uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoWhenResponseIs_Nonsense.
@Test
public void shouldNotReturnADtoWhenResponseIs_Nonsense() {
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(StringUtils.rightPad("test", 2000, "x"), TEST_RP);
Response clientResponse = postToSamlEngine(samlResponseContainerDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldReturnADtoWhenResponseIs_RequesterError.
@Test
public void shouldReturnADtoWhenResponseIs_RequesterError() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = StatusCode.NO_AUTHN_CONTEXT;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(REQUESTER).build()).build();
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(aValidNoMatchResponseFromMatchingService(requestId, status, TEST_RP_MS).getBytes()), TEST_RP);
Response clientResponse = postToSamlEngine(samlResponseContainerDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.RequesterError.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance()).isNotPresent();
assertThat(inboundResponseFromMatchingServiceDto.getEncryptedMatchingServiceAssertion()).isNotPresent();
}
use of uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match.
@Test
public void shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.MATCH;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(aValidMatchResponseFromMatchingServiceWithMissingData(requestId, status, TEST_RP_MS).getBytes()), TEST_RP);
Response clientResponse = postToSamlEngine(samlResponseContainerDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoWhenResponseIs_bad.
@Test
public void shouldNotReturnADtoWhenResponseIs_bad() throws Exception {
final String requestId = "requestId";
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(anInvalidAMatchingServiceSamlResponse(requestId).getBytes()), TEST_RP);
Response clientResponse = postToSamlEngine(samlResponseContainerDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Aggregations