Search in sources :

Example 1 with PasswordCredentialVersionData

use of org.cloudfoundry.credhub.entity.PasswordCredentialVersionData 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"));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) 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 2 with PasswordCredentialVersionData

use of org.cloudfoundry.credhub.entity.PasswordCredentialVersionData 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()));
}
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) 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 3 with PasswordCredentialVersionData

use of org.cloudfoundry.credhub.entity.PasswordCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method save_givenAnExistingCredential_throwsExceptionIfTypeMismatch.

@Test(expected = ParameterizedValidationException.class)
public void save_givenAnExistingCredential_throwsExceptionIfTypeMismatch() {
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential-3");
    passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
    PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
    subject.save(credential);
    ValueCredentialVersionData newCredentialData = new ValueCredentialVersionData();
    newCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("some value".getBytes()));
    newCredentialData.setCredential(passwordCredentialData.getCredential());
    ValueCredentialVersion newCredential = new ValueCredentialVersion(newCredentialData);
    subject.save(newCredential);
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with PasswordCredentialVersionData

use of org.cloudfoundry.credhub.entity.PasswordCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method setupTestFixtureForFindMostRecent.

private void setupTestFixtureForFindMostRecent() {
    Credential credential = credentialDataService.save(new Credential("/my-CREDENTIAL"));
    namedPasswordCredential1 = new PasswordCredentialVersionData();
    namedPasswordCredential1.setCredential(credential);
    namedPasswordCredential1.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("/my-old-password".getBytes()).setNonce(new byte[] {}));
    passwordCredential2 = new PasswordCredentialVersionData();
    passwordCredential2.setCredential(credential);
    passwordCredential2.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("/my-new-password".getBytes()).setNonce(new byte[] {}));
    subject.save(namedPasswordCredential1);
    // 1 second later
    fakeTimeSetter.accept(345346L);
    subject.save(passwordCredential2);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue)

Example 5 with PasswordCredentialVersionData

use of org.cloudfoundry.credhub.entity.PasswordCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method delete_onACredentialName_deletesAllCredentialsWithTheName.

@Test
public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
    Credential credential = credentialDataService.save(new Credential("/my-credential"));
    PasswordCredentialVersionData credentialData = new PasswordCredentialVersionData();
    credentialData.setCredential(credential);
    credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce("nonce".getBytes()));
    subject.save(credentialData);
    credentialData = new PasswordCredentialVersionData("/my-credential");
    credentialData.setCredential(credential);
    credentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce("nonce".getBytes()));
    subject.save(credentialData);
    assertThat(subject.findAllByName("/my-credential"), hasSize(2));
    subject.delete("/my-credential");
    assertThat(subject.findAllByName("/my-credential"), hasSize(0));
    assertNull(credentialDataService.find("/my-credential"));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)16 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)12 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)9 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)5 Credential (org.cloudfoundry.credhub.entity.Credential)5 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)5 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)4 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)4 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)2 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)2 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)2 SshCredentialVersionData (org.cloudfoundry.credhub.entity.SshCredentialVersionData)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)1 JsonObjectMapper (org.cloudfoundry.credhub.util.JsonObjectMapper)1