Search in sources :

Example 26 with ConstraintViolation

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);
}
Also used : ManagePasswordOptionsForm(org.orcid.frontend.web.forms.ManagePasswordOptionsForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 27 with ConstraintViolation

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());
}
Also used : ManagePasswordOptionsForm(org.orcid.frontend.web.forms.ManagePasswordOptionsForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 28 with ConstraintViolation

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());
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 29 with ConstraintViolation

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);
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 30 with ConstraintViolation

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);
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Aggregations

ConstraintViolation (javax.validation.ConstraintViolation)95 Test (org.junit.Test)78 Validator (javax.validation.Validator)19 ConstraintViolationException (javax.validation.ConstraintViolationException)12 SMSMessage (org.apache.camel.component.cm.client.SMSMessage)12 ChangePasswordForm (org.orcid.frontend.web.forms.ChangePasswordForm)11 CmsDocumentBlobSegment (gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment)10 ValidatorFactory (javax.validation.ValidatorFactory)9 ManagePasswordOptionsForm (org.orcid.frontend.web.forms.ManagePasswordOptionsForm)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 CMConfiguration (org.apache.camel.component.cm.CMConfiguration)6 Set (java.util.Set)5 InitialContext (javax.naming.InitialContext)5 Session (org.hibernate.Session)5 Transaction (org.hibernate.Transaction)5 Method (java.lang.reflect.Method)4 ExecutableValidator (javax.validation.executable.ExecutableValidator)4 CamelExecutionException (org.apache.camel.CamelExecutionException)4 Exchange (org.apache.camel.Exchange)4