Search in sources :

Example 6 with UserCredentialVersionData

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

the class UserCredentialVersionTest method getUsername_returnsUsernameFromDelegate.

@Test
public void getUsername_returnsUsernameFromDelegate() {
    subject = new UserCredentialVersion(new UserCredentialVersionData(CREDENTIAL_NAME).setUsername("test-user"));
    assertThat(subject.getUsername(), equalTo("test-user"));
}
Also used : UserCredentialVersionData(org.cloudfoundry.credhub.entity.UserCredentialVersionData) Test(org.junit.Test)

Example 7 with UserCredentialVersionData

use of org.cloudfoundry.credhub.entity.UserCredentialVersionData 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 8 with UserCredentialVersionData

use of org.cloudfoundry.credhub.entity.UserCredentialVersionData 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

UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)8 Test (org.junit.Test)8 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)5 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 UUID (java.util.UUID)1