use of org.cloudfoundry.credhub.config.EncryptionKeysConfiguration 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;
});
}
Aggregations