From bcfbeef0ca7f69ff50f40990e783d58fb9a83d30 Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Fri, 26 Jul 2019 15:44:58 +0200 Subject: [PATCH] xmlrpc test: add test for preserved > stage user When moving a preserved user to the stage area, check that the custom attributes are not lost ( = the attr for which there is no specific user_stage option). Test scenario: - add a stage user with --setattr "businesscategory=value" - activate the user, check that businesscategory is still present - delete (preserve) the user, check that attr is still present - stage the user, check that attr is still present Related: https://pagure.io/freeipa/issue/7597 Reviewed-By: Alexander Bokovoy Reviewed-By: Rob Crittenden --- ipatests/test_xmlrpc/test_stageuser_plugin.py | 64 +++++++++++++++++++ .../test_xmlrpc/tracker/stageuser_plugin.py | 5 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/ipatests/test_xmlrpc/test_stageuser_plugin.py b/ipatests/test_xmlrpc/test_stageuser_plugin.py index 9a869259d06a65722f019a19405baf53c03917e1..cc6a3b1a880acab1ffba06061be6eae229f80237 100644 --- a/ipatests/test_xmlrpc/test_stageuser_plugin.py +++ b/ipatests/test_xmlrpc/test_stageuser_plugin.py @@ -128,6 +128,17 @@ def stageduser_notposix(request): return tracker.make_fixture(request) +@pytest.fixture(scope='class') +def stageduser_customattr(request): + tracker = StageUserTracker(u'customattr', u'customattr', u'customattr', + setattr=u'businesscategory=BusinessCat') + tracker.track_create() + tracker.attrs.update( + businesscategory=[u'BusinessCat'] + ) + return tracker.make_fixture(request) + + @pytest.fixture(scope='class') def user(request): tracker = UserTracker(u'auser1', u'active', u'user') @@ -573,6 +584,59 @@ class TestPreserved(XMLRPC_test): stageduser.delete() +@pytest.mark.tier1 +class TestCustomAttr(XMLRPC_test): + """Test for pagure ticket 7597 + + When a staged user is activated, preserved and finally staged again, + the custom attributes are lost. + """ + def test_stageduser_customattr(self, stageduser_customattr): + # Create a staged user with attributes not accessible + # through the options + # --setattr is needed here + command = stageduser_customattr.make_create_command() + result = command() + stageduser_customattr.check_create(result, [u'businesscategory']) + + # Activate the staged user + user_customattr = UserTracker( + stageduser_customattr.uid, stageduser_customattr.givenname, + stageduser_customattr.sn) + user_customattr.create_from_staged(stageduser_customattr) + user_customattr.attrs[u'businesscategory'] = [u'BusinessCat'] + + command = stageduser_customattr.make_activate_command() + result = command() + user_customattr.check_activate(result) + + # Check that the user contains businesscategory + command = user_customattr.make_retrieve_command(all=True) + result = command() + assert 'BusinessCat' in result['result'][u'businesscategory'] + + # delete the user with --preserve + command = user_customattr.make_delete_command(no_preserve=False, + preserve=True) + result = command() + user_customattr.check_delete(result) + + # Check that the preserved user contains businesscategory + command = user_customattr.make_retrieve_command(all=True) + result = command() + assert 'BusinessCat' in result['result'][u'businesscategory'] + + # Move the user from preserved to stage + command = user_customattr.make_stage_command() + result = command() + stageduser_customattr.check_restore_preserved(result) + + # Check that the stage user contains businesscategory + command = stageduser_customattr.make_retrieve_command(all=True) + result = command() + assert 'BusinessCat' in result['result'][u'businesscategory'] + + @pytest.mark.tier1 class TestManagers(XMLRPC_test): def test_staged_manager(self, user, stageduser): diff --git a/ipatests/test_xmlrpc/tracker/stageuser_plugin.py b/ipatests/test_xmlrpc/tracker/stageuser_plugin.py index c2ab1d35c0b64980eae37f75db081b948c992b00..7609664ab4f3dc3d17b33c9ba4fa855f61a8b106 100644 --- a/ipatests/test_xmlrpc/tracker/stageuser_plugin.py +++ b/ipatests/test_xmlrpc/tracker/stageuser_plugin.py @@ -176,12 +176,13 @@ class StageUserTracker(KerberosAliasMixin, Tracker): self.exists = True - def check_create(self, result): + def check_create(self, result, extra_keys=()): """ Check 'stageuser-add' command result """ + expected = self.filter_attrs(self.create_keys | set(extra_keys)) assert_deepequal(dict( value=self.uid, summary=u'Added stage user "%s"' % self.uid, - result=self.filter_attrs(self.create_keys), + result=self.filter_attrs(expected), ), result) def check_delete(self, result): -- 2.20.1