Search in sources :

Example 16 with ParameterizedValidationException

use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.

the class CredentialsControllerTypeSpecificSetTest method validationExceptionsAreReturnedAsErrorMessages.

@Test
public void validationExceptionsAreReturnedAsErrorMessages() throws Exception {
    MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
    BaseCredentialSetRequest requestObject = mock(BaseCredentialSetRequest.class);
    doThrow(new ParameterizedValidationException("error.bad_request")).when(requestObject).validate();
    doReturn(requestObject).when(objectMapper).readValue(any(InputStream.class), any(JavaType.class));
    mockMvc.perform(request).andExpect(status().isBadRequest()).andExpect(content().json("{\"error\":\"The request could not be fulfilled because the request path or body did not meet expectation. Please check the documentation for required formatting and retry your request.\"}"));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) InputStream(java.io.InputStream) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) BaseCredentialSetRequest(org.cloudfoundry.credhub.request.BaseCredentialSetRequest) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 17 with ParameterizedValidationException

use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.

the class CertificateAuthorityServiceTest method findActiveVersion_whenCertificateIsNotACa_throwsException.

@Test
public void findActiveVersion_whenCertificateIsNotACa_throwsException() {
    CertificateCredentialVersion notACertificateAuthority = mock(CertificateCredentialVersion.class);
    when(notACertificateAuthority.getParsedCertificate()).thenReturn(mock(CertificateReader.class));
    when(notACertificateAuthority.getCertificate()).thenReturn(CertificateStringConstants.SIMPLE_SELF_SIGNED_TEST_CERT);
    when(certificateVersionDataService.findActive(CREDENTIAL_NAME)).thenReturn(notACertificateAuthority);
    try {
        certificateAuthorityService.findActiveVersion(CREDENTIAL_NAME);
    } catch (ParameterizedValidationException pe) {
        assertThat(pe.getMessage(), equalTo("error.cert_not_ca"));
    }
}
Also used : ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CertificateReader(org.cloudfoundry.credhub.util.CertificateReader) Test(org.junit.Test)

Aggregations

ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)17 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)6 Test (org.junit.Test)6 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)5 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)4 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)4 CertificateReader (org.cloudfoundry.credhub.util.CertificateReader)4 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)3 X509Certificate (java.security.cert.X509Certificate)2 Map (java.util.Map)2 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)2 Credential (org.cloudfoundry.credhub.entity.Credential)2 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 KeyPair (java.security.KeyPair)1