Search in sources :

Example 26 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method toResponse_shouldCreateResponseWithUnauditedErrorStatus.

@Test
public void toResponse_shouldCreateResponseWithUnauditedErrorStatus() throws Exception {
    SamlTransformationErrorException exception = aSamlTransformationFailureException().build();
    Response response = samlEngineExceptionMapper.toResponse(exception);
    assertThat(response.getEntity()).isNotNull();
    final ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(false);
    assertThat(errorStatusDto.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)

Example 27 with ErrorStatusDto

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

the class SamlMessageReceiverApiResourceTest method assertError.

private void assertError(Response.StatusType statusType, final Response response, final ExceptionType exceptionType) {
    assertThat(response.getStatus()).isEqualTo(statusType.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getErrorId()).isNotNull();
    assertThat(entity.getExceptionType()).isEqualTo(exceptionType);
}
Also used : ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto)

Example 28 with ErrorStatusDto

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

the class SamlProxySamlTransformationErrorExceptionMapperTest method shouldCreateAuditedErrorResponseForInvalidSaml.

@Test
public void shouldCreateAuditedErrorResponseForInvalidSaml() {
    Response response = exceptionMapper.handleException(new TestSamlTransformationErrorException("error", new RuntimeException(), Level.DEBUG));
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(responseEntity.isAudited()).isTrue();
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 29 with ErrorStatusDto

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldHandleErrorResponseFromSamlEngine.

@Test
public void responsePost_shouldHandleErrorResponseFromSamlEngine() throws Exception {
    samlEngineStub.setupStubForIdpAuthnResponseTranslateReturningError(ErrorStatusDto.createUnauditedErrorStatus(UUID.randomUUID(), ExceptionType.INVALID_SAML));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto responseEntity = response.readEntity(ErrorStatusDto.class);
    assertThat(responseEntity.getExceptionType()).isEqualTo(ErrorStatusDto.createUnauditedErrorStatus(UUID.randomUUID(), ExceptionType.INVALID_SAML).getExceptionType());
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 30 with ErrorStatusDto

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldReturnBadRequestSessionDoesNotExist.

@Test
public void responsePost_shouldReturnBadRequestSessionDoesNotExist() {
    Response response = postIdpResponse(SessionId.createNewSessionId(), samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto responseEntity = response.readEntity(ErrorStatusDto.class);
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.SESSION_NOT_FOUND);
}
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