Author: chris.laprun(a)jboss.com
Date: 2012-03-14 13:21:09 -0400 (Wed, 14 Mar 2012)
New Revision: 8602
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java
Log:
- GTNPORTAL-2378: Improved group membership regular expression, added test cases.
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java 2012-03-14
17:19:38 UTC (rev 8601)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java 2012-03-14
17:21:09 UTC (rev 8602)
@@ -67,7 +67,8 @@
public static final String USERNAME = "username";
public static final String GROUPMEMBERSHIP = "groupmembership";
public static final String DEFAULT_LOCALIZATION_KEY =
"ExpressionValidator.msg.value-invalid";
- public static final String GROUP_MEMBERSHIP_VALIDATION_REGEX =
"^\\p{L}[\\p{L}\\d._\\-\\s*,\\s*]+$";
+ /** Note that this regular expression should actually validate comma-separated
usernames. This is not the case as some constraints (consecutive symbols for examples) are
not taken into account. */
+ public static final String GROUP_MEMBERSHIP_VALIDATION_REGEX =
"^(\\p{Lower}[\\p{Lower}\\d\\._]+)(\\s*,\\s*(\\p{Lower}[\\p{Lower}\\d\\._]+))*$";
public static final String GROUP_MEMBERSHIP_LOCALIZATION_KEY =
"UIGroupMembershipForm.msg.Invalid-char";
private static Map<String, ValidatorConfiguration> configurations = new
HashMap<String, ValidatorConfiguration>(3);
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java 2012-03-14
17:19:38 UTC (rev 8601)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java 2012-03-14
17:21:09 UTC (rev 8602)
@@ -41,7 +41,6 @@
/**
* @author <a href="mailto:haint@exoplatform.com">Nguyen Thanh
Hai</a>
- *
* @datSep 26, 2011
*/
public class TestWebuiValidator extends TestCase
@@ -115,6 +114,26 @@
assertFalse(expected(validator, "Root"));
}
+ public void validateUsernamesInGroupMembership()
+ {
+ final UserConfigurableValidator validator = new
UserConfigurableValidator(UserConfigurableValidator.GROUPMEMBERSHIP);
+ assertTrue(expected(validator, "root.gtn"));
+ assertTrue(expected(validator, "root_gtn"));
+ assertTrue(expected(validator, "root_gtn.01"));
+ assertTrue(expected(validator, "a1,foo,bar"));
+ assertTrue(expected(validator, "a1 ,\tfoo,\nbar \r"));
+ assertFalse(expected(validator, "a1 ,\tfoo,\nbar \ra"));
+ assertFalse(expected(validator, "a1 ,\tfoo,\nbar \r,a"));
+ assertFalse(expected(validator, "root_gtn_"));
+ assertFalse(expected(validator, "_root_gtn"));
+// assertFalse(expected(validator, "root__gtn")); // not taken into
account yet
+// assertFalse(expected(validator, "root._gtn")); // not taken into
account yet
+ assertFalse(expected(validator, "root--gtn"));
+ assertFalse(expected(validator, "root*gtn"));
+ assertFalse(expected(validator, "Root"));
+ assertFalse(expected(validator, "a"));
+ }
+
public void testEmailValidator()
{
Validator validator = new EmailAddressValidator();
@@ -158,7 +177,7 @@
assertFalse(expected(validator, "01"));
assertFalse(expected(validator, "-01"));
}
-
+
public void testNumberRangeValidator()
{
Validator validator = new NumberRangeValidator(-5, 5);
@@ -167,28 +186,28 @@
assertTrue(expected(validator, "0"));
assertTrue(expected(validator, "1"));
assertTrue(expected(validator, "5"));
-
+
assertFalse(expected(validator, "-10"));
assertFalse(expected(validator, "-6"));
assertFalse(expected(validator, "6"));
assertFalse(expected(validator, "10"));
}
-
+
public void testSpecialCharacterValidator()
{
- Validator validator= new SpecialCharacterValidator();
- assertTrue(expected(validator,"aAzZ caffé"));
- assertFalse(expected(validator,"aAzZ\tcaffé"));
- assertFalse(expected(validator,"aAzZ\ncaffé"));
- assertFalse(expected(validator,"aAzZ \rcaffé"));
- assertFalse(expected(validator,"\tcaffé"));
- assertFalse(expected(validator,"\ncaffé"));
- assertFalse(expected(validator,"\rcaffé"));
- assertTrue(expected(validator,"\n"));
+ Validator validator = new SpecialCharacterValidator();
+ assertTrue(expected(validator, "aAzZ caffé"));
+ assertFalse(expected(validator, "aAzZ\tcaffé"));
+ assertFalse(expected(validator, "aAzZ\ncaffé"));
+ assertFalse(expected(validator, "aAzZ \rcaffé"));
+ assertFalse(expected(validator, "\tcaffé"));
+ assertFalse(expected(validator, "\ncaffé"));
+ assertFalse(expected(validator, "\rcaffé"));
+ assertTrue(expected(validator, "\n"));
assertTrue(expected(validator, "\t"));
assertTrue(expected(validator, "\n"));
}
-
+
public void testResourceValidator()
{
Validator validator = new ResourceValidator();
@@ -196,7 +215,7 @@
assertFalse(expected(validator, "_caffé"));
assertFalse(expected(validator, "0caffé"));
}
-
+
public void testNameValidator()
{
Validator validator = new NameValidator();
@@ -204,7 +223,7 @@
assertTrue(expected(validator, "*caffé"));
assertTrue(expected(validator, "0caffé"));
}
-
+
public void testIdentifierValidator()
{
Validator validator = new IdentifierValidator();