Search in sources :

Example 51 with EncryptedValue

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));
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Test(org.junit.Test)

Example 52 with EncryptedValue

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));
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Test(org.junit.Test)

Example 53 with EncryptedValue

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

Example 54 with EncryptedValue

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));
}
Also used : UserCredentialVersionData(org.cloudfoundry.credhub.entity.UserCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Test(org.junit.Test)

Example 55 with EncryptedValue

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));
}
Also used : UserCredentialVersionData(org.cloudfoundry.credhub.entity.UserCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Test(org.junit.Test)

Aggregations

EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)56 Test (org.junit.Test)31 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)12 Before (org.junit.Before)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)7 Credential (org.cloudfoundry.credhub.entity.Credential)7 UUID (java.util.UUID)6 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)6 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)6 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)5 UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)5 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)5 ProviderException (java.security.ProviderException)4 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)4 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)4 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Key (java.security.Key)3 KeyNotFoundException (org.cloudfoundry.credhub.exceptions.KeyNotFoundException)3