for (String pw : pwds.keySet()) {
u.changePassword(pw);
String plain = pwds.get(pw);
SimpleCredentials sc = new SimpleCredentials(u.getID(), plain.toCharArray());
CryptedSimpleCredentials cc = (CryptedSimpleCredentials) u.getCredentials();
assertTrue(cc.matches(sc));
}
// valid passwords, non-matching plain text
Map<String, String>noMatch = new HashMap<String, String>();
noMatch.put("{"+SecurityConstants.DEFAULT_DIGEST+"}", "");
noMatch.put("{"+SecurityConstants.DEFAULT_DIGEST+"}", "{"+SecurityConstants.DEFAULT_DIGEST+"}");
noMatch.put("{"+SecurityConstants.DEFAULT_DIGEST+"}any", "any");
noMatch.put("{"+SecurityConstants.DEFAULT_DIGEST+"}any", "{"+SecurityConstants.DEFAULT_DIGEST+"}any");
noMatch.put(sha1Hash, sha1Hash);
noMatch.put(md5Hash, md5Hash);
for (String pw : noMatch.keySet()) {
u.changePassword(pw);
String plain = noMatch.get(pw);
SimpleCredentials sc = new SimpleCredentials(u.getID(), plain.toCharArray());
CryptedSimpleCredentials cc = (CryptedSimpleCredentials) u.getCredentials();
assertFalse(cc.matches(sc));
}
// invalid pw string
try {
u.changePassword(null);