Search in sources :

Example 31 with CertificateCredentialVersion

use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion 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)

Example 32 with CertificateCredentialVersion

use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificatesHandlerTest method handleGetAllVersionsRequest_returnsListOfCertificateViews.

@Test
public void handleGetAllVersionsRequest_returnsListOfCertificateViews() {
    UUID uuid = UUID.randomUUID();
    String certificateName = "some certificate";
    CredentialVersion credentialVersion = new CertificateCredentialVersion(certificateName);
    when(permissionedCertificateService.getVersions(uuid, false, Collections.emptyList())).thenReturn(Collections.singletonList(credentialVersion));
    List<CertificateView> certificateViews = subject.handleGetAllVersionsRequest(uuid.toString(), Collections.emptyList(), false);
    assertThat(certificateViews.size(), equalTo(1));
    assertThat(certificateViews.get(0).getName(), equalTo(certificateName));
}
Also used : UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 33 with CertificateCredentialVersion

use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificatesHandlerTest method handleRegenerate_passesOnTransitionalFlagWhenRegeneratingCertificate.

@Test
public void handleRegenerate_passesOnTransitionalFlagWhenRegeneratingCertificate() {
    BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
    CertificateCredentialVersion certificate = mock(CertificateCredentialVersion.class);
    CertificateCredentialValue newValue = mock(CertificateCredentialValue.class);
    when(certificate.getName()).thenReturn("test");
    when(certificateService.findByCredentialUuid(eq(UUID_STRING), any())).thenReturn(certificate);
    when(generationRequestGenerator.createGenerateRequest(eq(certificate), eq("test"), any())).thenReturn(generateRequest);
    when(universalCredentialGenerator.generate(eq(generateRequest))).thenReturn(newValue);
    when(permissionedCertificateService.save(eq(certificate), any(), any(), any())).thenReturn(mock(CertificateCredentialVersion.class));
    CertificateRegenerateRequest regenerateRequest = new CertificateRegenerateRequest(true);
    subject.handleRegenerate(UUID_STRING, Collections.emptyList(), regenerateRequest);
    verify(newValue).setTransitional(true);
}
Also used : CertificateRegenerateRequest(org.cloudfoundry.credhub.request.CertificateRegenerateRequest) BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Aggregations

CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)33 Test (org.junit.Test)16 UUID (java.util.UUID)10 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)10 Credential (org.cloudfoundry.credhub.entity.Credential)9 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)8 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)8 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)7 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)6 BaseCredentialGenerateRequest (org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)6 UserContext (org.cloudfoundry.credhub.auth.UserContext)5 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)5 CertificateView (org.cloudfoundry.credhub.view.CertificateView)5 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)4 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)3 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)3 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)3 CertificateRegenerateRequest (org.cloudfoundry.credhub.request.CertificateRegenerateRequest)3