use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldThrowExceptionForSecondIdpIfTwoIdpsSubmitAnAuthnStatementAssertionWithTheSameId.
@Test
public void handleResponseFromIdp_shouldThrowExceptionForSecondIdpIfTwoIdpsSubmitAnAuthnStatementAssertionWithTheSameId() throws Exception {
String authnStatementAssertionId = "authnStatementAssertionId" + UUID.randomUUID().toString();
String mdsStatementAssertionId = "mdsStatementAssertionId" + UUID.randomUUID().toString();
SamlAuthnResponseTranslatorDto samlResponseDto_1 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_TWO, authnStatementAssertionId, mdsStatementAssertionId + "-1");
SamlAuthnResponseTranslatorDto samlResponseDto_2 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_THREE, authnStatementAssertionId, mdsStatementAssertionId + "-2");
Response clientResponse = postToSamlEngine(samlResponseDto_1);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
clientResponse = postToSamlEngine(samlResponseDto_2);
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.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldThrowExceptionIfmdsAssertionIsReplayedInResponseFromIdp.
@Test
public void handleResponseFromIdp_shouldThrowExceptionIfmdsAssertionIsReplayedInResponseFromIdp() throws Exception {
String authnStatementAssertionId = "authnStatementAssertionId" + UUID.randomUUID().toString();
String mdsStatementAssertionId = "mdsStatementAssertionId" + UUID.randomUUID().toString();
SamlAuthnResponseTranslatorDto samlResponseDto_1 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_ONE, authnStatementAssertionId + "-1", mdsStatementAssertionId);
SamlAuthnResponseTranslatorDto samlResponseDto_2 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_ONE, authnStatementAssertionId + "-2", mdsStatementAssertionId);
Response clientResponse = postToSamlEngine(samlResponseDto_1);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
clientResponse = postToSamlEngine(samlResponseDto_2);
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.common.ErrorStatusDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldReturnADtoWhenResponseIs_TooOld.
@Test
public void shouldReturnADtoWhenResponseIs_TooOld() 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(aValidMatchResponseFromMatchingService(requestId, status, DateTime.now().minusDays(1)).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.common.ErrorStatusDto in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoResponse_WhenBadlySigned_NoMatch.
@Test
public void shouldNotReturnADtoResponse_WhenBadlySigned_NoMatch() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.NO_MATCH;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(RESPONDER).build()).build();
final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(Base64.getEncoder().encodeToString(aValidNoMatchResponseFromMatchingServiceisBadlySigned(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.common.ErrorStatusDto in project verify-hub by alphagov.
the class RpAuthnResponseGeneratorResourceTest method shouldReturnAnErrorResponseGivenBadInput.
@Test
public void shouldReturnAnErrorResponseGivenBadInput() throws JsonProcessingException {
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAssertionConsumerServiceUri(null).build();
configStub.signResponsesAndUseSamlStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
Response rpAuthnResponse = client.postTargetMain(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE, responseFromHubDto);
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = rpAuthnResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
Aggregations