Search in sources :

Example 21 with EncryptionKeyCanary

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

the class EncryptionKeyCanaryDataServiceTest method save_savesTheEncryptionCanary.

@Test
public void save_savesTheEncryptionCanary() {
    EncryptionKeyCanary encryptionKeyCanary = new EncryptionKeyCanary();
    encryptionKeyCanary.setNonce("test-nonce".getBytes());
    encryptionKeyCanary.setEncryptedCanaryValue("test-value".getBytes());
    subject.save(encryptionKeyCanary);
    List<EncryptionKeyCanary> canaries = subject.findAll();
    assertThat(canaries, hasSize(1));
    EncryptionKeyCanary actual = canaries.get(0);
    assertNotNull(actual.getUuid());
    assertThat(actual.getUuid(), equalTo(encryptionKeyCanary.getUuid()));
    assertThat(actual.getNonce(), equalTo("test-nonce".getBytes()));
    assertThat(actual.getEncryptedCanaryValue(), equalTo("test-value".getBytes()));
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 22 with EncryptionKeyCanary

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

the class EncryptionKeyCanaryDataServiceTest method delete_whenThereAreCanaries_deletesTheRequestedCanaries.

@Test
public void delete_whenThereAreCanaries_deletesTheRequestedCanaries() {
    EncryptionKeyCanary firstCanary = new EncryptionKeyCanary();
    EncryptionKeyCanary secondCanary = new EncryptionKeyCanary();
    EncryptionKeyCanary thirdCanary = new EncryptionKeyCanary();
    firstCanary = subject.save(firstCanary);
    secondCanary = subject.save(secondCanary);
    thirdCanary = subject.save(thirdCanary);
    List<EncryptionKeyCanary> canaries = subject.findAll();
    List<UUID> uuids = canaries.stream().map(canary -> canary.getUuid()).collect(Collectors.toList());
    assertThat(canaries, hasSize(3));
    assertThat(uuids, containsInAnyOrder(firstCanary.getUuid(), secondCanary.getUuid(), thirdCanary.getUuid()));
    subject.delete(newArrayList(firstCanary.getUuid(), thirdCanary.getUuid()));
    canaries = subject.findAll();
    uuids = canaries.stream().map(canary -> canary.getUuid()).collect(Collectors.toList());
    assertThat(canaries, hasSize(1));
    assertThat(uuids, containsInAnyOrder(secondCanary.getUuid()));
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) EncryptionKeyCanaryRepository(org.cloudfoundry.credhub.repository.EncryptionKeyCanaryRepository) RunWith(org.junit.runner.RunWith) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) ActiveProfiles(org.springframework.test.context.ActiveProfiles) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) AutoConfigureTestDatabase(org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase) Replace(org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace) SpringRunner(org.springframework.test.context.junit4.SpringRunner) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DatabaseProfileResolver(org.cloudfoundry.credhub.util.DatabaseProfileResolver) Before(org.junit.Before) EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) UUID(java.util.UUID) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)22 Test (org.junit.Test)13 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)4 Before (org.junit.Before)4 Key (java.security.Key)3 UUID (java.util.UUID)3 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 EncryptionKeyMetadata (org.cloudfoundry.credhub.config.EncryptionKeyMetadata)2 EncryptionKeyCanaryRepository (org.cloudfoundry.credhub.repository.EncryptionKeyCanaryRepository)2 DatabaseProfileResolver (org.cloudfoundry.credhub.util.DatabaseProfileResolver)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)2 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)2 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 RunWith (org.junit.runner.RunWith)2