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 |
| 17 | |
| 18 | from tempest_lib.common.utils import data_utils |
| 19 | from tempest_lib import exceptions |
| 20 | |
| 21 | from tempest.api.identity import base |
| 22 | from tempest import manager |
| 23 | from tempest import test |
| 24 | |
| 25 | |
| 26 | class IdentityUsersTest(base.BaseIdentityV2Test): |
| 27 | |
| 28 | @classmethod |
| 29 | def resource_setup(cls): |
| 30 | super(IdentityUsersTest, cls).resource_setup() |
| 31 | cls.creds = cls.os.credentials |
| 32 | cls.username = cls.creds.username |
| 33 | cls.password = cls.creds.password |
| 34 | cls.tenant_name = cls.creds.tenant_name |
| 35 | |
| 36 | @test.idempotent_id('165859c9-277f-4124-9479-a7d1627b0ca7') |
| 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 Client with new credentials, since |
| 41 | # current non_admin_client token will be revoked after updating |
| 42 | # password |
| 43 | self.non_admin_client_for_cleanup = copy.copy(self.non_admin_client) |
| 44 | self.non_admin_client_for_cleanup.auth_provider = ( |
| 45 | manager.get_auth_provider(self.new_creds)) |
| 46 | user_id = self.creds.credentials.user_id |
| 47 | old_pass = self.creds.credentials.password |
| 48 | new_pass = self.new_creds.password |
| 49 | |
| 50 | # to change password back. important for allow_tenant_isolation = false |
| 51 | self.addCleanup( |
| 52 | self.non_admin_client_for_cleanup.update_user_own_password, |
| 53 | user_id=user_id, |
| 54 | new_pass=old_pass, |
| 55 | old_pass=new_pass) |
| 56 | |
| 57 | # user updates own password |
| 58 | resp = self.non_admin_client.update_user_own_password( |
Anusha Ramineni | fa5591f | 2015-09-24 14:25:01 +0530 | [diff] [blame] | 59 | user_id=user_id, new_pass=new_pass, old_pass=old_pass)['access'] |
Jane Zadorozhna | 9c938c6 | 2015-07-01 17:06:16 +0300 | [diff] [blame] | 60 | |
| 61 | # check authorization with new token |
| 62 | self.non_admin_token_client.auth_token(resp['token']['id']) |
| 63 | # check authorization with new password |
| 64 | self.non_admin_token_client.auth(self.username, |
| 65 | new_pass, |
| 66 | self.tenant_name) |
| 67 | |
| 68 | # authorize with old token should lead to Unauthorized |
| 69 | self.assertRaises(exceptions.Unauthorized, |
| 70 | self.non_admin_token_client.auth_token, |
| 71 | self.non_admin_client.token) |
| 72 | |
| 73 | # authorize with old password should lead to Unauthorized |
| 74 | self.assertRaises(exceptions.Unauthorized, |
| 75 | self.non_admin_token_client.auth, |
| 76 | self.username, |
| 77 | old_pass, |
| 78 | self.tenant_name) |