Prevent the creation on users and groups with numeric characters only

Update regular expression validator to prevent user and group creation.

Fixes: https://pagure.io/freeipa/issue/7572

Signed-off-by: Armando Neto <abiagion@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Armando Neto 2018-06-25 14:30:24 -03:00
parent 81f36df7ac
commit d622be295a
3 changed files with 42 additions and 1 deletions

View File

@ -288,7 +288,9 @@ RENEWAL_REUSE_CA_NAME = 'dogtag-ipa-ca-renew-agent-reuse'
CA_DBUS_TIMEOUT = 120 CA_DBUS_TIMEOUT = 120
# regexp definitions # regexp definitions
PATTERN_GROUPUSER_NAME = '^[a-zA-Z0-9_.][a-zA-Z0-9_.-]*[a-zA-Z0-9_.$-]?$' PATTERN_GROUPUSER_NAME = (
'(?!^[0-9]+$)^[a-zA-Z0-9_.][a-zA-Z0-9_.-]*[a-zA-Z0-9_.$-]?$'
)
# Kerberos Anonymous principal name # Kerberos Anonymous principal name
ANON_USER = 'WELLKNOWN/ANONYMOUS' ANON_USER = 'WELLKNOWN/ANONYMOUS'

View File

@ -169,6 +169,26 @@ class TestGroup(XMLRPC_test):
error=u'may only include letters, numbers, _, -, . and $')): error=u'may only include letters, numbers, _, -, . and $')):
command() command()
def test_create_with_name_starting_with_numeric(self):
"""Successfully create a group with name starting with numeric chars"""
testgroup = GroupTracker(
name=u'1234group',
description=u'Group name starting with numeric chars',
)
testgroup.create()
testgroup.delete()
def test_create_with_numeric_only_group_name(self):
"""Try to create a group with name only contains numeric chars"""
testgroup = GroupTracker(
name=u'1234', description=u'Numeric only group name',
)
with raises_exact(errors.ValidationError(
name='group_name',
error=u'may only include letters, numbers, _, -, . and $',
)):
testgroup.create()
@pytest.mark.tier1 @pytest.mark.tier1
class TestFindGroup(XMLRPC_test): class TestFindGroup(XMLRPC_test):

View File

@ -644,6 +644,25 @@ class TestCreate(XMLRPC_test):
with raises_exact(errors.ManagedGroupExistsError(group=group.cn)): with raises_exact(errors.ManagedGroupExistsError(group=group.cn)):
command() command()
def test_create_with_username_starting_with_numeric(self):
"""Successfully create a user with name starting with numeric chars"""
testuser = UserTracker(
name=u'1234user', givenname=u'First1234', sn=u'Surname1234',
)
testuser.create()
testuser.delete()
def test_create_with_numeric_only_username(self):
"""Try to create a user with name only contains numeric chars"""
testuser = UserTracker(
name=u'1234', givenname=u'NumFirst1234', sn=u'NumSurname1234',
)
with raises_exact(errors.ValidationError(
name=u'login',
error=u'may only include letters, numbers, _, -, . and $',
)):
testuser.create()
@pytest.mark.tier1 @pytest.mark.tier1
class TestUserWithGroup(XMLRPC_test): class TestUserWithGroup(XMLRPC_test):