blob: 3b89b66105c8645f383e94e6eca39f930cc0578b [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
16import copy
17
18from tempest_lib.common.utils import data_utils
19from tempest_lib import exceptions
20
21from tempest.api.identity import base
22from tempest import manager
23from tempest import test
24
25
26class 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 Raminenifa5591f2015-09-24 14:25:01 +053059 user_id=user_id, new_pass=new_pass, old_pass=old_pass)['access']
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030060
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)