summaryrefslogtreecommitdiffstats
path: root/ipa-server/ipa-gui
diff options
context:
space:
mode:
authorRob Crittenden <rcrit@ipa.greyoak.com>2008-08-06 13:00:36 -0400
committerRob Crittenden <rcrit@ipa.greyoak.com>2008-08-07 11:21:33 -0400
commit110f60da8e8cbf2b83f66b4959857dc62b407f06 (patch)
tree17ad23d4b346d7e826f8e3755697c382ed5ac84e /ipa-server/ipa-gui
parentfbc74a0cb48e7c596eb5c03fd56c068a8e0ef29e (diff)
downloadfreeipa-110f60da8e8cbf2b83f66b4959857dc62b407f06.tar.gz
freeipa-110f60da8e8cbf2b83f66b4959857dc62b407f06.tar.xz
freeipa-110f60da8e8cbf2b83f66b4959857dc62b407f06.zip
Change user and group validators to match shadow-utils
This sets the regex to [a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]? Also change the validators to return True/False 450613, 457124
Diffstat (limited to 'ipa-server/ipa-gui')
-rw-r--r--ipa-server/ipa-gui/ipagui/forms/group.py4
-rw-r--r--ipa-server/ipa-gui/ipagui/forms/user.py3
-rw-r--r--ipa-server/ipa-gui/ipagui/helpers/validators.py28
3 files changed, 32 insertions, 3 deletions
diff --git a/ipa-server/ipa-gui/ipagui/forms/group.py b/ipa-server/ipa-gui/ipagui/forms/group.py
index 4835e9168..dc3ac0608 100644
--- a/ipa-server/ipa-gui/ipagui/forms/group.py
+++ b/ipa-server/ipa-gui/ipagui/forms/group.py
@@ -36,7 +36,7 @@ class GroupFields(object):
dn_to_info_json = widgets.HiddenField(name="dn_to_info_json")
class GroupNewValidator(validators.Schema):
- cn = validators.String(not_empty=True)
+ cn = GoodName(not_empty=True)
description = validators.String(not_empty=False)
@@ -59,7 +59,7 @@ class GroupNewForm(widgets.Form):
class GroupEditValidator(validators.Schema):
- cn = validators.String(not_empty=False)
+ cn = GoodName(not_empty=False)
gidnumber = validators.Int(not_empty=False)
description = validators.String(not_empty=False)
diff --git a/ipa-server/ipa-gui/ipagui/forms/user.py b/ipa-server/ipa-gui/ipagui/forms/user.py
index 22a49653c..62fc0dfdc 100644
--- a/ipa-server/ipa-gui/ipagui/forms/user.py
+++ b/ipa-server/ipa-gui/ipagui/forms/user.py
@@ -86,7 +86,7 @@ class UserFields(object):
custom_fields = []
class UserNewValidator(validators.Schema):
- uid = validators.PlainText(not_empty=True)
+ uid = GoodName(not_empty=True)
krbprincipalkey = validators.String(not_empty=False)
krbprincipalkey_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
@@ -129,6 +129,7 @@ class UserNewForm(widgets.Form):
super(UserNewForm,self).update_params(params)
class UserEditValidator(validators.Schema):
+ uid = GoodName(not_empty=False)
krbprincipalkey = validators.String(not_empty=False)
krbprincipalkey_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
diff --git a/ipa-server/ipa-gui/ipagui/helpers/validators.py b/ipa-server/ipa-gui/ipagui/helpers/validators.py
index 6e78781a4..27272595b 100644
--- a/ipa-server/ipa-gui/ipagui/helpers/validators.py
+++ b/ipa-server/ipa-gui/ipagui/helpers/validators.py
@@ -63,3 +63,31 @@ class UniqueList(FancyValidator):
if orig > check:
raise Invalid(self.message('notunique', state),
value, state)
+
+class GoodName(Regex):
+ """
+ Test that the field contains only letters, numbers, underscore,
+ dash, hyphen and $.
+
+ Examples::
+
+ >>> GoodName.to_python('_this9_')
+ '_this9_'
+ >>> GoodName.from_python(' this ')
+ ' this '
+ >>> GoodName(accept_python=False).from_python(' this ')
+ Traceback (most recent call last):
+ ...
+ Invalid: Enter only letters, numbers, _ (underscore), - (dash) or $')
+ >>> GoodName(strip=True).to_python(' this ')
+ 'this'
+ >>> GoodName(strip=True).from_python(' this ')
+ 'this'
+ """
+
+ regex = r"^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$"
+
+ messages = {
+ 'invalid': _('Enter only letters, numbers, _ (underscore), - (dash) or
+$'),
+ }