From 0aa1fe1ba0661cb47514cd59a2b86c7d05bc80f5 Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Fri, 20 May 2016 18:57:27 +0100 Subject: [PATCH] Fix update_password tests The current implementation uses object shallow copy to get new credentials and clients to restore the password after update, which is fragile and a bit complicated. Using one client is enough. To restore the password we clear auth to ensure a new token is requested, set the new password temporarily, restore the password and finally reset auth again. Change-Id: I41f442ee89b1bd37dacb02b5ca276abd85981295 --- tempest/api/identity/v2/test_users.py | 35 ++++++++++++++------------- tempest/api/identity/v3/test_users.py | 35 +++++++++++++-------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tempest/api/identity/v2/test_users.py b/tempest/api/identity/v2/test_users.py index 62ddeadd7a..79f2576f64 100644 --- a/tempest/api/identity/v2/test_users.py +++ b/tempest/api/identity/v2/test_users.py @@ -13,13 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import copy import time from tempest.api.identity import base from tempest.lib.common.utils import data_utils from tempest.lib import exceptions -from tempest import manager from tempest import test @@ -35,23 +33,26 @@ class IdentityUsersTest(base.BaseIdentityV2Test): @test.idempotent_id('165859c9-277f-4124-9479-a7d1627b0ca7') def test_user_update_own_password(self): - self.new_creds = copy.copy(self.creds.credentials) - self.new_creds.password = data_utils.rand_password() - # we need new non-admin Identity Client with new credentials, since - # current non_admin_client token will be revoked after updating - # password - self.non_admin_users_client_for_cleanup = copy.copy( - self.non_admin_users_client) - self.non_admin_users_client_for_cleanup.auth_provider = ( - manager.get_auth_provider(self.new_creds)) - user_id = self.creds.credentials.user_id - old_pass = self.creds.credentials.password - new_pass = self.new_creds.password + def _restore_password(client, user_id, old_pass, new_pass): + # Reset auth to get a new token with the new password + client.auth_provider.clear_auth() + client.auth_provider.credentials.password = new_pass + client.update_user_own_password(user_id, password=old_pass, + original_password=new_pass) + # Reset auth again to verify the password restore does work. + # Clear auth restores the original credentials and deletes + # cached auth data + client.auth_provider.clear_auth() + client.auth_provider.set_auth() + + old_pass = self.creds.credentials.password + new_pass = data_utils.rand_password() + user_id = self.creds.credentials.user_id # to change password back. important for allow_tenant_isolation = false - self.addCleanup( - self.non_admin_users_client_for_cleanup.update_user_own_password, - user_id, original_password=new_pass, password=old_pass) + self.addCleanup(_restore_password, self.non_admin_users_client, + user_id, old_pass=old_pass, new_pass=new_pass) + # user updates own password self.non_admin_users_client.update_user_own_password( user_id, password=new_pass, original_password=old_pass) diff --git a/tempest/api/identity/v3/test_users.py b/tempest/api/identity/v3/test_users.py index 60fbe12205..76b46c0e90 100644 --- a/tempest/api/identity/v3/test_users.py +++ b/tempest/api/identity/v3/test_users.py @@ -13,13 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import copy import time from tempest.api.identity import base from tempest.lib.common.utils import data_utils from tempest.lib import exceptions -from tempest import manager from tempest import test @@ -35,24 +33,25 @@ class IdentityV3UsersTest(base.BaseIdentityV3Test): @test.idempotent_id('ad71bd23-12ad-426b-bb8b-195d2b635f27') def test_user_update_own_password(self): - self.new_creds = copy.copy(self.creds.credentials) - self.new_creds.password = data_utils.rand_password() - # we need new non-admin Identity V3 Client with new credentials, since - # current non_admin_users_client token will be revoked after updating - # password - self.non_admin_users_client_for_cleanup = ( - copy.copy(self.non_admin_users_client)) - self.non_admin_users_client_for_cleanup.auth_provider = ( - manager.get_auth_provider(self.new_creds)) - user_id = self.creds.credentials.user_id + + def _restore_password(client, user_id, old_pass, new_pass): + # Reset auth to get a new token with the new password + client.auth_provider.clear_auth() + client.auth_provider.credentials.password = new_pass + client.update_user_password(user_id, password=old_pass, + original_password=new_pass) + # Reset auth again to verify the password restore does work. + # Clear auth restores the original credentials and deletes + # cached auth data + client.auth_provider.clear_auth() + client.auth_provider.set_auth() + old_pass = self.creds.credentials.password - new_pass = self.new_creds.password + new_pass = data_utils.rand_password() + user_id = self.creds.credentials.user_id # to change password back. important for allow_tenant_isolation = false - self.addCleanup( - self.non_admin_users_client_for_cleanup.update_user_password, - user_id, - password=old_pass, - original_password=new_pass) + self.addCleanup(_restore_password, self.non_admin_users_client, + user_id, old_pass=old_pass, new_pass=new_pass) # user updates own password self.non_admin_users_client.update_user_password(