Search in sources :

Example 1 with ChangedNumberRule

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);
}
Also used : ChangedNumberRule(com.emc.storageos.security.password.rules.ChangedNumberRule) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Password(com.emc.storageos.security.password.Password) Test(org.junit.Test)

Aggregations

Password (com.emc.storageos.security.password.Password)1 ChangedNumberRule (com.emc.storageos.security.password.rules.ChangedNumberRule)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 Test (org.junit.Test)1