Search in sources :

Example 16 with StringGenerationParameters

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

the class PassayStringCredentialValueGeneratorTest method ignoresTooSmallLengthValues.

@Test
public void ignoresTooSmallLengthValues() {
    when(passwordGenerator.generatePassword(eq(subject.DEFAULT_LENGTH), anyList())).thenReturn("very-credential");
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setLength(3);
    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 17 with StringGenerationParameters

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

the class PassayStringCredentialValueGeneratorTest method canGenerateCredential.

@Test
public void canGenerateCredential() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    when(passwordGenerator.generatePassword(eq(subject.DEFAULT_LENGTH), any(List.class))).thenReturn("very-credential");
    StringCredentialValue stringCredentialValue = subject.generateCredential(generationParameters);
    assertThat(stringCredentialValue.getStringCredential(), equalTo("very-credential"));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 18 with StringGenerationParameters

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

the class UserGeneratorTest method beforeEach.

@Before
public void beforeEach() {
    UsernameGenerator usernameGenerator = mock(UsernameGenerator.class);
    PasswordCredentialGenerator passwordGenerator = mock(PasswordCredentialGenerator.class);
    CryptSaltFactory cryptSaltFactory = mock(CryptSaltFactory.class);
    passwordParameters = new StringGenerationParameters();
    userContext = null;
    subject = new UserGenerator(usernameGenerator, passwordGenerator, cryptSaltFactory);
    StringCredentialValue generatedUsername = new StringCredentialValue("fake-generated-username");
    StringCredentialValue generatedPassword = new StringCredentialValue("fake-generated-password");
    when(usernameGenerator.generateCredential()).thenReturn(generatedUsername);
    when(passwordGenerator.generateCredential(eq(passwordParameters))).thenReturn(generatedPassword);
    when(cryptSaltFactory.generateSalt(generatedPassword.getStringCredential())).thenReturn("fake-generated-salt");
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) CryptSaltFactory(org.cloudfoundry.credhub.credential.CryptSaltFactory) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 19 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutUppercase.

@Test
public void getCharacterRules_canCreateCharacterRulesWithoutUppercase() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setExcludeUpper(true);
    List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(generationParameters);
    assertThat(characterRules, iterableWithSize(2));
    assertThat(characterRules, containsInAnyOrder(usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit)));
    assertThat(characterRules, not(containsInAnyOrder(usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(CredHubCharacterData.Special), usesCharacters(CredHubCharacterData.Hex))));
}
Also used : CharacterRule(org.passay.CharacterRule) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 20 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters.

@Test
public void getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setIncludeSpecial(false);
    List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(generationParameters);
    assertThat(characterRules, iterableWithSize(3));
    assertThat(characterRules, containsInAnyOrder(usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit)));
    assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Special))));
    assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Hex))));
}
Also used : CharacterRule(org.passay.CharacterRule) 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