Search in sources :

Example 46 with ErrorStatusDto

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

the class SessionNotFoundExceptionMapperTest method toResponse_shouldReturnUnauditedErrorStatus.

@Test
public void toResponse_shouldReturnUnauditedErrorStatus() {
    SessionNotFoundException exception = new SessionNotFoundException(aSessionId().with(SESSION_ID).build());
    Response response = mapper.toResponse(exception);
    verify(eventLogger).logErrorEvent(any(UUID.class), eq(aSessionId().with(SESSION_ID).build()), eq("Session: 42 not found."));
    assertThat(response.getEntity()).isNotNull();
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.isAudited()).isEqualTo(false);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.SESSION_NOT_FOUND);
}
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 47 with ErrorStatusDto

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

the class RpAuthnRequestTranslatorResourceTest method shouldThrowExceptionWhenTheRequestIdIsADuplicate.

@Test
public void shouldThrowExceptionWhenTheRequestIdIsADuplicate() {
    SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withId("_iamtheoneandonlytheresnootherrequestididratherbe").withIssuer(TEST_RP).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    post(requestDto, Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE);
    Response response = post(requestDto, Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_DUPLICATE_REQUEST_ID);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.jupiter.api.Test)

Example 48 with ErrorStatusDto

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

the class RpAuthnRequestTranslatorResourceTest method authenticationRequestPost_shouldThrowExceptionWhenIssueInstantTooOld.

@Test
public void authenticationRequestPost_shouldThrowExceptionWhenIssueInstantTooOld() {
    DateTimeFreezer.freezeTime();
    DateTime issueInstant = DateTime.now().minusMinutes(5).minusSeconds(1);
    SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withIssueInstant(issueInstant).withIssuer(TEST_RP).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    Response response = post(requestDto, Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_REQUEST_TOO_OLD);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 49 with ErrorStatusDto

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

the class RpErrorResponseGeneratorResourceTest method shouldReturnAnErrorResponseGivenBadInput.

@Test
public void shouldReturnAnErrorResponseGivenBadInput() throws JsonProcessingException {
    RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto = aRequestForErrorResponseFromHubDto().withStatus(null).build();
    configStub.signResponsesAndUseSamlStandard(requestForErrorResponseFromHubDto.getAuthnRequestIssuerEntityId());
    Response rpAuthnResponse = post(requestForErrorResponseFromHubDto, Urls.SamlEngineUrls.GENERATE_RP_ERROR_RESPONSE_RESOURCE);
    assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = rpAuthnResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) RequestForErrorResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.RequestForErrorResponseFromHubDto) RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.RequestForErrorResponseFromHubDtoBuilder.aRequestForErrorResponseFromHubDto) Test(org.junit.jupiter.api.Test)

Example 50 with ErrorStatusDto

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

the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoWhenResponseIs_Nonsense.

@Test
public void shouldNotReturnADtoWhenResponseIs_Nonsense() {
    final SamlResponseContainerDto samlResponseContainerDto = new SamlResponseContainerDto(StringUtils.rightPad("test", 2000, "x"), TEST_RP);
    Response clientResponse = postToSamlEngine(samlResponseContainerDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) SamlResponseContainerDto(uk.gov.ida.hub.samlengine.domain.SamlResponseContainerDto) 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