Search in sources :

Example 21 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method toResponse_shouldReturnAuditedErrorResponseWhenExceptionHasBeenAuditedAlready.

@Test
public void toResponse_shouldReturnAuditedErrorResponseWhenExceptionHasBeenAuditedAlready() throws Exception {
    ApplicationException applicationException = createAuditedException(ExceptionType.INVALID_SAML, UUID.randomUUID());
    final Response response = samlEngineExceptionMapper.toResponse(applicationException);
    final ErrorStatusDto entity = (ErrorStatusDto) response.getEntity();
    assertThat(entity.isAudited()).isTrue();
    checkLogLevel(applicationException.getExceptionType().getLevel());
}
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 22 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method shouldCreateUnauditedErrorResponse.

@Test
public void shouldCreateUnauditedErrorResponse() throws Exception {
    final SamlTransformationErrorException exception = new SamlTransformationErrorException("error", new RuntimeException(), Level.DEBUG);
    Response response = samlEngineExceptionMapper.toResponse(exception);
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(responseEntity.isAudited()).isFalse();
    checkLogLevel(exception.getLogLevel());
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) Test(org.junit.jupiter.api.Test)

Example 23 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method toResponse_shouldReturnUnauditedErrorResponseWhenExceptionHasNotBeenAudited.

@Test
public void toResponse_shouldReturnUnauditedErrorResponseWhenExceptionHasNotBeenAudited() throws Exception {
    ApplicationException applicationException = createUnauditedExceptionThatShouldNotBeAudited();
    final Response response = samlEngineExceptionMapper.toResponse(applicationException);
    final ErrorStatusDto entity = (ErrorStatusDto) response.getEntity();
    assertThat(entity.isAudited()).isEqualTo(false);
    checkLogLevel(applicationException.getExceptionType().getLevel());
}
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 24 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method shouldHandleSamlFailedToDecryptErrorExceptionCorrectly.

@Test
public void shouldHandleSamlFailedToDecryptErrorExceptionCorrectly() throws Exception {
    SamlTransformationErrorException exception = new SamlFailedToDecryptException("error", new RuntimeException(), Level.DEBUG);
    final Response response = samlEngineExceptionMapper.toResponse(exception);
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(responseEntity.isAudited()).isFalse();
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_FAILED_TO_DECRYPT);
    checkLogLevel(exception.getLogLevel());
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) SamlFailedToDecryptException(uk.gov.ida.saml.security.exception.SamlFailedToDecryptException) Test(org.junit.jupiter.api.Test)

Example 25 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method shouldHandleSamlContextExceptionCorrectly.

@Test
public void shouldHandleSamlContextExceptionCorrectly() throws Exception {
    final SamlContextException exception = new SamlContextException(UUID.randomUUID().toString(), "entityId", new SamlTransformationErrorException("error", Level.ERROR));
    Response response = samlEngineExceptionMapper.toResponse(exception);
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(responseEntity.isAudited()).isFalse();
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
    checkLogLevel(exception.getLogLevel());
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) 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