Search in sources :

Example 6 with CredentialVersionData

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()));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) SshCredentialVersionData(org.cloudfoundry.credhub.entity.SshCredentialVersionData) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with CredentialVersionData

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));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Aggregations

CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)7 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)5 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)5 Test (org.junit.Test)5 Credential (org.cloudfoundry.credhub.entity.Credential)4 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)3 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 UUID (java.util.UUID)2 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)2 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)2 SshCredentialVersionData (org.cloudfoundry.credhub.entity.SshCredentialVersionData)2 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)2 ArrayList (java.util.ArrayList)1 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)1 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)1 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)1 MockMvcResultHandlers.print (org.springframework.test.web.servlet.result.MockMvcResultHandlers.print)1