Search in sources :

Example 1 with PortalDBPropertySource

use of com.ctrip.framework.apollo.portal.service.PortalDBPropertySource in project apollo by ctripcorp.

the class AuthUserPasswordCheckerTest method testIsWeakPassword.

@Test
public void testIsWeakPassword() {
    // use default
    PortalDBPropertySource propertySource = Mockito.mock(PortalDBPropertySource.class);
    PortalConfig mock = new PortalConfig(propertySource);
    AuthUserPasswordChecker checker = new AuthUserPasswordChecker(mock);
    Map<String, Boolean> cases = new HashMap<>();
    cases.put("a1234567", false);
    cases.put("b98765432", false);
    cases.put("c11111111", false);
    cases.put("d2222222", false);
    cases.put("e3333333", false);
    cases.put("f4444444", false);
    cases.put("g5555555", false);
    cases.put("h6666666", false);
    cases.put("i7777777", false);
    cases.put("j8888888", false);
    cases.put("k9999999", false);
    cases.put("l0000000", false);
    cases.put("1q2w3e4r", false);
    cases.put("qwertyuiop1", false);
    cases.put("asdfghjkl2", false);
    cases.put("asdfghjkl3", false);
    cases.put("abcd1234", false);
    cases.put("1s39gvisk", true);
    String exceptedErrMsg = "Passwords cannot be consecutive, regular letters or numbers. And cannot be commonly used.";
    for (Entry<String, Boolean> c : cases.entrySet()) {
        CheckResult res = checker.checkWeakPassword(c.getKey());
        Assert.assertEquals(res.isSuccess(), c.getValue());
        if (!c.getValue()) {
            Assert.assertTrue(res.getMessage().startsWith(exceptedErrMsg));
        }
    }
}
Also used : PortalConfig(com.ctrip.framework.apollo.portal.component.config.PortalConfig) HashMap(java.util.HashMap) CheckResult(com.ctrip.framework.apollo.portal.util.checker.CheckResult) PortalDBPropertySource(com.ctrip.framework.apollo.portal.service.PortalDBPropertySource) AuthUserPasswordChecker(com.ctrip.framework.apollo.portal.util.checker.AuthUserPasswordChecker) Test(org.junit.Test)

Aggregations

PortalConfig (com.ctrip.framework.apollo.portal.component.config.PortalConfig)1 PortalDBPropertySource (com.ctrip.framework.apollo.portal.service.PortalDBPropertySource)1 AuthUserPasswordChecker (com.ctrip.framework.apollo.portal.util.checker.AuthUserPasswordChecker)1 CheckResult (com.ctrip.framework.apollo.portal.util.checker.CheckResult)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1