Search in sources :

Example 11 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters 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)

Example 12 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class UserCredentialVersionTest method getGenerationParameters_returnsNullIfTheGenerationParametersAreNull.

@Test
public void getGenerationParameters_returnsNullIfTheGenerationParametersAreNull() {
    userCredentialData = new UserCredentialVersionData();
    subject = new UserCredentialVersion(userCredentialData).setEncryptor(encryptor);
    subject.setGenerationParameters(null);
    StringGenerationParameters generationParameters = subject.getGenerationParameters();
    assertThat(generationParameters, equalTo(null));
}
Also used : UserCredentialVersionData(org.cloudfoundry.credhub.entity.UserCredentialVersionData) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 13 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class UserCredentialVersionTest method getGenerationParameters_decryptsGenerationParameters.

@Test
public void getGenerationParameters_decryptsGenerationParameters() {
    final EncryptedValue parameterEncryption = new EncryptedValue(ENCRYPTION_KEY_UUID, ENCRYPTED_GENERATION_PARAMS, PARAMETERS_NONCE);
    final EncryptedValue passwordEncryption = new EncryptedValue(ENCRYPTION_KEY_UUID, ENCRYPTED_PASSWORD, NONCE);
    when(encryptor.decrypt(parameterEncryption)).thenReturn(USER_GENERATION_PARAMS_STRING);
    when(encryptor.decrypt(passwordEncryption)).thenReturn(USER_PASSWORD);
    userCredentialData = new UserCredentialVersionData().setEncryptedValueData(passwordEncryption).setEncryptedGenerationParameters(parameterEncryption);
    subject = new UserCredentialVersion(userCredentialData).setEncryptor(encryptor);
    StringGenerationParameters generationParameters = subject.getGenerationParameters();
    assertThat(generationParameters, samePropertyValuesAs(STRING_GENERATION_PARAMS));
    verify(encryptor, times(2)).decrypt(any());
}
Also used : UserCredentialVersionData(org.cloudfoundry.credhub.entity.UserCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 14 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class PassayStringCredentialValueGeneratorTest method ignoresTooLargeLengthValues.

@Test
public void ignoresTooLargeLengthValues() {
    when(passwordGenerator.generatePassword(eq(subject.DEFAULT_LENGTH), anyList())).thenReturn("very-credential");
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setLength(201);
    StringCredentialValue stringCredentialValue = subject.generateCredential(generationParameters);
    assertThat(stringCredentialValue.getStringCredential(), equalTo("very-credential"));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 15 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class PassayStringCredentialValueGeneratorTest method canGenerateCredentialWithSpecificLength.

@Test
public void canGenerateCredentialWithSpecificLength() {
    when(passwordGenerator.generatePassword(eq(42), anyList())).thenReturn("very-credential");
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setLength(42);
    StringCredentialValue stringCredentialValue = subject.generateCredential(generationParameters);
    assertThat(stringCredentialValue.getStringCredential(), equalTo("very-credential"));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Aggregations

StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)40 Test (org.junit.Test)24 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)8 CharacterRule (org.passay.CharacterRule)7 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)6 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)5 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)5 Before (org.junit.Before)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)2 UserContext (org.cloudfoundry.credhub.auth.UserContext)2 UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)2 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)2 PermissionService (org.cloudfoundry.credhub.service.PermissionService)2 PermissionedCredentialService (org.cloudfoundry.credhub.service.PermissionedCredentialService)2