diff options
| author | Zhenguo Niu <Niu.ZGlinux@gmail.com> | 2013-12-04 11:05:47 +0800 |
|---|---|---|
| committer | Dolph Mathews <dolph.mathews@gmail.com> | 2014-03-25 12:07:23 -0500 |
| commit | f121c2285f58c695030dbbc910a7114b6ea0e0d5 (patch) | |
| tree | 7aa1902a798ebdcd39e962ac2c35a14292d1fa0a /keystoneclient/tests/v3 | |
| parent | c1ddc5e199c2047f9714ab3fc223547c01ecef62 (diff) | |
| download | python-keystoneclient-f121c2285f58c695030dbbc910a7114b6ea0e0d5.tar.gz | |
Add a method for changing a user's password in v3
The new Identity API v3 resource for changing a user's password in
keystone can be utilized with:
c.users.update_password(old_password, new_password)
Change-Id: Ia887d853140a18ba75d6eb1bfde4ce2d64b7af60
Closes-Bug: 1239757
Co-Authored-By: Dolph Mathews <dolph.mathews@gmail.com>
DocImpact
Diffstat (limited to 'keystoneclient/tests/v3')
| -rw-r--r-- | keystoneclient/tests/v3/test_users.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/keystoneclient/tests/v3/test_users.py b/keystoneclient/tests/v3/test_users.py index 613e6c9..153e27a 100644 --- a/keystoneclient/tests/v3/test_users.py +++ b/keystoneclient/tests/v3/test_users.py @@ -197,3 +197,55 @@ class UserTests(utils.TestCase, utils.CrudTests): ref[attr], 'Expected different %s' % attr) self.assertEntityRequestBodyIs(req_ref) + + @httpretty.activate + def test_update_password(self): + old_password = uuid.uuid4().hex + new_password = uuid.uuid4().hex + + self.stub_url(httpretty.POST, + [self.collection_key, self.TEST_USER, 'password']) + self.client.user_id = self.TEST_USER + self.manager.update_password(old_password, new_password) + + exp_req_body = { + 'user': { + 'password': new_password, 'original_password': old_password + } + } + + self.assertEqual('/v3/users/test/password', + httpretty.last_request().path) + self.assertRequestBodyIs(json=exp_req_body) + + def test_update_password_with_bad_inputs(self): + old_password = uuid.uuid4().hex + new_password = uuid.uuid4().hex + + # users can't unset their password + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + old_password, None) + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + old_password, '') + + # users can't start with empty passwords + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + None, new_password) + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + '', new_password) + + # this wouldn't result in any change anyway + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + None, None) + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + '', '') + password = uuid.uuid4().hex + self.assertRaises(exceptions.ValidationError, + self.manager.update_password, + password, password) |
