Search in sources :

Example 1 with EncryptionKeyCanaryDataService

use of org.cloudfoundry.credhub.data.EncryptionKeyCanaryDataService in project credhub by cloudfoundry-incubator.

the class EncryptionKeyCanaryMapperTest method beforeEach.

@Before()
public void beforeEach() throws Exception {
    encryptionKeyCanaryDataService = mock(EncryptionKeyCanaryDataService.class);
    encryptionService = mock(EncryptionService.class);
    encryptionKeysConfiguration = mock(EncryptionKeysConfiguration.class);
    keySet = new EncryptionKeySet();
    providerFactory = mock(EncryptionProviderFactory.class);
    activeCanaryUuid = UUID.randomUUID();
    existingCanaryUuid1 = UUID.randomUUID();
    existingCanaryUuid2 = UUID.randomUUID();
    unknownCanaryUuid = UUID.randomUUID();
    activeKeyData = new EncryptionKeyMetadata();
    activeKeyData.setEncryptionPassword("this-is-active");
    activeKeyData.setActive(true);
    activeKeyData.setProviderType(ProviderType.INTERNAL);
    existingKey1Data = new EncryptionKeyMetadata();
    existingKey1Data.setEncryptionPassword("existing-key-1");
    existingKey1Data.setActive(false);
    existingKey1Data.setProviderType(ProviderType.INTERNAL);
    existingKey2Data = new EncryptionKeyMetadata();
    existingKey2Data.setEncryptionPassword("existing-key-2");
    existingKey2Data.setActive(false);
    existingKey2Data.setProviderType(ProviderType.INTERNAL);
    activeKey = mock(Key.class, "active key");
    existingKey1 = mock(Key.class, "key 1");
    existingKey2 = mock(Key.class, "key 2");
    unknownKey = mock(Key.class, "key 3");
    activeKeyProxy = mock(KeyProxy.class);
    existingKey1Proxy = mock(KeyProxy.class);
    existingKey2Proxy = mock(KeyProxy.class);
    activeKeyCanary = createEncryptionCanary(activeCanaryUuid, "fake-active-encrypted-value", "fake-active-nonce", activeKey);
    existingKeyCanary1 = createEncryptionCanary(existingCanaryUuid1, "fake-existing-encrypted-value1", "fake-existing-nonce1", existingKey1);
    existingKeyCanary2 = createEncryptionCanary(existingCanaryUuid2, "fake-existing-encrypted-value2", "fake-existing-nonce2", existingKey2);
    unknownCanary = createEncryptionCanary(unknownCanaryUuid, "fake-existing-encrypted-value3", "fake-existing-nonce3", unknownKey);
    when(encryptionService.encrypt(null, activeKey, CANARY_VALUE)).thenReturn(new EncryptedValue(null, "fake-encrypted-value", "fake-nonce"));
    when(encryptionKeysConfiguration.getKeys()).thenReturn(newArrayList(existingKey1Data, activeKeyData, existingKey2Data));
    when(providerFactory.getEncryptionService(ProviderType.INTERNAL)).thenReturn(encryptionService);
    when(encryptionService.createKeyProxy(eq(activeKeyData))).thenReturn(activeKeyProxy);
    when(encryptionService.createKeyProxy(eq(existingKey1Data))).thenReturn(existingKey1Proxy);
    when(encryptionService.createKeyProxy(eq(existingKey2Data))).thenReturn(existingKey2Proxy);
    when(activeKeyProxy.matchesCanary(eq(activeKeyCanary))).thenReturn(true);
    when(existingKey1Proxy.matchesCanary(eq(existingKeyCanary1))).thenReturn(true);
    when(existingKey2Proxy.matchesCanary(eq(existingKeyCanary2))).thenReturn(true);
    when(activeKeyProxy.getKey()).thenReturn(activeKey);
    when(existingKey1Proxy.getKey()).thenReturn(existingKey1);
    when(existingKey2Proxy.getKey()).thenReturn(existingKey2);
    when(encryptionKeyCanaryDataService.findAll()).thenReturn(new ArrayList<>(asArrayList(existingKeyCanary1, activeKeyCanary, existingKeyCanary2)));
    timedRetry = mock(TimedRetry.class);
    when(timedRetry.retryEverySecondUntil(anyLong(), any(Supplier.class))).thenAnswer(answer -> {
        Supplier<Boolean> retryableOperation = answer.getArgumentAt(1, Supplier.class);
        for (int i = 0; i < 10; ++i) {
            if (retryableOperation.get()) {
                return true;
            }
        }
        return false;
    });
}
Also used : TimedRetry(org.cloudfoundry.credhub.util.TimedRetry) EncryptionKeyCanaryDataService(org.cloudfoundry.credhub.data.EncryptionKeyCanaryDataService) EncryptionKeyMetadata(org.cloudfoundry.credhub.config.EncryptionKeyMetadata) EncryptionKeysConfiguration(org.cloudfoundry.credhub.config.EncryptionKeysConfiguration) Supplier(java.util.function.Supplier) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Key(java.security.Key) Before(org.junit.Before)

Example 2 with EncryptionKeyCanaryDataService

use of org.cloudfoundry.credhub.data.EncryptionKeyCanaryDataService in project credhub by cloudfoundry-incubator.

the class KeyUsageControllerTest method beforeEach.

@Before
public void beforeEach() {
    credentialVersionDataService = mock(CredentialVersionDataService.class);
    keySet = new EncryptionKeySet();
    encryptionKeyCanaryDataService = mock(EncryptionKeyCanaryDataService.class);
    final KeyUsageController keyUsageController = new KeyUsageController(credentialVersionDataService, keySet);
    mockMvc = MockMvcBuilders.standaloneSetup(keyUsageController).alwaysDo(print()).build();
}
Also used : EncryptionKeySet(org.cloudfoundry.credhub.service.EncryptionKeySet) CredentialVersionDataService(org.cloudfoundry.credhub.data.CredentialVersionDataService) EncryptionKeyCanaryDataService(org.cloudfoundry.credhub.data.EncryptionKeyCanaryDataService) Before(org.junit.Before)

Aggregations

EncryptionKeyCanaryDataService (org.cloudfoundry.credhub.data.EncryptionKeyCanaryDataService)2 Before (org.junit.Before)2 Key (java.security.Key)1 Supplier (java.util.function.Supplier)1 EncryptionKeyMetadata (org.cloudfoundry.credhub.config.EncryptionKeyMetadata)1 EncryptionKeysConfiguration (org.cloudfoundry.credhub.config.EncryptionKeysConfiguration)1 CredentialVersionDataService (org.cloudfoundry.credhub.data.CredentialVersionDataService)1 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)1 EncryptionKeySet (org.cloudfoundry.credhub.service.EncryptionKeySet)1 TimedRetry (org.cloudfoundry.credhub.util.TimedRetry)1