Search in sources :

Example 31 with ErrorStatusDto

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

the class RpErrorResponseFromHubIntegrationTest method shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry.

@Test
public void shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry() throws Exception {
    final SessionId sessionId = aSessionIsCreated();
    samlEngineStub.setUpStubForErrorResponseGenerateErrorOccurring();
    URI uri = UriBuilder.fromPath(Urls.PolicyUrls.RP_ERROR_RESPONSE_RESOURCE).build(sessionId.getSessionId());
    Response response = get(uri);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = response.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 32 with ErrorStatusDto

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

the class AuthnRequestFromTransactionResourceIntegrationTest method idpSelected_shouldThrowIfIdpIsNotAvailable.

@Test
public void idpSelected_shouldThrowIfIdpIsNotAvailable() throws JsonProcessingException {
    sessionId = aSessionIsCreated();
    IdpSelected idpSelected = new IdpSelected("does-not-exist", principalIpAddress, REGISTERING, LEVEL_2, "this-is-an-analytics-session-id", "this-is-a-journey-type", abTestVariant);
    Response response = postIdpSelected(idpSelected);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto error = response.readEntity(ErrorStatusDto.class);
    assertThat(error.getExceptionType()).isEqualTo(ExceptionType.STATE_PROCESSING_VALIDATION);
}
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 33 with ErrorStatusDto

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

the class SessionResourceAuthnResponseFromIdpIntegrationTests method responsePost_shouldReturnForbiddenWhenIdpIsNotAvailable.

@Test
public void responsePost_shouldReturnForbiddenWhenIdpIsNotAvailable() throws JsonProcessingException {
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.successResponse("idpDoesNotExist", LevelOfAssurance.LEVEL_2));
    Response response = postIdpResponse(sessionId, samlResponseDto);
    assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());
    ErrorStatusDto responseEntity = response.readEntity(ErrorStatusDto.class);
    assertThat(responseEntity.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 34 with ErrorStatusDto

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

the class SamlProxySamlTransformationErrorExceptionMapperTest method shouldCreateAuditedErrorResponseForDuplicateRequestIdError.

@Test
public void shouldCreateAuditedErrorResponseForDuplicateRequestIdError() throws Exception {
    Response response = exceptionMapper.handleException(new SamlDuplicateRequestIdException("error", new RuntimeException(), Level.DEBUG));
    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(responseEntity.isAudited()).isTrue();
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_DUPLICATE_REQUEST_ID);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlDuplicateRequestIdException(uk.gov.ida.saml.hub.exception.SamlDuplicateRequestIdException) Test(org.junit.Test)

Example 35 with ErrorStatusDto

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

the class SamlEngineExceptionMapperTest method shouldHandleSamlDuplicateRequestIdExceptionCorrectly.

@Test
public void shouldHandleSamlDuplicateRequestIdExceptionCorrectly() throws Exception {
    SamlTransformationErrorException exception = new SamlDuplicateRequestIdException("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_DUPLICATE_REQUEST_ID);
    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) SamlDuplicateRequestIdException(uk.gov.ida.saml.hub.exception.SamlDuplicateRequestIdException) 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