blob: 29396a8b649ff4db8739179f4949cdb8c05b7462 [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
Lance Bragstada2c4ebc2015-10-05 20:34:39 +000017import time
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030018
19from tempest_lib.common.utils import data_utils
20from tempest_lib import exceptions
21
22from tempest.api.identity import base
23from tempest import manager
24from tempest import test
25
26
27class IdentityV3UsersTest(base.BaseIdentityV3Test):
28
29 @classmethod
30 def resource_setup(cls):
31 super(IdentityV3UsersTest, cls).resource_setup()
32 cls.creds = cls.os.credentials
33 cls.user_id = cls.creds.user_id
34 cls.username = cls.creds.username
35 cls.password = cls.creds.password
36
37 @test.idempotent_id('ad71bd23-12ad-426b-bb8b-195d2b635f27')
38 def test_user_update_own_password(self):
39 self.new_creds = copy.copy(self.creds.credentials)
40 self.new_creds.password = data_utils.rand_password()
41 # we need new non-admin Identity V3 Client with new credentials, since
Daniel Mellado7aea5342016-02-09 09:10:12 +000042 # current non_admin_users_client token will be revoked after updating
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030043 # password
Daniel Mellado7aea5342016-02-09 09:10:12 +000044 self.non_admin_users_client_for_cleanup = (
45 copy.copy(self.non_admin_users_client))
46 self.non_admin_users_client_for_cleanup.auth_provider = (
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030047 manager.get_auth_provider(self.new_creds))
48 user_id = self.creds.credentials.user_id
49 old_pass = self.creds.credentials.password
50 new_pass = self.new_creds.password
51 # to change password back. important for allow_tenant_isolation = false
52 self.addCleanup(
Daniel Mellado7aea5342016-02-09 09:10:12 +000053 self.non_admin_users_client_for_cleanup.update_user_password,
piyush110786983b5f92015-12-15 12:19:04 +053054 user_id,
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030055 password=old_pass,
56 original_password=new_pass)
57
Lance Bragstad144c2f42015-11-19 16:42:37 +000058 # user updates own password
Daniel Mellado7aea5342016-02-09 09:10:12 +000059 self.non_admin_users_client.update_user_password(
piyush110786983b5f92015-12-15 12:19:04 +053060 user_id, password=new_pass, original_password=old_pass)
Lance Bragstad144c2f42015-11-19 16:42:37 +000061
Lance Bragstada2c4ebc2015-10-05 20:34:39 +000062 # TODO(lbragstad): Sleeping after the response status has been checked
63 # and the body loaded as JSON allows requests to fail-fast. The sleep
64 # is necessary because keystone will err on the side of security and
65 # invalidate tokens within a small margin of error (within the same
66 # wall clock second) after a revocation event is issued (such as a
67 # password change). Remove this once keystone and Fernet support
68 # sub-second precision.
69 time.sleep(1)
70
Jane Zadorozhna9c938c62015-07-01 17:06:16 +030071 # check authorization with new password
72 self.non_admin_token.auth(user_id=self.user_id, password=new_pass)
73
74 # authorize with old token should lead to IdentityError (404 code)
75 self.assertRaises(exceptions.IdentityError,
76 self.non_admin_token.auth,
77 token=self.non_admin_client.token)
78
79 # authorize with old password should lead to Unauthorized
80 self.assertRaises(exceptions.Unauthorized,
81 self.non_admin_token.auth,
82 user_id=self.user_id,
83 password=old_pass)