From 77c0fe4a1c2bf38d08ebae02e7d7057f277fd6c7 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Wed, 29 Jan 2014 14:44:34 -0600 Subject: [PATCH] Add required properties field to rules schema Added an extra field in the JSON schema for mapping rules, that specifies which properites are required. There is a specific remote rule that may only have a type key. This ensures that no other keys are specified. Change-Id: I80f0e5b4bdc275db2d6cd06a81968cef33423a4d --- keystone/contrib/federation/utils.py | 2 +- keystone/tests/mapping_fixtures.py | 32 ++++++++++++++++++++++++++++ keystone/tests/test_v3_federation.py | 10 +++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/keystone/contrib/federation/utils.py b/keystone/contrib/federation/utils.py index 5b0b4a5473..738d5a152f 100644 --- a/keystone/contrib/federation/utils.py +++ b/keystone/contrib/federation/utils.py @@ -51,8 +51,8 @@ MAPPING_SCHEMA = { "definitions": { "empty": { "type": "object", + "required": ['type'], "properties": { - "required": ['type'], "type": { "type": "string" }, diff --git a/keystone/tests/mapping_fixtures.py b/keystone/tests/mapping_fixtures.py index ce6a5d7922..1bd33127b0 100644 --- a/keystone/tests/mapping_fixtures.py +++ b/keystone/tests/mapping_fixtures.py @@ -209,3 +209,35 @@ MAPPING_MISSING_LOCAL = { } ] } + +MAPPING_WRONG_TYPE = { + "rules": [ + { + "local": [ + { + "user": "$1" + } + ], + "remote": [ + { + "not_type": "UserName" + } + ] + } + ] +} + +MAPPING_MISSING_TYPE = { + "rules": [ + { + "local": [ + { + "user": "$1" + } + ], + "remote": [ + {} + ] + } + ] +} diff --git a/keystone/tests/test_v3_federation.py b/keystone/tests/test_v3_federation.py index de7a7405d2..ff7e517bf8 100644 --- a/keystone/tests/test_v3_federation.py +++ b/keystone/tests/test_v3_federation.py @@ -551,3 +551,13 @@ class MappingTests(FederationTests): url = self.MAPPING_URL + uuid.uuid4().hex self.put(url, expected_status=400, body={'mapping': mapping_fixtures.MAPPING_MISSING_LOCAL}) + + def test_create_mapping_missing_type(self): + url = self.MAPPING_URL + uuid.uuid4().hex + self.put(url, expected_status=400, + body={'mapping': mapping_fixtures.MAPPING_MISSING_TYPE}) + + def test_create_mapping_wrong_type(self): + url = self.MAPPING_URL + uuid.uuid4().hex + self.put(url, expected_status=400, + body={'mapping': mapping_fixtures.MAPPING_WRONG_TYPE})