use of org.cloudfoundry.credhub.entity.CredentialVersionData 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.CredentialVersionData in project credhub by cloudfoundry-incubator.
the class CertificateVersionDataServiceTest method findActiveWithTransitional_findsMostRecentNonTransitionalAndTransitionalCredentialVersions.
@Test
public void findActiveWithTransitional_findsMostRecentNonTransitionalAndTransitionalCredentialVersions() throws Exception {
Credential certificate = mock(Credential.class);
when(dataService.find("/some-cert-name")).thenReturn(certificate);
CredentialVersionData activeCert = mock(CredentialVersionData.class);
when(versionRepository.findLatestNonTransitionalCertificateVersion(any())).thenReturn(activeCert);
CredentialVersionData transitionalCert = mock(CredentialVersionData.class);
when(versionRepository.findTransitionalCertificateVersion(any())).thenReturn(transitionalCert);
CredentialVersion expectedActive = mock(CredentialVersion.class);
when(factory.makeCredentialFromEntity(activeCert)).thenReturn(expectedActive);
CredentialVersion expectedTransitional = mock(CredentialVersion.class);
when(factory.makeCredentialFromEntity(transitionalCert)).thenReturn(expectedTransitional);
List<CredentialVersion> credentialVersions = subject.findActiveWithTransitional("/some-cert-name");
assertThat(credentialVersions, hasSize(2));
assertThat(credentialVersions, containsInAnyOrder(expectedActive, expectedTransitional));
}
Aggregations