use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method delete_onACredentialName_deletesAllCredentialsWithTheName.
@Test
public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
Credential credential = credentialDataService.save(new Credential("/my-credential"));
PasswordCredentialVersionData credentialData = new PasswordCredentialVersionData();
credentialData.setCredential(credential);
credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce("nonce".getBytes()));
subject.save(credentialData);
credentialData = new PasswordCredentialVersionData("/my-credential");
credentialData.setCredential(credential);
credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce("nonce".getBytes()));
subject.save(credentialData);
assertThat(subject.findAllByName("/my-credential"), hasSize(2));
subject.delete("/my-credential");
assertThat(subject.findAllByName("/my-credential"), hasSize(0));
assertNull(credentialDataService.find("/my-credential"));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionDataServiceTest method seedDatabase.
private void seedDatabase() {
ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(CREDENTIAL_NAME);
credential = valueCredentialData.getCredential();
ValueCredentialVersionData noAccessValueCredentialData = new ValueCredentialVersionData(NO_ACCESS_CREDENTIAL_NAME);
Credential noAccessValueCredential = noAccessValueCredentialData.getCredential();
Credential noAccessCredential = credentialDataService.save(noAccessValueCredential);
this.credential = credentialDataService.save(this.credential);
subject.savePermissions(this.credential, singletonList(new PermissionEntry(LUKE, newArrayList(WRITE, DELETE))));
subject.savePermissions(this.credential, singletonList(new PermissionEntry(LEIA, singletonList(READ))));
subject.savePermissions(this.credential, singletonList(new PermissionEntry(HAN_SOLO, newArrayList(READ_ACL, WRITE_ACL))));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CertificateVersionDataServiceTest method findActive_FindsMostRecentNonTransitionalCredentialVersion.
@Test
public void findActive_FindsMostRecentNonTransitionalCredentialVersion() throws Exception {
Credential certificate = mock(Credential.class);
when(dataService.find("/some-ca-name")).thenReturn(certificate);
CredentialVersionData certificateEntity = mock(CredentialVersionData.class);
when(versionRepository.findLatestNonTransitionalCertificateVersion(any())).thenReturn(certificateEntity);
CredentialVersion expectedVersion = mock(CredentialVersion.class);
when(factory.makeCredentialFromEntity(certificateEntity)).thenReturn(expectedVersion);
CredentialVersion activeVersion = subject.findActive("/some-ca-name");
assertThat(activeVersion, equalTo(expectedVersion));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialDataServiceTest method find_isCaseInsensitive.
@Test
public void find_isCaseInsensitive() {
final Credential credential = new Credential(CREDENTIAL_NAME.toLowerCase());
credentialRepository.save(credential);
assertThat(subject.find(CREDENTIAL_NAME.toUpperCase()), equalTo(credential));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method deleteVersion.
public CertificateCredentialVersion deleteVersion(UUID certificateUuid, UUID versionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_DELETE, null);
auditRecordParameters.add(eventAuditRecordParameters);
Credential certificate = certificateDataService.findByUuid(certificateUuid);
if (certificate == null || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.DELETE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
eventAuditRecordParameters.setCredentialName(certificate.getName());
CertificateCredentialVersion versionToDelete = certificateVersionDataService.findVersion(versionUuid);
if (versionDoesNotBelongToCertificate(certificate, versionToDelete)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
if (certificateHasOnlyOneVersion(certificateUuid)) {
throw new ParameterizedValidationException("error.credential.cannot_delete_last_version");
}
certificateVersionDataService.deleteVersion(versionUuid);
return versionToDelete;
}
Aggregations