use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion 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);
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findNByName_whenProvidedANameAndCount_findsCountMatchingCredentials.
@Test
public void findNByName_whenProvidedANameAndCount_findsCountMatchingCredentials() {
PasswordCredentialVersion credential1 = savePassword(2000000000125L, "/secret1");
PasswordCredentialVersion credential2 = savePassword(2000000000124L, "/seCret1");
PasswordCredentialVersion credential3 = savePassword(2000000000123L, "/secret1");
savePassword(3000000000123L, "/Secret2");
List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", 2);
assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(credential1.getUuid())), hasProperty("uuid", equalTo(credential2.getUuid()))));
assertThat("returns empty list when no credential matches", subject.findNByName("does/NOT/exist", 12), empty());
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findStartingWithPath_whenProvidedAPath_returnsTheListOfOrderedCredentials.
@Test
public void findStartingWithPath_whenProvidedAPath_returnsTheListOfOrderedCredentials() {
setupTestFixtureForFindStartingWithPath();
List<FindCredentialResult> credentials = subject.findStartingWithPath("Credential/");
assertThat(credentials.size(), equalTo(3));
assertThat(credentials, IsIterableContainingInOrder.contains(hasProperty("name", equalTo("/Credential/2")), hasProperty("name", equalTo("/credential/1")), hasProperty("name", equalTo("/CREDENTIAL/3"))));
assertThat("should return a list of credentials in chronological order that start with a given string", credentials, not(contains(hasProperty("notSoSecret"))));
PasswordCredentialVersion passwordCredential = (PasswordCredentialVersion) subject.findMostRecent("/credential/1");
passwordCredential.setPasswordAndGenerationParameters("new-password", null);
subject.save(passwordCredential);
credentials = subject.findStartingWithPath("Credential/");
assertThat("should return credentials in order by version_created_at, not updated_at", credentials, IsIterableContainingInOrder.contains(hasProperty("name", equalTo("/Credential/2")), hasProperty("name", equalTo("/credential/1")), hasProperty("name", equalTo("/CREDENTIAL/3"))));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findNByName_whenAskedForANegativeNumberOfVersions_throws.
@Test(expected = IllegalArgumentException.class)
public void findNByName_whenAskedForANegativeNumberOfVersions_throws() {
PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", -2);
assertThat(credentialVersions.size(), equalTo(0));
}
Aggregations