Search in sources :

Example 61 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class IdpAuthnResponseTranslatorResourceTest method shouldThrowExceptionIfResponseContainsPartsWithMismatchedPids.

@Test
public void shouldThrowExceptionIfResponseContainsPartsWithMismatchedPids() throws Exception {
    final String ipAddressAsSeenByIdp = "256.256.256.256";
    final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilder(STUB_IDP_ONE, ipAddressAsSeenByIdp, "some-pid", "some-different-pid").withDestination("http://localhost" + Urls.FrontendUrls.SAML2_SSO_RESPONSE_ENDPOINT).build();
    String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
    SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.jupiter.api.Test)

Example 62 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class PolicyApplicationExceptionMapperTest method toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited.

@Test
public void toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited() {
    ApplicationException exception = createUnauditedExceptionThatShouldNotBeAudited();
    final Response response = mapper.toResponse(exception);
    final ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatus.isAudited()).isEqualTo(false);
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(uk.gov.ida.exceptions.ApplicationException) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 63 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class PolicyApplicationExceptionMapperTest method toResponse_shouldReturnAnAuditedErrorStatusIfExceptionIsAudited.

@Test
public void toResponse_shouldReturnAnAuditedErrorStatusIfExceptionIsAudited() {
    ApplicationException exception = createAuditedException(ExceptionType.IDP_DISABLED, UUID.randomUUID());
    final Response response = mapper.toResponse(exception);
    final ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatus.isAudited()).isEqualTo(true);
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(uk.gov.ida.exceptions.ApplicationException) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 64 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class SessionTimeoutExceptionMapperTest method toResponse_shouldReturnAuditedErrorStatus.

@Test
public void toResponse_shouldReturnAuditedErrorStatus() {
    SessionTimeoutExceptionMapper mapper = new SessionTimeoutExceptionMapper(hubEventLogger);
    mapper.setHttpServletRequest(servletRequest);
    SessionTimeoutException exception = new SessionTimeoutException("Timeout exception", aSessionId().build(), "some entity id", DateTime.now().minusMinutes(10), "some request id");
    final Response response = mapper.toResponse(exception);
    assertThat(response.getEntity()).isNotNull();
    assertThat(response.getStatus()).isEqualTo(400);
    final ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(true);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.SESSION_TIMEOUT);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 65 with ErrorStatusDto

use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.

the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldThrowExceptionAuthnResponseIsReplayed.

@Test
public void handleResponseFromIdp_shouldThrowExceptionAuthnResponseIsReplayed() throws Exception {
    SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto();
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) Test(org.junit.jupiter.api.Test)

Aggregations

ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)78 Response (javax.ws.rs.core.Response)69 Test (org.junit.jupiter.api.Test)66 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto)17 SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto (uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto)17 UUID (java.util.UUID)13 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)7 ApplicationException (uk.gov.ida.exceptions.ApplicationException)6 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)6 SamlResponseContainerDto (uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 Status (org.opensaml.saml.saml2.core.Status)3 SamlRequestWithAuthnRequestInformationDto (uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto)3 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)3 SamlDuplicateRequestIdException (uk.gov.ida.saml.hub.exception.SamlDuplicateRequestIdException)3 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 ExceptionType (uk.gov.ida.common.ExceptionType)2 IdpSelected (uk.gov.ida.hub.policy.domain.IdpSelected)2 SamlRequestTooOldException (uk.gov.ida.saml.hub.exception.SamlRequestTooOldException)2