Search in sources :

Example 1 with JsonObjectMapper

use of org.cloudfoundry.credhub.util.JsonObjectMapper in project credhub by cloudfoundry-incubator.

the class CredentialFactoryTest method setup.

@Before
public void setup() throws JsonProcessingException {
    Encryptor encryptor = mock(Encryptor.class);
    subject = new CredentialFactory(encryptor);
    objectMapper = new JsonObjectMapper();
    generationParameters = new StringGenerationParameters().setExcludeNumber(true).setLength(PLAINTEXT_VALUE.length());
    UUID encryptionKeyUuid = UUID.randomUUID();
    EncryptedValue encryption = new EncryptedValue(encryptionKeyUuid, PLAINTEXT_VALUE.getBytes(), "test-nonce".getBytes());
    when(encryptor.encrypt(PLAINTEXT_VALUE)).thenReturn(encryption);
    when(encryptor.decrypt(encryption)).thenReturn(PLAINTEXT_VALUE);
    String generationParametersJsonString = objectMapper.writeValueAsString(generationParameters);
    EncryptedValue parametersEncryption = new EncryptedValue(encryptionKeyUuid, "test-parameters".getBytes(), "test-parameters-nonce".getBytes());
    when(encryptor.encrypt(generationParametersJsonString)).thenReturn(parametersEncryption);
    when(encryptor.decrypt(parametersEncryption)).thenReturn(generationParametersJsonString);
    EncryptedValue jsonEncryption = new EncryptedValue(encryptionKeyUuid, jsonValueJsonString.getBytes(), "test-nonce".getBytes());
    when(encryptor.encrypt(jsonValueJsonString)).thenReturn(jsonEncryption);
    when(encryptor.decrypt(jsonEncryption)).thenReturn(jsonValueJsonString);
}
Also used : JsonObjectMapper(org.cloudfoundry.credhub.util.JsonObjectMapper) UUID(java.util.UUID) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 2 with JsonObjectMapper

use of org.cloudfoundry.credhub.util.JsonObjectMapper in project credhub by cloudfoundry-incubator.

the class PasswordCredentialVersionTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    canaryUuid = UUID.randomUUID();
    encryptor = mock(Encryptor.class);
    encryptedValue = "fake-encrypted-value".getBytes();
    nonce = "fake-nonce".getBytes();
    encryptedParametersValue = "fake-encrypted-parameters".getBytes();
    parametersNonce = "fake-parameters-nonce".getBytes();
    generationParameters = new StringGenerationParameters().setExcludeLower(true).setLength(10);
    String generationParametersJson = new JsonObjectMapper().writeValueAsString(generationParameters);
    when(encryptor.encrypt(null)).thenReturn(new EncryptedValue(canaryUuid, "", ""));
    final EncryptedValue encryption = new EncryptedValue(canaryUuid, encryptedValue, nonce);
    when(encryptor.encrypt(PASSWORD)).thenReturn(encryption);
    final EncryptedValue parametersEncryption = new EncryptedValue(canaryUuid, encryptedParametersValue, parametersNonce);
    when(encryptor.encrypt(eq(generationParametersJson))).thenReturn(parametersEncryption);
    when(encryptor.decrypt(encryption)).thenReturn(PASSWORD);
    when(encryptor.decrypt(parametersEncryption)).thenReturn(generationParametersJson);
    passwordCredentialData = new PasswordCredentialVersionData("/Foo");
    subject = new PasswordCredentialVersion(passwordCredentialData);
    subject.setEncryptor(encryptor);
}
Also used : JsonObjectMapper(org.cloudfoundry.credhub.util.JsonObjectMapper) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Aggregations

EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)2 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 JsonObjectMapper (org.cloudfoundry.credhub.util.JsonObjectMapper)2 Before (org.junit.Before)2 UUID (java.util.UUID)1 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)1