use of org.cloudfoundry.credhub.service.EncryptionKey in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method createOldKey.
private Key createOldKey() throws Exception {
final PasswordBasedKeyProxy keyProxy = new PasswordBasedKeyProxy("old-password", 1, encryptionService);
Key oldKey = keyProxy.deriveKey();
oldCanary = new EncryptionKeyCanary();
final EncryptedValue canaryEncryption = encryptionService.encrypt(null, oldKey, CANARY_VALUE);
oldCanary.setEncryptedCanaryValue(canaryEncryption.getEncryptedValue());
oldCanary.setNonce(canaryEncryption.getNonce());
oldCanary = encryptionKeyCanaryDataService.save(oldCanary);
keySet.add(new EncryptionKey(encryptionService, oldCanary.getUuid(), oldKey));
return oldKey;
}
use of org.cloudfoundry.credhub.service.EncryptionKey in project credhub by cloudfoundry-incubator.
the class KeyUsageControllerTest method getKeyUsages_getsKeyDistributionAcrossActiveInactiveAndUnknownEncryptionKeys.
@Test
public void getKeyUsages_getsKeyDistributionAcrossActiveInactiveAndUnknownEncryptionKeys() throws Exception {
final UUID activeKey = UUID.randomUUID();
final UUID knownKey = UUID.randomUUID();
final UUID unknownKey = UUID.randomUUID();
HashMap<UUID, Long> countByEncryptionKey = new HashMap<>();
countByEncryptionKey.put(activeKey, 200L);
countByEncryptionKey.put(knownKey, 10L);
countByEncryptionKey.put(unknownKey, 5L);
keySet.add(new EncryptionKey(mock(EncryptionService.class), activeKey, mock(Key.class)));
keySet.add(new EncryptionKey(mock(EncryptionService.class), knownKey, mock(Key.class)));
keySet.setActive(activeKey);
when(credentialVersionDataService.countByEncryptionKey()).thenReturn(countByEncryptionKey);
mockMvc.perform(get("/api/v1/key-usage")).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.active_key").value(200)).andExpect(jsonPath("$.inactive_keys").value(10)).andExpect(jsonPath("$.unknown_keys").value(5));
}
Aggregations