Tests: Improve handling of rename operation by user tracker

Improving handling of rename operation by user tracker, together with
fixes for user tests, that failed as consequence.
Failures were caused by RFE Kerberos principal alias.

Some tests were rewritten, since they used "--setattr" option instead of
"--rename", and hence didn't reflect proper behaviour of the principal
aliases feature.

https://fedorahosted.org/freeipa/ticket/6024

Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
Lenka Doudova 2016-07-15 17:57:53 +02:00 committed by Martin Babinsky
parent a0d90263d6
commit 9093647f86
2 changed files with 15 additions and 25 deletions

View File

@ -316,24 +316,10 @@ class TestUpdate(XMLRPC_test):
renameduser.ensure_missing() renameduser.ensure_missing()
olduid = user.uid olduid = user.uid
# using user.update(dict(uid=value)) results in user.update(updates=dict(rename=renameduser.uid))
# OverlapError: overlapping arguments and options: ['uid']
user.attrs.update(uid=[renameduser.uid])
command = user.make_update_command(
updates=dict(setattr=(u'uid=%s' % renameduser.uid))
)
result = command()
user.check_update(result)
user.uid = renameduser.uid
# rename the test user back so it gets properly deleted # rename the test user back so it gets properly deleted
user.attrs.update(uid=[olduid]) user.update(updates=dict(rename=olduid))
command = user.make_update_command(
updates=dict(setattr=(u'uid=%s' % olduid))
)
result = command()
user.check_update(result)
user.uid = olduid
def test_rename_to_the_same_value(self, user): def test_rename_to_the_same_value(self, user):
""" Try to rename user to the same value """ """ Try to rename user to the same value """
@ -640,18 +626,13 @@ class TestUserWithGroup(XMLRPC_test):
if its manager is also renamed """ if its manager is also renamed """
renamed_name = u'renamed_npg2' renamed_name = u'renamed_npg2'
old_name = user_npg2.uid old_name = user_npg2.uid
command = user_npg2.make_update_command(dict(rename=renamed_name))
result = command() user_npg2.update(updates=dict(rename=renamed_name))
user_npg2.attrs.update(uid=[renamed_name])
user_npg2.check_update(result)
user_npg.attrs.update(manager=[renamed_name]) user_npg.attrs.update(manager=[renamed_name])
user_npg.retrieve(all=True) user_npg.retrieve(all=True)
command = user_npg2.make_command( user_npg2.update(updates=dict(rename=old_name))
'user_mod', renamed_name, **dict(rename=old_name)
)
# we rename the user back otherwise the tracker is too confused
result = command()
def test_check_if_manager_gets_removed(self, user_npg, user_npg2): def test_check_if_manager_gets_removed(self, user_npg, user_npg2):
""" Delete manager and check if it's gone from user's attributes """ """ Delete manager and check if it's gone from user's attributes """

View File

@ -196,6 +196,12 @@ class UserTracker(Tracker):
for key, value in updates.items(): for key, value in updates.items():
if value is None or value is '' or value is u'': if value is None or value is '' or value is u'':
del self.attrs[key] del self.attrs[key]
elif key == 'rename':
new_principal = u'{0}@{1}'.format(value, self.api.env.realm)
self.attrs['uid'] = [value]
self.attrs['krbcanonicalname'] = [new_principal]
if new_principal not in self.attrs['krbprincipalname']:
self.attrs['krbprincipalname'].append(new_principal)
else: else:
if type(value) is list: if type(value) is list:
self.attrs[key] = value self.attrs[key] = value
@ -212,6 +218,9 @@ class UserTracker(Tracker):
extra_keys=set(updates.keys()) | set(expected_updates.keys()) extra_keys=set(updates.keys()) | set(expected_updates.keys())
) )
if 'rename' in updates:
self.uid = self.attrs['uid'][0]
def check_create(self, result, extra_keys=()): def check_create(self, result, extra_keys=()):
""" Check 'user-add' command result """ """ Check 'user-add' command result """
expected = self.filter_attrs(self.create_keys | set(extra_keys)) expected = self.filter_attrs(self.create_keys | set(extra_keys))