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));
}
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"));
}
}
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" + "}" + "}"));
}
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);
}
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;
}
Aggregations