blob: 79f2576f6446abdc88cd8bb38d7fbcec5cf6e3bc [file] [log] [blame]
Jane Zadorozhna9c938c62015-07-01 17:06:16 +03001# Copyright 2015 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Lance Bragstada2c4ebc2015-10-05 20:34:39 +000016import time
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030017
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030018from tempest.api.identity import base
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib.common.utils import data_utils
20from tempest.lib import exceptions
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030021from tempest import test
22
23
24class IdentityUsersTest(base.BaseIdentityV2Test):
25
26 @classmethod
27 def resource_setup(cls):
28 super(IdentityUsersTest, cls).resource_setup()
29 cls.creds = cls.os.credentials
30 cls.username = cls.creds.username
31 cls.password = cls.creds.password
32 cls.tenant_name = cls.creds.tenant_name
33
34 @test.idempotent_id('165859c9-277f-4124-9479-a7d1627b0ca7')
35 def test_user_update_own_password(self):
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030036
Andrea Frittoli (andreaf)0aa1fe12016-05-20 18:57:27 +010037 def _restore_password(client, user_id, old_pass, new_pass):
38 # Reset auth to get a new token with the new password
39 client.auth_provider.clear_auth()
40 client.auth_provider.credentials.password = new_pass
41 client.update_user_own_password(user_id, password=old_pass,
42 original_password=new_pass)
43 # Reset auth again to verify the password restore does work.
44 # Clear auth restores the original credentials and deletes
45 # cached auth data
46 client.auth_provider.clear_auth()
47 client.auth_provider.set_auth()
48
49 old_pass = self.creds.credentials.password
50 new_pass = data_utils.rand_password()
51 user_id = self.creds.credentials.user_id
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030052 # to change password back. important for allow_tenant_isolation = false
Andrea Frittoli (andreaf)0aa1fe12016-05-20 18:57:27 +010053 self.addCleanup(_restore_password, self.non_admin_users_client,
54 user_id, old_pass=old_pass, new_pass=new_pass)
55
Lance Bragstad144c2f42015-11-19 16:42:37 +000056 # user updates own password
Daniel Mellado82c83a52015-12-09 15:16:49 +000057 self.non_admin_users_client.update_user_own_password(
piyush110786980c7be2015-12-15 14:14:48 +053058 user_id, password=new_pass, original_password=old_pass)
Morgan Fainberg5b2c7452016-02-02 20:15:47 -080059 # NOTE(morganfainberg): Fernet tokens are not subsecond aware and
60 # Keystone should only be precise to the second. Sleep to ensure
Yaroslav Lobankovcbcb6112016-03-08 12:30:01 -060061 # we are passing the second boundary.
Lance Bragstada2c4ebc2015-10-05 20:34:39 +000062 time.sleep(1)
63
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030064 # check authorization with new password
65 self.non_admin_token_client.auth(self.username,
66 new_pass,
67 self.tenant_name)
68
69 # authorize with old token should lead to Unauthorized
70 self.assertRaises(exceptions.Unauthorized,
71 self.non_admin_token_client.auth_token,
Daniel Mellado82c83a52015-12-09 15:16:49 +000072 self.non_admin_users_client.token)
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030073
74 # authorize with old password should lead to Unauthorized
75 self.assertRaises(exceptions.Unauthorized,
76 self.non_admin_token_client.auth,
77 self.username,
78 old_pass,
79 self.tenant_name)