use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findAllByName_whenProvidedAName_findsAllMatchingCredentials.
@Test
public void findAllByName_whenProvidedAName_findsAllMatchingCredentials() {
PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
PasswordCredentialVersion credential2 = savePassword(4000000000123L, "/seCret1");
savePassword(3000000000123L, "/Secret2");
List<CredentialVersion> credentialVersions = subject.findAllByName("/Secret1");
assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(credential1.getUuid())), hasProperty("uuid", equalTo(credential2.getUuid()))));
assertThat("returns empty list when no credential matches", subject.findAllByName("does/NOT/exist"), empty());
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findActiveByName_whenAskedNonCertificateType_returnsOneCredentialValue.
@Test
public void findActiveByName_whenAskedNonCertificateType_returnsOneCredentialValue() throws Exception {
PasswordCredentialVersion password1 = savePassword(2000000000123L, "/test/password");
PasswordCredentialVersion password2 = savePassword(3000000000123L, "/test/password");
PasswordCredentialVersion password3 = savePassword(4000000000123L, "/test/password");
List<CredentialVersion> credentialVersions = subject.findActiveByName("/test/password");
assertThat(credentialVersions.size(), equalTo(1));
assertThat(credentialVersions, contains(hasProperty("uuid", equalTo(password3.getUuid()))));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenACredentialWithALeadingSlash_savesWithTheLeadingSlash.
@Test
public void save_givenACredentialWithALeadingSlash_savesWithTheLeadingSlash() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my/credential");
PasswordCredentialVersion credentialWithLeadingSlash = new PasswordCredentialVersion(passwordCredentialData);
subject.save(credentialWithLeadingSlash);
CredentialVersion savedCredentialVersion = subject.findMostRecent("/my/credential");
assertThat(savedCredentialVersion.getCredential().getName(), equalTo("/my/credential"));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findNByName_whenAskedForTooManyVersions_returnsAllVersions.
@Test
public void findNByName_whenAskedForTooManyVersions_returnsAllVersions() {
PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", 2);
assertThat(credentialVersions.size(), equalTo(1));
assertThat(credentialVersions.get(0).getUuid(), equalTo(credential1.getUuid()));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenANewCredential_savesTheCredential.
@Test
public void save_givenANewCredential_savesTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "credential-password", ""));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
credential.setEncryptor(encryptor);
CredentialVersion savedCredentialVersion = subject.save(credential);
assertNotNull(savedCredentialVersion);
PasswordCredentialVersion savedPasswordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential");
CredentialVersionData credentialVersionData = credentialVersionRepository.findOneByUuid(savedCredentialVersion.getUuid());
assertThat(savedPasswordCredential.getName(), equalTo(credential.getName()));
assertThat(savedPasswordCredential.getUuid(), equalTo(credential.getUuid()));
assertThat(credentialVersionData.getCredential().getName(), equalTo("/my-credential"));
assertThat(credentialVersionData.getEncryptedValueData().getEncryptedValue(), equalTo("credential-password".getBytes()));
}
Aggregations