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 | |
| 16 | import copy |
Lance Bragstad | a2c4ebc | 2015-10-05 20:34:39 +0000 | [diff] [blame] | 17 | import time |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 18 | |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 19 | from tempest.api.identity import base |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
| 21 | from tempest.lib import exceptions |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 22 | from tempest import manager |
| 23 | from tempest import test |
| 24 | |
| 25 | |
| 26 | class IdentityV3UsersTest(base.BaseIdentityV3Test): |
| 27 | |
| 28 | @classmethod |
| 29 | def resource_setup(cls): |
| 30 | super(IdentityV3UsersTest, cls).resource_setup() |
| 31 | cls.creds = cls.os.credentials |
| 32 | cls.user_id = cls.creds.user_id |
| 33 | cls.username = cls.creds.username |
| 34 | cls.password = cls.creds.password |
| 35 | |
| 36 | @test.idempotent_id('ad71bd23-12ad-426b-bb8b-195d2b635f27') |
| 37 | def test_user_update_own_password(self): |
| 38 | self.new_creds = copy.copy(self.creds.credentials) |
| 39 | self.new_creds.password = data_utils.rand_password() |
| 40 | # we need new non-admin Identity V3 Client with new credentials, since |
Daniel Mellado | 7aea534 | 2016-02-09 09:10:12 +0000 | [diff] [blame] | 41 | # current non_admin_users_client token will be revoked after updating |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 42 | # password |
Daniel Mellado | 7aea534 | 2016-02-09 09:10:12 +0000 | [diff] [blame] | 43 | self.non_admin_users_client_for_cleanup = ( |
| 44 | copy.copy(self.non_admin_users_client)) |
| 45 | self.non_admin_users_client_for_cleanup.auth_provider = ( |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 46 | manager.get_auth_provider(self.new_creds)) |
| 47 | user_id = self.creds.credentials.user_id |
| 48 | old_pass = self.creds.credentials.password |
| 49 | new_pass = self.new_creds.password |
| 50 | # to change password back. important for allow_tenant_isolation = false |
| 51 | self.addCleanup( |
Daniel Mellado | 7aea534 | 2016-02-09 09:10:12 +0000 | [diff] [blame] | 52 | self.non_admin_users_client_for_cleanup.update_user_password, |
piyush110786 | 983b5f9 | 2015-12-15 12:19:04 +0530 | [diff] [blame] | 53 | user_id, |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 54 | password=old_pass, |
| 55 | original_password=new_pass) |
| 56 | |
Lance Bragstad | 144c2f4 | 2015-11-19 16:42:37 +0000 | [diff] [blame] | 57 | # user updates own password |
Daniel Mellado | 7aea534 | 2016-02-09 09:10:12 +0000 | [diff] [blame] | 58 | self.non_admin_users_client.update_user_password( |
piyush110786 | 983b5f9 | 2015-12-15 12:19:04 +0530 | [diff] [blame] | 59 | user_id, password=new_pass, original_password=old_pass) |
Lance Bragstad | 144c2f4 | 2015-11-19 16:42:37 +0000 | [diff] [blame] | 60 | |
Morgan Fainberg | 5b2c745 | 2016-02-02 20:15:47 -0800 | [diff] [blame] | 61 | # NOTE(morganfainberg): Fernet tokens are not subsecond aware and |
| 62 | # Keystone should only be precise to the second. Sleep to ensure |
Yaroslav Lobankov | cbcb611 | 2016-03-08 12:30:01 -0600 | [diff] [blame^] | 63 | # we are passing the second boundary. |
Lance Bragstad | a2c4ebc | 2015-10-05 20:34:39 +0000 | [diff] [blame] | 64 | time.sleep(1) |
| 65 | |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 66 | # check authorization with new password |
| 67 | self.non_admin_token.auth(user_id=self.user_id, password=new_pass) |
| 68 | |
| 69 | # authorize with old token should lead to IdentityError (404 code) |
| 70 | self.assertRaises(exceptions.IdentityError, |
| 71 | self.non_admin_token.auth, |
| 72 | token=self.non_admin_client.token) |
| 73 | |
| 74 | # authorize with old password should lead to Unauthorized |
| 75 | self.assertRaises(exceptions.Unauthorized, |
| 76 | self.non_admin_token.auth, |
| 77 | user_id=self.user_id, |
| 78 | password=old_pass) |