Search in sources :

Example 71 with ErrorStatusDto

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

the class AuthnRequestFromTransactionResourceIntegrationTest method idpSelected_shouldThrowIfSessionInWrongState.

@Test
public void idpSelected_shouldThrowIfSessionInWrongState() {
    sessionId = SessionId.createNewSessionId();
    TestSessionResourceHelper.createSessionInSuccessfulMatchState(sessionId, transactionEntityId, idpEntityId, client, buildUriForTestSession(SUCCESSFUL_MATCH_STATE, sessionId));
    Response response = postIdpSelected(new IdpSelected("does-not-exist", principalIpAddress, REGISTERING, LEVEL_2, "this-is-an-analytics-session-id", "this-is-a-journey-type", abTestVariant));
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto error = response.readEntity(ErrorStatusDto.class);
    assertThat(error.getExceptionType()).isEqualTo(ExceptionType.INVALID_STATE);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) Test(org.junit.jupiter.api.Test)

Example 72 with ErrorStatusDto

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

the class ExceptionFactory method createDisabledEntityException.

private WebApplicationException createDisabledEntityException(ExceptionType exceptionType) {
    final ErrorStatusDto entity = createUnauditedErrorStatus(UUID.randomUUID(), exceptionType);
    final Response response = Response.status(Response.Status.FORBIDDEN).entity(entity).build();
    return new WebApplicationException(response);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 73 with ErrorStatusDto

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

the class ExceptionFactory method createInvalidAssertionConsumerServiceIndexException.

public WebApplicationException createInvalidAssertionConsumerServiceIndexException(String entityId, Integer assertionConsumerServiceIndex) {
    LOG.error(format("Invalid assertion consumer service index ''{0}'' for ''{1}''.", assertionConsumerServiceIndex, entityId));
    final ErrorStatusDto entity = createUnauditedErrorStatus(UUID.randomUUID(), ExceptionType.INVALID_ASSERTION_CONSUMER_INDEX);
    final Response response = Response.status(Response.Status.NOT_FOUND).entity(entity).build();
    return new WebApplicationException(response);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 74 with ErrorStatusDto

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

the class SamlProxyApplicationExceptionMapperTest method toResponse_shouldReturnAuditedErrorResponse.

@Test
public void toResponse_shouldReturnAuditedErrorResponse() {
    ApplicationException exception = createAuditedException(exceptionType, errorId);
    final Response response = mapper.toResponse(exception);
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(responseEntity.isAudited()).isTrue();
}
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 75 with ErrorStatusDto

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

the class SamlProxyExceptionMapperTest method shouldCreateAuditedErrorResponse.

@Test
public void shouldCreateAuditedErrorResponse() {
    Response response = exceptionMapper.handleException(new RuntimeException());
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(responseEntity.isAudited()).isTrue();
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) 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