use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateRandomPasswordLength.
@Test
public void testGenerateRandomPasswordLength() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_01");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMinPasswordLength(5);
policy.setMaxPasswordLength(12);
for (int index = 0; index < ATTEMPTS; index++) {
String password = passwordPolicyService.generatePassword(policy);
assertTrue(password.length() >= 5);
assertTrue(password.length() <= 12);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateComplexPassword.
@Test
public void testGenerateComplexPassword() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_09");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(10);
policy.setMinPasswordLength(5);
policy.setSpecialCharBase("!");
policy.setNumberBase("123");
policy.setMinNumber(3);
policy.setMinLowerChar(2);
policy.setMinSpecialChar(2);
policy.setMinUpperChar(1);
for (int index = 0; index < ATTEMPTS * 5; index++) {
String password = passwordPolicyService.generatePassword(policy);
assertTrue(password.length() >= 8);
assertTrue(StringUtils.countMatches(password, "!") >= 2);
assertTrue(StringUtils.containsNone(password, "@#$%^&*()"));
assertTrue(StringUtils.containsNone(password, "0456789"));
assertTrue(password.matches(".*[A-Z].*{1,}"));
assertTrue(password.matches(".*[a-z].*{2,}"));
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testFailGenerateRandom.
@Test
public void testFailGenerateRandom() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_03");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(5);
String password = passwordPolicyService.generatePassword(policy);
assertTrue(password.length() <= 5);
policy.setMinNumber(2);
policy.setMinSpecialChar(2);
policy.setMinLowerChar(2);
try {
password = passwordPolicyService.generatePassword(policy);
fail("Password cant be generate");
} catch (Exception e) {
// nothing
}
policy.setMinLowerChar(1);
password = passwordPolicyService.generatePassword(policy);
assertEquals(5, password.length());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateOnlyNumbers.
@Test
public void testGenerateOnlyNumbers() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_06");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(10);
policy.setMinPasswordLength(1);
policy.setLowerCharBase("");
policy.setSpecialCharBase("");
policy.setNumberBase("0123456789");
policy.setUpperCharBase("");
for (int index = 0; index < ATTEMPTS; index++) {
try {
String password = passwordPolicyService.generatePassword(policy);
Long.parseLong(password);
} catch (Exception e) {
fail("Password must cointains only numbers: " + e.getMessage());
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateProhibited.
@Test
public void testGenerateProhibited() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_10");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(2);
policy.setMinPasswordLength(2);
policy.setSpecialCharBase("");
policy.setLowerCharBase("a");
policy.setUpperCharBase("");
policy.setNumberBase("123");
policy.setProhibitedCharacters("asd2!@#%3$");
for (int index = 0; index < ATTEMPTS; index++) {
String password = passwordPolicyService.generatePassword(policy);
assertTrue(password.length() == 2);
assertTrue(StringUtils.countMatches(password, "1") == 2);
assertTrue(StringUtils.containsNone(password, "asd2!@#%3$"));
}
}
Aggregations