Search in sources :

Example 41 with EncryptedValue

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

the class CredentialVersionDataServiceTest method delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive.

@Test
public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive() {
    Credential credentialName = credentialDataService.save(new Credential("/my-credential"));
    PasswordCredentialVersionData credential = new PasswordCredentialVersionData();
    credential.setCredential(credentialName);
    credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce(new byte[] {}));
    subject.save(credential);
    credential = new PasswordCredentialVersionData();
    credential.setCredential(credentialName);
    credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce(new byte[] {}));
    subject.save(credential);
    assertThat(subject.findAllByName("/my-credential"), hasSize(2));
    subject.delete("/MY-CREDENTIAL");
    assertThat(subject.findAllByName("/my-credential"), empty());
}
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)

Example 42 with EncryptedValue

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

the class CredentialVersionDataServiceTest method findContainingName_givenACredentialName_returnsCredentialsInReverseChronologicalOrder.

@Test
public void findContainingName_givenACredentialName_returnsCredentialsInReverseChronologicalOrder() {
    String valueName = "/value.Credential";
    String passwordName = "/password/Credential";
    String certificateName = "/certif/ic/atecredential";
    setupTestFixturesForFindContainingName(valueName, passwordName, certificateName);
    assertThat(subject.findContainingName("CREDENTIAL"), IsIterableContainingInOrder.contains(hasProperty("name", equalTo(certificateName)), hasProperty("name", equalTo(valueName)), hasProperty("name", equalTo(passwordName))));
    ValueCredentialVersion valueCredential = (ValueCredentialVersion) subject.findMostRecent("/value.Credential");
    valueCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("new-encrypted-value".getBytes()).setNonce("nonce".getBytes()));
    subject.save(valueCredential);
    assertThat("The credentials are ordered by versionCreatedAt", subject.findContainingName("CREDENTIAL"), IsIterableContainingInOrder.contains(hasProperty("name", equalTo(certificateName)), hasProperty("name", equalTo(valueName)), hasProperty("name", equalTo(passwordName))));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 43 with EncryptedValue

use of org.cloudfoundry.credhub.entity.EncryptedValue 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 44 with EncryptedValue

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

the class CredentialVersionDataServiceTest method savePassword.

private PasswordCredentialVersion savePassword(long timeMillis, String name, UUID canaryUuid) {
    fakeTimeSetter.accept(timeMillis);
    Credential credential = credentialDataService.find(name);
    if (credential == null) {
        credential = credentialDataService.save(new Credential(name));
    }
    PasswordCredentialVersionData credentialObject = new PasswordCredentialVersionData();
    credentialObject.setCredential(credential);
    credentialObject.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
    return subject.save(credentialObject);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue)

Example 45 with EncryptedValue

use of org.cloudfoundry.credhub.entity.EncryptedValue 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)

Aggregations

EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)56 Test (org.junit.Test)31 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)12 Before (org.junit.Before)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)7 Credential (org.cloudfoundry.credhub.entity.Credential)7 UUID (java.util.UUID)6 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)6 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)6 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)5 UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)5 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)5 ProviderException (java.security.ProviderException)4 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)4 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)4 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Key (java.security.Key)3 KeyNotFoundException (org.cloudfoundry.credhub.exceptions.KeyNotFoundException)3