Search in sources :

Example 36 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_createdCharacterRulesFromDefaultParameters.

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

Example 37 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutNumbers.

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

Example 38 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithAllIncluded.

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

Example 39 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutLowercase.

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

Example 40 with StringGenerationParameters

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

the class CharacterRuleProviderTest method getCharacterRules_returnsAnEmptyListWhenAllAreExcluded.

@Test
public void getCharacterRules_returnsAnEmptyListWhenAllAreExcluded() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setIncludeSpecial(false);
    generationParameters.setExcludeNumber(true);
    generationParameters.setExcludeUpper(true);
    generationParameters.setExcludeLower(true);
    List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(generationParameters);
    assertThat(characterRules, iterableWithSize(0));
}
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