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);
}
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);
}
Aggregations