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:
parent
9adda34914
commit
4adf01b03b
@ -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
|
||||
|
@ -66,3 +66,10 @@ group_update = {
|
||||
'minProperties': 1,
|
||||
'additionalProperties': True
|
||||
}
|
||||
|
||||
enable_user_v2 = {
|
||||
'type': 'object',
|
||||
'properties': {'enabled': parameter_types.boolean},
|
||||
'required': ['enabled'],
|
||||
'additionalProperties': False
|
||||
}
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user