Skip to content
Snippets Groups Projects
Commit 62b502e6 authored by srosse's avatar srosse
Browse files

no-jira: add unit test for a password checker with at least 8 characters, a...

no-jira: add unit test for a password checker with at least 8 characters, a number, a special character, a lower and upper case character
parent 8d3bde0a
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.springframework.beans.factory.annotation.Autowired;
/**
......@@ -52,6 +53,9 @@ public class ChangePasswordForm extends FormBasicController {
private String _oldpass = "";
private String _newpass = "";
@Autowired
private UserManager userManager;
/**
* @param name
......@@ -95,17 +99,23 @@ public class ChangePasswordForm extends FormBasicController {
@Override
protected boolean validateFormLogic (UserRequest ureq) {
if (!UserManager.getInstance().syntaxCheckOlatPassword(newpass1.getValue())) {
boolean allOk = true;
newpass1.clearError();
newpass2.clearError();
if (!userManager.syntaxCheckOlatPassword(newpass1.getValue())) {
newpass1.setErrorKey("form.checkPassword", null);
return false;
allOk &= false;
}
if (!newpass1.getValue().equals(newpass2.getValue())) {
newpass1.setValue("");
newpass2.setValue("");
newpass2.setErrorKey("error.password.nomatch", null);
return false;
allOk &= false;
}
return true;
return allOk & super.validateFormLogic(ureq);
}
@Override
......
......@@ -30,9 +30,11 @@ import org.junit.Test;
*/
public class UserNameAndPasswordSyntaxCheckerWithRegexpTest {
/**
* Min. 7 characters, one uppercase, one lowercase, one number
*/
@Test
public void testCustom() {
//Min. 7 characters, one uppercase, one lowercase, one number
public void testCustomPasswordCheck_upperLowerCase_number() {
UserNameAndPasswordSyntaxCheckerWithRegexp checker = new UserNameAndPasswordSyntaxCheckerWithRegexp();
checker.setPasswordRegExp("(?=^.{7,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$");
......@@ -41,4 +43,21 @@ public class UserNameAndPasswordSyntaxCheckerWithRegexpTest {
Assert.assertFalse(checker.syntaxCheckOlatPassword("Kanu#1"));//less than 7 characters
Assert.assertFalse(checker.syntaxCheckOlatPassword("Kanuunch"));//no number
}
/**
* Min. 8 characters, one uppercase, one lowercase, one number, one special character
*/
@Test
public void testCustomPasswordCheck_upperLowerCase_number_special() {
UserNameAndPasswordSyntaxCheckerWithRegexp checker = new UserNameAndPasswordSyntaxCheckerWithRegexp();
checker.setPasswordRegExp("(?=^.{8,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z])(?=.*[$@$!%*#?&]).*$");
Assert.assertTrue(checker.syntaxCheckOlatPassword("Kanu#010"));
Assert.assertTrue(checker.syntaxCheckOlatPassword("?Ryomou#010"));
Assert.assertFalse(checker.syntaxCheckOlatPassword("Kanuunc1"));
Assert.assertFalse(checker.syntaxCheckOlatPassword("Kanu#10"));//less than 8 characters
Assert.assertFalse(checker.syntaxCheckOlatPassword("Kanuunch"));//no number
Assert.assertFalse(checker.syntaxCheckOlatPassword("kanu8#10"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment