From 387ee6e60f398efcdaf91c8097794ed24179150d Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Thu, 26 Sep 2019 12:19:23 +0200 Subject: [PATCH] ipatests: add XMLRPC test for user-add when UPG plugin is disabled Add a new XMLRPC test in test_user_plugin: - disable the UPG plugin - create a user without the --gid parameter as the default group for new users is not POSIX (ipausers), the command is expected to fail - create a user with the --gid parameter The provided gid is used and command is expected to succeed - create a user with the same name as an existing group As the UPG plugin is disabled, the user creation will not trigger the creation of a group with the same name, and command is expected to succeed - re-enable the UPG plugin for other tests Related to: https://pagure.io/freeipa/issue/4972 Reviewed-By: Rob Crittenden --- ipatests/test_xmlrpc/test_user_plugin.py | 81 ++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/ipatests/test_xmlrpc/test_user_plugin.py b/ipatests/test_xmlrpc/test_user_plugin.py index f867b042d..a8b46d629 100644 --- a/ipatests/test_xmlrpc/test_user_plugin.py +++ b/ipatests/test_xmlrpc/test_user_plugin.py @@ -32,6 +32,7 @@ import re from ipalib import api, errors from ipaplatform.constants import constants as platformconstants +from ipapython import ipautil from ipatests.test_xmlrpc import objectclasses from ipatests.util import ( assert_deepequal, assert_equal, assert_not_equal, raises) @@ -786,6 +787,86 @@ class TestUserWithGroup(XMLRPC_test): ) +@pytest.mark.tier1 +class TestUserWithUPGDisabled(XMLRPC_test): + """ Tests with UPG plugin disabled """ + + @classmethod + def managed_entries_upg(cls, action='enable'): + """ Change the UPG plugin state """ + assert action in ('enable', 'disable') + ipautil.run(['ipa-managed-entries', '-e', 'UPG Definition', action]) + + @classmethod + def setup_class(cls): + super(TestUserWithUPGDisabled, cls).setup_class() + cls.managed_entries_upg(action='disable') + + @classmethod + def teardown_class(cls): + cls.managed_entries_upg(action='enable') + super(TestUserWithUPGDisabled, cls).teardown_class() + + def test_create_without_upg(self): + """ Try to create user without User's Primary GID + + As the UPG plugin is disabled, the user gets assigned to the Default + Group for new users (ipausers) which is not POSIX and the command + is expected to fail + """ + testuser = UserTracker( + name=u'tuser1', givenname=u'Test', sn=u'Tuser1' + ) + command = testuser.make_create_command() + with raises_exact(errors.NotFound( + reason=u'Default group for new users is not POSIX')): + command() + + def test_create_without_upg_with_gid_set(self): + """ Create user without User's Primary GID with GID set + + The UPG plugin is disabled, but the user is provided with a group + """ + testuser = UserTracker( + name=u'tuser1', givenname=u'Test', sn=u'Tuser1', + gidnumber=1000 + ) + testuser.track_create() + del testuser.attrs['mepmanagedentry'] + testuser.attrs.update(gidnumber=[u'1000']) + testuser.attrs.update( + description=[], + objectclass=add_oc(objectclasses.user_base, u'ipantuserattrs') + ) + command = testuser.make_create_command() + result = command() + testuser.check_create(result, [u'description']) + testuser.delete() + + def test_create_where_managed_group_exists(self, user, group): + """ Create a managed group and then try to create user + with the same name the group has + + As the UPG plugin is disabled, there is no conflict + """ + group.create() + testuser = UserTracker( + name=group.cn, givenname=u'Test', sn=u'Tuser1', + gidnumber=1000 + ) + testuser.track_create() + del testuser.attrs['mepmanagedentry'] + testuser.attrs.update(gidnumber=[u'1000']) + testuser.attrs.update( + description=[], + objectclass=add_oc(objectclasses.user_base, u'ipantuserattrs') + ) + command = testuser.make_create_command() + result = command() + testuser.check_create(result, [u'description']) + testuser.delete() + + @pytest.mark.tier1 class TestManagers(XMLRPC_test): def test_assign_nonexistent_manager(self, user, user2):