Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 1 | # 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 Bragstad | a2c4ebc | 2015-10-05 20:34:39 +0000 | [diff] [blame] | 16 | import time |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 17 | |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 18 | from tempest.api.identity import base |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 19 | from tempest.lib.common.utils import data_utils |
| 20 | from tempest.lib import exceptions |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 21 | from tempest import test |
| 22 | |
| 23 | |
| 24 | class 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 Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 36 | |
Andrea Frittoli (andreaf) | 0aa1fe1 | 2016-05-20 18:57:27 +0100 | [diff] [blame] | 37 | 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 Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 52 | # to change password back. important for allow_tenant_isolation = false |
Andrea Frittoli (andreaf) | 0aa1fe1 | 2016-05-20 18:57:27 +0100 | [diff] [blame] | 53 | self.addCleanup(_restore_password, self.non_admin_users_client, |
| 54 | user_id, old_pass=old_pass, new_pass=new_pass) |
| 55 | |
Lance Bragstad | 144c2f4 | 2015-11-19 16:42:37 +0000 | [diff] [blame] | 56 | # user updates own password |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 57 | self.non_admin_users_client.update_user_own_password( |
piyush110786 | 980c7be | 2015-12-15 14:14:48 +0530 | [diff] [blame] | 58 | user_id, password=new_pass, original_password=old_pass) |
Morgan Fainberg | 5b2c745 | 2016-02-02 20:15:47 -0800 | [diff] [blame] | 59 | # NOTE(morganfainberg): Fernet tokens are not subsecond aware and |
| 60 | # Keystone should only be precise to the second. Sleep to ensure |
Yaroslav Lobankov | cbcb611 | 2016-03-08 12:30:01 -0600 | [diff] [blame] | 61 | # we are passing the second boundary. |
Lance Bragstad | a2c4ebc | 2015-10-05 20:34:39 +0000 | [diff] [blame] | 62 | time.sleep(1) |
| 63 | |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 64 | # 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 Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 72 | self.non_admin_users_client.token) |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 73 | |
| 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) |