use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptorTest method decrypt_decryptsEncryptedValues.
@Test
public void decrypt_decryptsEncryptedValues() throws Exception {
String expected = "the expected clear text";
EncryptedValue encryptedValue = new EncryptedValue(newUuid, "", "");
when(encryptionService.decrypt(encryptedValue)).thenReturn(expected);
String result = subject.decrypt(encryptedValue);
assertThat(result, equalTo(expected));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptorTest method encrypt_encryptsPlainTest.
@Test
public void encrypt_encryptsPlainTest() throws Exception {
String value = "some value";
EncryptedValue encrypted = mock(EncryptedValue.class);
when(encryptionService.encrypt(value)).thenReturn(encrypted);
EncryptedValue result = subject.encrypt("some value");
assertThat(result, equalTo(encrypted));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue 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);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class UserCredentialVersionTest method setPassword_encryptedProvidedPasswordOnce_andSetsCorrectValuesOnDelegate.
@Test
public void setPassword_encryptedProvidedPasswordOnce_andSetsCorrectValuesOnDelegate() {
when(encryptor.encrypt(eq(USER_PASSWORD))).thenReturn(new EncryptedValue(ENCRYPTION_KEY_UUID, ENCRYPTED_PASSWORD, NONCE));
userCredentialData = new UserCredentialVersionData(CREDENTIAL_NAME);
subject = new UserCredentialVersion(userCredentialData).setEncryptor(encryptor);
subject.setPassword(USER_PASSWORD);
verify(encryptor, times(1)).encrypt(eq(USER_PASSWORD));
assertThat(userCredentialData.getEncryptionKeyUuid(), equalTo(ENCRYPTION_KEY_UUID));
assertThat(userCredentialData.getEncryptedValueData().getEncryptedValue(), equalTo(ENCRYPTED_PASSWORD));
assertThat(userCredentialData.getNonce(), equalTo(NONCE));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class UserCredentialVersionTest method setGenerationParameters_setsEncryptedGenerationParametersAndNonce.
@Test
public void setGenerationParameters_setsEncryptedGenerationParametersAndNonce() {
when(encryptor.encrypt(eq(USER_GENERATION_PARAMS_STRING))).thenReturn(new EncryptedValue(ENCRYPTION_KEY_UUID, ENCRYPTED_GENERATION_PARAMS, PARAMETERS_NONCE));
userCredentialData = new UserCredentialVersionData(CREDENTIAL_NAME);
subject = new UserCredentialVersion(userCredentialData).setEncryptor(encryptor);
subject.setGenerationParameters(STRING_GENERATION_PARAMS);
verify(encryptor, times(1)).encrypt(eq(USER_GENERATION_PARAMS_STRING));
assertThat(userCredentialData.getEncryptedGenerationParameters().getEncryptionKeyUuid(), equalTo(ENCRYPTION_KEY_UUID));
assertThat(userCredentialData.getEncryptedGenerationParameters().getEncryptedValue(), equalTo(ENCRYPTED_GENERATION_PARAMS));
assertThat(userCredentialData.getEncryptedGenerationParameters().getNonce(), equalTo(PARAMETERS_NONCE));
}
Aggregations