use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldThrowExceptionIfResponseContainsAuthnAssertionInResponseToValuesNotMatchingRequestId.
@Test
public void shouldThrowExceptionIfResponseContainsAuthnAssertionInResponseToValuesNotMatchingRequestId() throws Exception {
final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilderWithInResponseToValues(STUB_IDP_ONE, "default-request-id", "wrong-request-id", "default-request-id").withDestination("http://localhost" + Urls.FrontendUrls.SAML2_SSO_RESPONSE_ENDPOINT).build();
String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldNotDecryptAssertionEncryptedWithIncorrectEncryptionCertificates.
@Test
public void handleResponseFromIdp_shouldNotDecryptAssertionEncryptedWithIncorrectEncryptionCertificates() throws Exception {
BasicCredential incorrectEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getPrimaryEncryptionKeyForEntity(TEST_RP));
SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(incorrectEncryptionKey);
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_FAILED_TO_DECRYPT);
}
use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldThrowExceptionIfResponseContainsPartsWithMismatchedIssuers.
@Test
public void shouldThrowExceptionIfResponseContainsPartsWithMismatchedIssuers() throws Exception {
final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilderWithIssuers(STUB_IDP_ONE, STUB_IDP_ONE, STUB_IDP_TWO).withDestination("http://localhost" + Urls.FrontendUrls.SAML2_SSO_RESPONSE_ENDPOINT).build();
String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldThrowExceptionWithTimeoutErrorStatusIfBearerSubjectTimeIsTooOld.
@Test
public void shouldThrowExceptionWithTimeoutErrorStatusIfBearerSubjectTimeIsTooOld() throws Exception {
DateTimeFreezer.freezeTime(DateTime.now().minusDays(1));
SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto();
DateTimeFreezer.unfreezeTime();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.common.ErrorStatusDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldNotTranslateAnIncorrectIdpAuthnResponse.
@Test
public void shouldNotTranslateAnIncorrectIdpAuthnResponse() throws Exception {
final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilder(STUB_IDP_ONE).withDestination(IDP_RESPONSE_ENDPOINT).withStatus(AUTHN_FAILED_STATUS).build();
String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId("IGNOREME").build();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Aggregations