Add schema for enabling a user

The schema is added to ensure the payload is correctly assembled.

The route of the API is defined here:
https://github.com/openstack/keystone/blob/master/keystone/v2_crud/admin_crud.py#L134

Partially implements: bp schema-validation-extent
Change-Id: I79c95be3699cf915fc8542d2e770072970656261
Closes-Bug: #1603905
This commit is contained in:
Dave Chen 2016-07-19 14:53:36 +08:00
parent 9adda34914
commit 4adf01b03b
3 changed files with 46 additions and 0 deletions

View File

@ -174,6 +174,7 @@ class User(controller.V2Controller):
@controller.v2_deprecated
def set_user_enabled(self, request, user_id, user):
validation.lazy_validate(schema.enable_user_v2, user)
return self.update_user(request, user_id, user)
@controller.v2_deprecated

View File

@ -66,3 +66,10 @@ group_update = {
'minProperties': 1,
'additionalProperties': True
}
enable_user_v2 = {
'type': 'object',
'properties': {'enabled': parameter_types.boolean},
'required': ['enabled'],
'additionalProperties': False
}

View File

@ -1398,6 +1398,44 @@ class V2TestCase(RestfulTestCase, CoreApiTests, LegacyV2UsernameTests):
},
expected_status=http_client.OK)
def test_enable_or_disable_user(self):
token = self.get_scoped_token()
user_id = self.user_badguy['id']
self.assertFalse(self.user_badguy['enabled'])
def _admin_request(body, status):
resp = self.admin_request(
method='PUT',
path='/v2.0/users/%s/OS-KSADM/enabled' % user_id,
token=token,
body=body,
expected_status=status)
return resp
# Enable the user.
body = {'user': {'enabled': True}}
resp = _admin_request(body, http_client.OK)
self.assertTrue(resp.json['user']['enabled'])
# Disable the user.
body = {'user': {'enabled': False}}
resp = _admin_request(body, http_client.OK)
self.assertFalse(resp.json['user']['enabled'])
# Attributes other than `enabled` are not allowed.
body = {
'user': {
'description': uuid.uuid4().hex,
'name': uuid.uuid4().hex
}
}
_admin_request(body, http_client.BAD_REQUEST)
# `enabled` is boolean, type other than boolean is not allowed.
body = {'user': {'enabled': uuid.uuid4().hex}}
_admin_request(body, http_client.BAD_REQUEST)
class RevokeApiTestCase(V2TestCase):
def config_overrides(self):