use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.
the class ManagePasswordOptionsValidationFormTest method testPasswordFormatValidation.
@Test
public void testPasswordFormatValidation() throws Exception {
String pwErrorMessage = "Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol";
String tooShortPassword = "pssword";
ManagePasswordOptionsForm form = new ManagePasswordOptionsForm();
form.setPassword(tooShortPassword);
Set<ConstraintViolation<ManagePasswordOptionsForm>> violations = validator.validate(form);
Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
String passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightDigitsButLowerCaseAlphaOnly = "password";
form.setPassword(eightDigitsButLowerCaseAlphaOnly);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightDigitsLowerUpperCaseButAlphaOnly = "pAssword";
form.setPassword(eightDigitsLowerUpperCaseButAlphaOnly);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightCharactersLowerUpperCaseSymbol = "pAssw%rd";
form.setPassword(eightCharactersLowerUpperCaseSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightMixedCharactersDigitsAndSymbol = "p4ssW&rd";
form.setPassword(eightMixedCharactersDigitsAndSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertNull(passwordValidationError);
String eightUpperCaseCharactersOnlyDigitsAndSymbol = "P4SSW&RD";
form.setPassword(eightUpperCaseCharactersOnlyDigitsAndSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertNull(passwordValidationError);
}
use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.
the class ManagePasswordOptionsValidationFormTest method testNonUsAsciiCharsPermitted.
@Test
public void testNonUsAsciiCharsPermitted() throws Exception {
ManagePasswordOptionsForm form = new ManagePasswordOptionsForm();
form.setPassword("ååååååå1å");
form.setRetypedPassword("ååååååå1å");
form.setSecurityQuestionId(1);
form.setSecurityQuestionAnswer("stan");
form.setVerificationNumber("9999");
Set<ConstraintViolation<ManagePasswordOptionsForm>> errors = validator.validate(form);
assertEquals("Should be no errors", 0, errors.size());
}
use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.
the class ChangePasswordFormValidatorTest method testNonUsAsciiCharsPermitted.
@Test
public void testNonUsAsciiCharsPermitted() throws Exception {
ChangePasswordForm form = new ChangePasswordForm();
form.setOldPassword("passw0rd");
form.setPassword("ååååååå1å");
form.setRetypedPassword("ååååååå1å");
Set<ConstraintViolation<ChangePasswordForm>> errors = validator.validate(form);
assertEquals("Should be no errors", 0, errors.size());
}
use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.
the class ChangePasswordFormValidatorTest method testPasswordFormMissingData.
@Test
public void testPasswordFormMissingData() {
ChangePasswordForm form = new ChangePasswordForm();
form.setOldPassword("");
form.setPassword("");
form.setRetypedPassword("");
Set<ConstraintViolation<ChangePasswordForm>> violations = validator.validate(form);
Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
String password = allErrorValues.get("password");
String confirmedPassword = allErrorValues.get("retypedPassword");
String oldPassword = allErrorValues.get("oldPassword");
assertEquals("Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol", password);
assertEquals("Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol", confirmedPassword);
assertEquals("Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol", oldPassword);
}
use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.
the class ChangePasswordFormValidatorTest method testPasswordFormatValidation.
@Test
public void testPasswordFormatValidation() throws Exception {
String pwErrorMessage = "Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol";
String tooShortPassword = "pssword";
ChangePasswordForm form = new ChangePasswordForm();
form.setPassword(tooShortPassword);
Set<ConstraintViolation<ChangePasswordForm>> violations = validator.validate(form);
Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
String passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightDigitsButLowerCaseAlphaOnly = "password";
form.setPassword(eightDigitsButLowerCaseAlphaOnly);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightDigitsLowerUpperCaseButAlphaOnly = "pAssword";
form.setPassword(eightDigitsLowerUpperCaseButAlphaOnly);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightCharactersLowerUpperCaseSymbol = "pAssw%rd";
form.setPassword(eightCharactersLowerUpperCaseSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertEquals(pwErrorMessage, passwordValidationError);
String eightMixedCharactersDigitsAndSymbol = "p4ssW&rd";
form.setPassword(eightMixedCharactersDigitsAndSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertNull(passwordValidationError);
String eightUpperCaseCharactersOnlyDigitsAndSymbol = "P4SSW&RD";
form.setPassword(eightUpperCaseCharactersOnlyDigitsAndSymbol);
violations = validator.validate(form);
allErrorValues = retrieveErrorKeyAndMessage(violations);
passwordValidationError = allErrorValues.get("password");
assertNull(passwordValidationError);
}
Aggregations