Search in sources :

Example 1 with JsonCredentialVersionData

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

the class JsonCredentialVersionTest method beforeEach.

@Before
public void beforeEach() throws JsonProcessingException {
    Map<String, Object> nested = new HashMap<>();
    nested.put("key", "value");
    value = new HashMap<>();
    value.put("simple", "just-a-string");
    value.put("complex", nested);
    String serializedValue = new ObjectMapper().writeValueAsString(value);
    Encryptor encryptor = mock(Encryptor.class);
    byte[] encryptedValue = "fake-encrypted-value".getBytes();
    byte[] nonce = "fake-nonce".getBytes();
    UUID canaryUuid = UUID.randomUUID();
    final EncryptedValue encryption = new EncryptedValue(canaryUuid, encryptedValue, nonce);
    when(encryptor.encrypt(serializedValue)).thenReturn(encryption);
    when(encryptor.decrypt(encryption)).thenReturn(serializedValue);
    jsonCredentialData = new JsonCredentialVersionData("Foo");
    subject = new JsonCredentialVersion(jsonCredentialData).setEncryptor(encryptor);
}
Also used : JsonCredentialVersionData(org.cloudfoundry.credhub.entity.JsonCredentialVersionData) HashMap(java.util.HashMap) UUID(java.util.UUID) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)1 JsonCredentialVersionData (org.cloudfoundry.credhub.entity.JsonCredentialVersionData)1 Before (org.junit.Before)1