Search in sources :

Example 41 with ErrorStatusDto

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

the class IdaJsonProcessingExceptionMapperTest method toResponse_shouldReturnBadRequestAndErrorStatusDtoWhenErrorDeemedToBeFromClient.

@Test
public void toResponse_shouldReturnBadRequestAndErrorStatusDtoWhenErrorDeemedToBeFromClient() {
    String clientErrorMessage = "This is a client error";
    Response response = mapper.toResponse(new JsonMappingException(null, clientErrorMessage));
    ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(errorStatus.isAudited()).isEqualTo(false);
    assertThat(errorStatus.getClientMessage()).isEqualTo(clientErrorMessage);
    assertThat(errorStatus.getExceptionType()).isEqualTo(ExceptionType.JSON_PARSING);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Test(org.junit.jupiter.api.Test)

Example 42 with ErrorStatusDto

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

the class SessionAlreadyExistingExceptionMapperTest method toResponse_shouldLogToAudit.

@Test
public void toResponse_shouldLogToAudit() {
    SessionAlreadyExistingException exception = new SessionAlreadyExistingException(MESSAGE, SESSION_ID);
    final Response response = mapper.toResponse(exception);
    verify(hubEventLogger).logErrorEvent(any(UUID.class), eq(SESSION_ID), eq(MESSAGE));
    final ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(true);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.DUPLICATE_SESSION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 43 with ErrorStatusDto

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

the class StateProcessingValidationExceptionMapperTest method toResponse_shouldReturnUnauditedErrorStatus.

@Test
public void toResponse_shouldReturnUnauditedErrorStatus() {
    when(servletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn(SESSION_ID);
    String errorMessage = "error message";
    StateProcessingValidationException exception = new StateProcessingValidationException(errorMessage, Level.ERROR);
    final Response response = mapper.toResponse(exception);
    verify(eventLogger).logErrorEvent(any(UUID.class), eq(aSessionId().with(SESSION_ID).build()), eq(errorMessage));
    assertThat(response.getEntity()).isNotNull();
    ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(false);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.STATE_PROCESSING_VALIDATION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 44 with ErrorStatusDto

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

the class IdpDisabledExceptionMapperTest method toResponse_shouldReturnErrorResponseWithAuditingTrue.

@Test
public void toResponse_shouldReturnErrorResponseWithAuditingTrue() {
    IdpDisabledException exception = new IdpDisabledException(ENTITY_ID);
    Response response = exceptionMapper.toResponse(exception);
    final ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(true);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.IDP_DISABLED);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 45 with ErrorStatusDto

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

the class SessionCreationFailureExceptionMapperTest method toResponse_shouldLogToAudit.

@Test
public void toResponse_shouldLogToAudit() {
    SessionCreationFailureException exception = new SessionCreationFailureException(MESSAGE, Level.ERROR, ExceptionType.DUPLICATE_SESSION);
    final Response response = mapper.toResponse(exception);
    verify(hubEventLogger).logErrorEvent(any(UUID.class), eq(SESSION_ID), eq(MESSAGE));
    final ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(true);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.DUPLICATE_SESSION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) UUID(java.util.UUID) 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