Search in sources :

Example 31 with PasswordCredentialVersion

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);
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 32 with PasswordCredentialVersion

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());
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 33 with PasswordCredentialVersion

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"))));
}
Also used : FindCredentialResult(org.cloudfoundry.credhub.view.FindCredentialResult) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 34 with PasswordCredentialVersion

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));
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)34 Test (org.junit.Test)25 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)20 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)15 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)11 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)11 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)10 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)9 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)7 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)6 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)5 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)5 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 UUID (java.util.UUID)3 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)3 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Before (org.junit.Before)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2