From 96a883a5ad37a922218b6d33eec7baa206622620 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Tue, 6 Dec 2016 10:09:25 -0600 Subject: [PATCH] Use consistent role schema in token response validation The tests used a different schema for the roles in the token response schema for different token scopes. The role information shouldn't change depending on the scope, so let's make the test more DRY by not redefining the role schema in multiple places. Related-Bug: 1763510 Change-Id: I58d3dc2a3306994890688d5ff40a62cdaedf378e --- keystone/tests/unit/test_v3.py | 49 +++++++++++++++------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/keystone/tests/unit/test_v3.py b/keystone/tests/unit/test_v3.py index ca3ad754e2..f06e1f0055 100644 --- a/keystone/tests/unit/test_v3.py +++ b/keystone/tests/unit/test_v3.py @@ -46,6 +46,20 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase, def generate_token_schema(self, system_scoped=False, domain_scoped=False, project_scoped=False): """Return a dictionary of token properties to validate against.""" + ROLES_SCHEMA = { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': {'type': 'string', }, + 'name': {'type': 'string', }, + }, + 'required': ['id', 'name', ], + 'additionalProperties': False, + }, + 'minItems': 1, + } + properties = { 'audit_ids': { 'type': 'array', @@ -111,34 +125,10 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase, 'all': {'type': 'boolean'} } } - properties['roles'] = { - 'type': 'array', - 'items': { - 'type': 'object', - 'properties': { - 'id': {'type': 'string', }, - 'name': {'type': 'string', }, - }, - 'required': ['id', 'name', ], - 'additionalProperties': False, - }, - 'minItems': 1, - } + properties['roles'] = ROLES_SCHEMA elif domain_scoped: properties['catalog'] = {'type': 'array'} - properties['roles'] = { - 'type': 'array', - 'items': { - 'type': 'object', - 'properties': { - 'id': {'type': 'string', }, - 'name': {'type': 'string', }, - }, - 'required': ['id', 'name', ], - 'additionalProperties': False, - }, - 'minItems': 1, - } + properties['roles'] = ROLES_SCHEMA properties['domain'] = { 'type': 'object', 'required': ['id', 'name'], @@ -151,7 +141,12 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase, elif project_scoped: properties['is_admin_project'] = {'type': 'boolean'} properties['catalog'] = {'type': 'array'} - properties['roles'] = {'type': 'array'} + # FIXME(lbragstad): Remove this in favor of the predefined + # ROLES_SCHEMA dictionary once bug 1763510 is fixed. + ROLES_SCHEMA['items']['properties']['domain_id'] = { + 'type': ['null', 'string', ], + } + properties['roles'] = ROLES_SCHEMA properties['is_domain'] = {'type': 'boolean'} properties['project'] = { 'type': ['object'],