AuthenticatorHelper { public static boolean verifyPasswordStrength(String oldPassword, String newPassword, String principalName) { if (newPassword == null || newPassword.isEmpty()) { LOG.error("verifyPasswordStrength failed because newPassword or principalName is null or empty"); return false; } else if (newPassword != null && newPassword.trim().length() < 8) { LOG.error("verifyPasswordStrength failed because newPassword is too short, should be at least 8 chars long"); return false; } else if (newPassword != null && !verifyCharSets(newPassword)) { LOG.error("verifyPasswordStrength failed because newPassword doesn't have a char from each char set"); return false; } if (principalName == null) { principalName = ""; } try { FileBasedAuthenticator.getInstance().verifyPasswordStrength(oldPassword, newPassword, getESAPIUser(principalName)); } catch (AuthenticationException e) { LOG.error("verifyPasswordStrength failed because: " + e.getUserMessage() + " " + e.getLogMessage()); return false; } return true; }  static boolean verifyPasswordStrength(String oldPassword, String newPassword, String principalName);  }
@Test public void testVerifyPasswordStrength_OK() throws AuthenticationException { assertTrue(AuthenticatorHelper.verifyPasswordStrength("test2", "aBc_123_X", "test2")); }
@Test public void testVerifyPasswordStrength_OK_newUser() throws AuthenticationException { assertTrue(AuthenticatorHelper.verifyPasswordStrength("", "aBc_123_X", "username")); }
@Test public void testVerifyPasswordStrength_OK_8Chars() throws AuthenticationException { assertTrue(AuthenticatorHelper.verifyPasswordStrength("test2", "aBcdef_1", "test2")); }
@Test public void testVerifyPasswordStrength_OK_specialChars() throws AuthenticationException { for (char special : AuthenticatorHelper.CHAR_SPECIALS) { String password = "aB178cd" + special; boolean isOK = AuthenticatorHelper.verifyPasswordStrength("test2", password, "test2"); System.out.println("password: " + password + " is OK"); if (!isOK) { System.out.println("password: " + password + " is NOK"); } assertTrue(isOK); } }
@Test public void testVerifyPasswordStrength_NOK_onlyLowerCase() { boolean isOK = AuthenticatorHelper.verifyPasswordStrength("test2", "abcdefghij", "test2"); if (!isOK) { System.out.println("testVerifyPasswordStrength_NOK_onlyLowerCase - oldPassword: " + "test2"); System.out.println("testVerifyPasswordStrength_NOK_onlyLowerCase - newPassword: " + "abcdefghij"); return; } fail(); }
@Test public void testVerifyPasswordStrength_NOK_only7Chars_tooShort() { boolean isOK = AuthenticatorHelper.verifyPasswordStrength("test2", "aB_4efg", "test2"); if (!isOK) { System.out.println("testVerifyPasswordStrength_NOK_onlyLowerAndUpperCase7Chars_tooShort: " + "aB_4efg"); return; } fail(); }
@Test public void testVerifyPasswordStrength_NOK_passwordMatchesUsernameIrrespectiveOfCase() { boolean isOK = AuthenticatorHelper.verifyPasswordStrength("abc", "t_ST2134", "t_st2134"); if (!isOK) { System.out.println("testVerifyPasswordStrength_NOK_tooSimilarWithUsername - username: " + "test2134"); System.out.println("testVerifyPasswordStrength_NOK_tooSimilarWithUsername - newPassword: " + "teST2134"); return; } fail(); }
@Test public void testVerifyPasswordStrength_NOK_tooSimilarWithOldPassword() throws AuthenticationException { boolean isOK = AuthenticatorHelper.verifyPasswordStrength("test2", "_tesT21_", "theusername"); if (!isOK) { System.out.println("testVerifyPasswordStrength_NOK_tooSimilarWithOldPassword - oldPassword: " + "test2"); System.out.println("testVerifyPasswordStrength_NOK_tooSimilarWithOldPassword - newPassword: " + "12tesT21"); return; } fail(); }
@Test public void testVerifyPasswordStrength_OK_butNoUserAvailable() throws AuthenticationException { assertTrue(AuthenticatorHelper.verifyPasswordStrength("test2", "aBcdef_1", "")); }