summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2012-04-03 09:23:39 -0400
committerRob Crittenden <rcritten@redhat.com>2012-04-08 17:10:27 -0400
commit9e2ee3ecb5489e2393763857e50485aa588872e9 (patch)
treeeed0059a4398063736eb6e52a572fb6dbc78c279
parentd925ebae6df628a4aa3e8aa1c8146d697ad7e5fe (diff)
downloadfreeipa.git-9e2ee3ecb5489e2393763857e50485aa588872e9.tar.gz
freeipa.git-9e2ee3ecb5489e2393763857e50485aa588872e9.tar.xz
freeipa.git-9e2ee3ecb5489e2393763857e50485aa588872e9.zip
Check configured maximum user login length on user rename.
ticket 2587
-rw-r--r--ipalib/plugins/user.py10
-rw-r--r--tests/test_xmlrpc/test_user_plugin.py7
2 files changed, 17 insertions, 0 deletions
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index a1afe40a..5b20984c 100644
--- a/ipalib/plugins/user.py
+++ b/ipalib/plugins/user.py
@@ -551,6 +551,16 @@ class user_mod(LDAPUpdate):
has_output_params = LDAPUpdate.has_output_params + user_output_params
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
+ if 'rename' in options:
+ config = ldap.get_ipa_config()[1]
+ if 'ipamaxusernamelength' in config:
+ if len(options['rename']) > int(config.get('ipamaxusernamelength')[0]):
+ raise errors.ValidationError(
+ name=self.obj.primary_key.cli_name,
+ error=_('can be at most %(len)d characters') % dict(
+ len = int(config.get('ipamaxusernamelength')[0])
+ )
+ )
if 'mail' in entry_attrs:
entry_attrs['mail'] = self.obj._normalize_email(entry_attrs['mail'])
if 'manager' in entry_attrs:
diff --git a/tests/test_xmlrpc/test_user_plugin.py b/tests/test_xmlrpc/test_user_plugin.py
index 8bd2d163..3fcd10a1 100644
--- a/tests/test_xmlrpc/test_user_plugin.py
+++ b/tests/test_xmlrpc/test_user_plugin.py
@@ -686,6 +686,13 @@ class test_user(Declarative):
dict(
+ desc='Try to rename to a username that is too long %r' % user1,
+ command=('user_mod', [user1], dict(rename=invaliduser2)),
+ expected=errors.ValidationError(name='uid', error='can be at most 33 characters'),
+ ),
+
+
+ dict(
desc='Create %r' % group1,
command=(
'group_add', [group1], dict(description=u'Test desc')