Search in sources :

Example 21 with CertificateCredentialVersion

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

the class PermissionedCertificateServiceTest method deleteVersion_deletesTheProvidedVersion.

@Test
public void deleteVersion_deletesTheProvidedVersion() {
    UUID versionUuid = UUID.randomUUID();
    UUID certificateUuid = UUID.randomUUID();
    CertificateCredentialVersion versionToDelete = mock(CertificateCredentialVersion.class);
    when(certificateVersionDataService.findVersion(versionUuid)).thenReturn(versionToDelete);
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    String user = "my-user";
    String credentialName = "my-credential";
    when(userContext.getActor()).thenReturn(user);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.DELETE)).thenReturn(true);
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    when(certificate.getUuid()).thenReturn(UUID.randomUUID());
    when(certificateVersionDataService.findVersion(versionUuid)).thenReturn(versionToDelete);
    when(versionToDelete.getCredential()).thenReturn(certificate);
    CertificateCredentialVersion certificateCredentialVersion = subject.deleteVersion(certificateUuid, versionUuid, newArrayList());
    assertThat(certificateCredentialVersion, equalTo(versionToDelete));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 22 with CertificateCredentialVersion

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

the class PermissionedCertificateServiceTest method save_whenTransitionalIsTrue_AndThereIsAnotherTransitionalVersion_throwsAnException.

@Test
public void save_whenTransitionalIsTrue_AndThereIsAnotherTransitionalVersion_throwsAnException() throws Exception {
    CertificateCredentialValue value = mock(CertificateCredentialValue.class);
    when(value.isTransitional()).thenReturn(true);
    BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
    when(generateRequest.getName()).thenReturn("/some-name");
    CertificateCredentialVersion previousVersion = mock(CertificateCredentialVersion.class);
    when(previousVersion.isVersionTransitional()).thenReturn(true);
    when(permissionedCredentialService.findAllByName(eq("/some-name"), any())).thenReturn(newArrayList(previousVersion));
    try {
        subject.save(mock(CredentialVersion.class), value, generateRequest, newArrayList());
        fail("should throw exception");
    } catch (ParameterizedValidationException e) {
        assertThat(e.getMessage(), equalTo("error.too_many_transitional_versions"));
    }
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 23 with CertificateCredentialVersion

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

the class CertificateCredentialTest method includesKeysWithNullValues.

@Test
public void includesKeysWithNullValues() {
    final CredentialView subject = CertificateView.fromEntity(new CertificateCredentialVersion(credentialName).setEncryptor(encryptor).setUuid(uuid));
    final String json = JsonTestHelper.serializeToString(subject);
    assertThat(json, equalTo("{" + "\"type\":\"certificate\"," + "\"transitional\":false," + "\"version_created_at\":null," + "\"id\":\"" + uuid.toString() + "\",\"name\":\"" + credentialName + "\",\"value\":{" + "\"ca\":null," + "\"certificate\":null," + "\"private_key\":null" + "}" + "}"));
}
Also used : CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 24 with CertificateCredentialVersion

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

the class CertificateCredentialTest method beforeEach.

@Before
public void beforeEach() {
    getBouncyCastleProvider();
    UUID canaryUuid = UUID.randomUUID();
    byte[] encryptedValue = "fake-encrypted-value".getBytes();
    byte[] nonce = "fake-nonce".getBytes();
    encryptor = mock(Encryptor.class);
    final EncryptedValue encryption = new EncryptedValue(canaryUuid, encryptedValue, nonce);
    when(encryptor.encrypt("priv")).thenReturn(encryption);
    when(encryptor.decrypt(encryption)).thenReturn("priv");
    credentialName = "/foo";
    uuid = UUID.randomUUID();
    entity = new CertificateCredentialVersion(credentialName).setEncryptor(encryptor).setCa("ca").setCertificate("cert").setPrivateKey("priv").setUuid(uuid);
}
Also used : Encryptor(org.cloudfoundry.credhub.domain.Encryptor) UUID(java.util.UUID) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Before(org.junit.Before)

Example 25 with CertificateCredentialVersion

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

the class CertificatesHandler method handleGetAllVersionsRequest.

public List<CertificateView> handleGetAllVersionsRequest(String uuidString, List<EventAuditRecordParameters> auditRecordParameters, boolean current) {
    UUID uuid;
    try {
        uuid = UUID.fromString(uuidString);
    } catch (IllegalArgumentException e) {
        auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, null));
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    final List<CredentialVersion> credentialList = permissionedCertificateService.getVersions(uuid, current, auditRecordParameters);
    List<CertificateView> list = credentialList.stream().map(credential -> new CertificateView((CertificateCredentialVersion) credential)).collect(Collectors.toList());
    return list;
}
Also used : CredentialView(org.cloudfoundry.credhub.view.CredentialView) PermissionedCertificateService(org.cloudfoundry.credhub.service.PermissionedCertificateService) BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialsView(org.cloudfoundry.credhub.view.CertificateCredentialsView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CreateVersionRequest(org.cloudfoundry.credhub.request.CreateVersionRequest) UUID(java.util.UUID) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Collectors(java.util.stream.Collectors) CertificateCredentialView(org.cloudfoundry.credhub.view.CertificateCredentialView) CertificateRegenerateRequest(org.cloudfoundry.credhub.request.CertificateRegenerateRequest) UpdateTransitionalVersionRequest(org.cloudfoundry.credhub.request.UpdateTransitionalVersionRequest) List(java.util.List) Credential(org.cloudfoundry.credhub.entity.Credential) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) AuditingOperationCode(org.cloudfoundry.credhub.audit.AuditingOperationCode) Service(org.springframework.stereotype.Service) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) CertificateService(org.cloudfoundry.credhub.service.CertificateService) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) UUID(java.util.UUID) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateView(org.cloudfoundry.credhub.view.CertificateView)

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