use of com.emc.storageos.security.password.rules.ChangedNumberRule in project coprhd-controller by CoprHD.
the class PasswordValidationUnitTest method changedNumberRule.
@Test
public void changedNumberRule() {
ChangedNumberRule rule = new ChangedNumberRule(4);
Password password = new Password("1122334455", "1122334455");
try {
rule.validate(password);
Assert.fail("old password same as new password, should fail");
} catch (BadRequestException e) {
logger.info(e.getServiceCode().toString());
logger.info(e.getMessage());
Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
}
try {
password = new Password("aab2334455", "1122334455");
rule.validate(password);
Assert.fail("old password 3 characters differ than new password, should fail");
} catch (BadRequestException e) {
logger.info(e.getServiceCode().toString());
logger.info(e.getMessage());
Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
}
// test change number of characters between passwords applies Levenshtein Distance
try {
password = new Password("ChangeMe", "hangeMe");
rule.validate(password);
Assert.fail("only remove 1 character from front, should fail");
} catch (BadRequestException e) {
logger.info(e.getServiceCode().toString());
logger.info(e.getMessage());
Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
}
try {
password = new Password("ChangeMe", "ChIangeMe");
rule.validate(password);
Assert.fail("only insert 1 character in the middle, should fail");
} catch (BadRequestException e) {
logger.info(e.getServiceCode().toString());
logger.info(e.getMessage());
Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
}
password = new Password("aabb334455", "1122334455");
rule.validate(password);
}
Aggregations