Search in sources :

Example 6 with ValueCredentialVersionData

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

the class ValueCredentialVersionTest method setValue_encryptsValue.

@Test
public void setValue_encryptsValue() {
    valueCredentialData = new ValueCredentialVersionData("foo");
    subject = new ValueCredentialVersion(valueCredentialData).setEncryptor(encryptor);
    subject.setValue("my-value");
    assertThat(valueCredentialData.getEncryptedValueData().getEncryptedValue(), notNullValue());
    assertThat(valueCredentialData.getEncryptedValueData().getNonce(), notNullValue());
}
Also used : ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Test(org.junit.Test)

Example 7 with ValueCredentialVersionData

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

the class ValueCredentialVersionTest method getValue_decryptsValue.

@Test
public void getValue_decryptsValue() {
    valueCredentialData = new ValueCredentialVersionData("foo");
    subject = new ValueCredentialVersion(valueCredentialData).setEncryptor(encryptor);
    subject.setValue("my-value");
    assertThat(subject.getValue(), equalTo("my-value"));
}
Also used : ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Test(org.junit.Test)

Example 8 with ValueCredentialVersionData

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

the class EventAuditLogServiceTest method beforeEach.

@Before
public void beforeEach() {
    canaries = encryptionKeyCanaryRepository.findAll();
    mockOutCurrentTimeProvider(currentTimeProvider).accept(now.toEpochMilli());
    userContext = mockUserContext(true);
    userContextHolder.setUserContext(userContext);
    entity = new ValueCredentialVersionData("keyName");
    entity.setEncryptedValueData(new EncryptedValue(canaries.get(0).getUuid(), "value", "nonce"));
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Before(org.junit.Before)

Example 9 with ValueCredentialVersionData

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

the class CredentialVersionDataRepositoryTest method canSaveStringsOfLength7000WhichMeans7016ForGCM.

@Test
public void canSaveStringsOfLength7000WhichMeans7016ForGCM() {
    byte[] encryptedValue = new byte[7016];
    Arrays.fill(encryptedValue, (byte) 'A');
    final StringBuilder stringBuilder = new StringBuilder(7000);
    Stream.generate(() -> "a").limit(stringBuilder.capacity()).forEach(stringBuilder::append);
    ValueCredentialVersionData entity = new ValueCredentialVersionData();
    Credential credential = credentialRepository.save(new Credential(name));
    entity.setCredential(credential);
    entity.setEncryptedValueData(new EncryptedValue().setEncryptedValue(encryptedValue).setEncryptionKeyUuid(canaryUuid).setNonce("nonce".getBytes()));
    subject.save(entity);
    assertThat(subject.findFirstByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid()).getEncryptedValueData().getEncryptedValue().length, equalTo(7016));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 10 with ValueCredentialVersionData

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

ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)12 Test (org.junit.Test)8 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)4 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)4 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)3 Credential (org.cloudfoundry.credhub.entity.Credential)3 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)2 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)2 PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)2 Before (org.junit.Before)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1