use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive.
@Test
public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive() {
Credential credentialName = credentialDataService.save(new Credential("/my-credential"));
PasswordCredentialVersionData credential = new PasswordCredentialVersionData();
credential.setCredential(credentialName);
credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce(new byte[] {}));
subject.save(credential);
credential = new PasswordCredentialVersionData();
credential.setCredential(credentialName);
credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce(new byte[] {}));
subject.save(credential);
assertThat(subject.findAllByName("/my-credential"), hasSize(2));
subject.delete("/MY-CREDENTIAL");
assertThat(subject.findAllByName("/my-credential"), empty());
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findContainingName_givenACredentialName_returnsCredentialsInReverseChronologicalOrder.
@Test
public void findContainingName_givenACredentialName_returnsCredentialsInReverseChronologicalOrder() {
String valueName = "/value.Credential";
String passwordName = "/password/Credential";
String certificateName = "/certif/ic/atecredential";
setupTestFixturesForFindContainingName(valueName, passwordName, certificateName);
assertThat(subject.findContainingName("CREDENTIAL"), IsIterableContainingInOrder.contains(hasProperty("name", equalTo(certificateName)), hasProperty("name", equalTo(valueName)), hasProperty("name", equalTo(passwordName))));
ValueCredentialVersion valueCredential = (ValueCredentialVersion) subject.findMostRecent("/value.Credential");
valueCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("new-encrypted-value".getBytes()).setNonce("nonce".getBytes()));
subject.save(valueCredential);
assertThat("The credentials are ordered by versionCreatedAt", subject.findContainingName("CREDENTIAL"), IsIterableContainingInOrder.contains(hasProperty("name", equalTo(certificateName)), hasProperty("name", equalTo(valueName)), hasProperty("name", equalTo(passwordName))));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenAnExistingCredential_updatesTheCredential.
@Test
public void save_givenAnExistingCredential_updatesTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential-2");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "credential-password", "nonce"));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(credential);
passwordCredentialData.getEncryptedValueData().setEncryptedValue("irynas-ninja-skills".getBytes());
subject.save(credential);
PasswordCredentialVersion savedPasswordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential-2");
CredentialVersionData credentialVersionData = credentialVersionRepository.findOneByUuid(savedPasswordCredential.getUuid());
assertThat(credentialVersionData.getCredential().getName(), equalTo("/my-credential-2"));
assertThat(credentialVersionData.getEncryptedValueData().getEncryptedValue(), equalTo("irynas-ninja-skills".getBytes()));
assertThat(credentialVersionData.getUuid(), equalTo(credential.getUuid()));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method savePassword.
private PasswordCredentialVersion savePassword(long timeMillis, String name, UUID canaryUuid) {
fakeTimeSetter.accept(timeMillis);
Credential credential = credentialDataService.find(name);
if (credential == null) {
credential = credentialDataService.save(new Credential(name));
}
PasswordCredentialVersionData credentialObject = new PasswordCredentialVersionData();
credentialObject.setCredential(credential);
credentialObject.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
return subject.save(credentialObject);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method setupTestFixturesForFindContainingName.
private void setupTestFixturesForFindContainingName(String valueName, String passwordName, String certificateName) {
fakeTimeSetter.accept(2000000000123L);
valueCredentialData = new ValueCredentialVersionData(valueName);
valueCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("value".getBytes()).setNonce(new byte[] {}));
ValueCredentialVersion namedValueCredential = new ValueCredentialVersion(valueCredentialData);
namedValueCredential.setEncryptor(encryptor);
subject.save(namedValueCredential);
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/mySe.cret");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "", ""));
new PasswordCredentialVersion(passwordCredentialData);
PasswordCredentialVersion namedPasswordCredential;
subject.save(namedValueCredential);
fakeTimeSetter.accept(1000000000123L);
passwordCredentialData = new PasswordCredentialVersionData(passwordName);
passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("password".getBytes()).setNonce(new byte[] {}));
namedPasswordCredential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(namedPasswordCredential);
CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData("/myseecret");
CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
fakeTimeSetter.accept(3000000000123L);
certificateCredentialData = new CertificateCredentialVersionData(certificateName);
certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
}
Aggregations