public void testValidate() { String invalidLogin = ""; String validLogin = TestUtils.randomString(); String invalidPassword = "******"; String validPassword = "******"; String invalidEmail = "foobar"; String validEmail = "*****@*****.**"; String invalidPrefix = "Foo."; String validPrefix = "Sr."; // Test invalid values command.setLogin(invalidLogin); command.setEmail(invalidEmail); command.setPassword(invalidPassword); command.setPrefix(invalidPrefix); command.setFirstNames("testuser"); command.setLastName("testuser"); // We should get 4 errors (login, email, password, prefix) Object[] errors = command.validate(); assertEquals(4, errors.length); // Test valid values command.setLogin(validLogin); command.setEmail(validEmail); command.setPassword(validPassword); command.setPrefix(validPrefix); errors = command.validate(); assertEquals(0, errors.length); }
public void testStore() { Org org = UserTestUtils.findNewOrg("testorg"); String login = TestUtils.randomString(); command.setLogin(login); command.setPassword("password"); command.setEmail("*****@*****.**"); command.setPrefix("Dr."); command.setFirstNames("Chuck Norris"); command.setLastName("Texas Ranger"); command.setOrg(org); command.setCompany("Test company"); Object[] errors = command.validate(); assertEquals(0, errors.length); command.storeNewUser(); Long uid = command.getUser().getId(); assertNotNull(uid); User result = UserFactory.lookupById(uid); assertEquals(login, result.getLogin()); assertEquals(PageSizeDecorator.getDefaultPageSize(), result.getPageSize()); }
public void testLongNames() { int maxLogin = UserDefaults.get().getMaxUserLength(); int maxPassword = UserDefaults.get().getMaxPasswordLength(); int emailLength = UserDefaults.get().getMaxEmailLength(); Config.get().setString(UserDefaults.MAX_USER_LENGTH, String.valueOf(5)); Config.get().setString(UserDefaults.MAX_PASSWORD_LENGTH, String.valueOf(5)); Config.get().setString(UserDefaults.MAX_EMAIL_LENGTH, String.valueOf(5)); String invalidLogin = TestUtils.randomString(); String invalidPassword = "******"; String invalidEmail = "*****@*****.**"; String validPrefix = "Sr."; // Test invalid values command.setLogin(invalidLogin); command.setEmail(invalidEmail); command.setPassword(invalidPassword); command.setPrefix(validPrefix); command.setFirstNames("testuser"); command.setLastName("testuser"); // We should get 4 errors (login, email, password, prefix) Object[] errors = command.validate(); Config.get().setString(UserDefaults.MAX_USER_LENGTH, String.valueOf(maxLogin)); Config.get().setString(UserDefaults.MAX_PASSWORD_LENGTH, String.valueOf(maxPassword)); Config.get().setString(UserDefaults.MAX_EMAIL_LENGTH, String.valueOf(emailLength)); assertEquals(3, errors.length); }
public void testUsernameValidation() { // setup stuff required for command command.setEmail("*****@*****.**"); command.setFirstNames("testuser"); command.setLastName("testuser"); command.setPassword("validPassword"); command.setPrefix("Ms."); invalidUsername("foo&user", command); invalidUsername("joe+page", command); invalidUsername("joe user", command); invalidUsername("10%users", command); invalidUsername("joe'suser", command); invalidUsername("`eval`", command); invalidUsername("joe=page", command); invalidUsername("foo#user", command); invalidUsername("joe\"user", command); invalidUsername("機能拡張を", command); invalidUsername("shughes login", command); invalidUsername("shughes%login", command); invalidUsername(" shughes", command); invalidUsername("a p&i+u%s'e r1150586011843", command); // bug195807 validUsername("*****@*****.**", command); validUsername("a$user", command); validUsername("!@$^*()-_{}[]|\\:;?", command); validUsername("/usr/bin/ls", command); validUsername("shughes_login", command); validUsername("*****@*****.**", command); validUsername("/shughes_login", command); validUsername("/\\/\\ark", command); }
public void testValidatePasswordHasNewlineCharacter() throws Exception { command.setLogin("bilbo"); command.setEmail("*****@*****.**"); command.setPassword("aaaaa\nb"); command.setPrefix("Hr."); ValidatorError[] errors = command.validate(); assertEquals(1, errors.length); }