From 110f60da8e8cbf2b83f66b4959857dc62b407f06 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 6 Aug 2008 13:00:36 -0400 Subject: 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 --- ipa-server/ipa-gui/ipagui/forms/group.py | 4 ++-- ipa-server/ipa-gui/ipagui/forms/user.py | 3 ++- ipa-server/ipa-gui/ipagui/helpers/validators.py | 28 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) (limited to 'ipa-server/ipa-gui') 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 +$'), + } -- cgit