Search in sources :

Example 1 with FindCredentialResult

use of org.cloudfoundry.credhub.view.FindCredentialResult in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataService method findMatchingName.

private List<FindCredentialResult> findMatchingName(String nameLike) {
    final List<FindCredentialResult> credentialResults = jdbcTemplate.query(" select name.name, credential_version.version_created_at from (" + "   select" + "     max(version_created_at) as version_created_at," + "     credential_uuid" + "   from credential_version group by credential_uuid" + " ) as credential_version inner join (" + "   select * from credential" + "     where lower(name) like lower(?)" + " ) as name" + " on credential_version.credential_uuid = name.uuid" + " order by version_created_at desc", new Object[] { nameLike }, (rowSet, rowNum) -> {
        final Instant versionCreatedAt = Instant.ofEpochMilli(rowSet.getLong("version_created_at"));
        final String name = rowSet.getString("name");
        return new FindCredentialResult(versionCreatedAt, name);
    });
    return credentialResults;
}
Also used : Instant(java.time.Instant) FindCredentialResult(org.cloudfoundry.credhub.view.FindCredentialResult)

Example 2 with FindCredentialResult

use of org.cloudfoundry.credhub.view.FindCredentialResult in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findContainingName_whenThereAreMultipleVerionsOfACredential.

@Test
public void findContainingName_whenThereAreMultipleVerionsOfACredential() {
    savePassword(2000000000123L, "/foo/DUPLICATE");
    savePassword(1000000000123L, "/foo/DUPLICATE");
    savePassword(3000000000123L, "/bar/duplicate");
    savePassword(4000000000123L, "/bar/duplicate");
    List<FindCredentialResult> credentials = subject.findContainingName("DUP");
    assertThat("should only return unique credential names", credentials.size(), equalTo(2));
    FindCredentialResult credential = credentials.get(0);
    assertThat(credential.getName(), equalTo("/bar/duplicate"));
    assertThat("should return the most recently created version", credential.getVersionCreatedAt(), equalTo(Instant.ofEpochMilli(4000000000123L)));
    credential = credentials.get(1);
    assertThat(credential.getName(), equalTo("/foo/DUPLICATE"));
    assertThat("should return the most recently created version", credential.getVersionCreatedAt(), equalTo(Instant.ofEpochMilli(2000000000123L)));
}
Also used : FindCredentialResult(org.cloudfoundry.credhub.view.FindCredentialResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with FindCredentialResult

use of org.cloudfoundry.credhub.view.FindCredentialResult in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findStartingWithPath_givenMultipleVersionsOfACredential.

@Test
public void findStartingWithPath_givenMultipleVersionsOfACredential() {
    savePassword(2000000000123L, "/DupSecret/1");
    savePassword(3000000000123L, "/DupSecret/1");
    savePassword(1000000000123L, "/DupSecret/1");
    List<FindCredentialResult> credentials = subject.findStartingWithPath("/dupsecret/");
    assertThat("should not return duplicate credential names", credentials.size(), equalTo(1));
    FindCredentialResult credential = credentials.get(0);
    assertThat("should return the most recent credential", credential.getVersionCreatedAt(), equalTo(Instant.ofEpochMilli(3000000000123L)));
}
Also used : FindCredentialResult(org.cloudfoundry.credhub.view.FindCredentialResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with FindCredentialResult

use of org.cloudfoundry.credhub.view.FindCredentialResult 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)

Aggregations

FindCredentialResult (org.cloudfoundry.credhub.view.FindCredentialResult)4 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Instant (java.time.Instant)1 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)1