From 25aa71d4c60280653c745850215e7ac9dd2abaef Mon Sep 17 00:00:00 2001 From: Sebastien Awwad Date: Wed, 3 Apr 2019 10:30:42 -0400 Subject: [PATCH] PR revision: test build_dict_conforming... arg for schema type Raise an error if it's not a schema.Object instance (not just if it's not a schema.Schema instance). Also adds a test for this. Signed-off-by: Sebastien Awwad --- tests/test_formats.py | 7 +++++++ tuf/formats.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_formats.py b/tests/test_formats.py index 42a354c7..25c27f28 100755 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -292,6 +292,13 @@ def test_build_dict_conforming_to_schema(self): # Test construction of a few metadata formats using # build_dict_conforming_to_schema(). + # Try the wrong type of schema object. + STRING_SCHEMA = securesystemslib.schema.AnyString() + + with self.assertRaises(ValueError): + tuf.formats.build_dict_conforming_to_schema( + STRING_SCHEMA, string='some string') + # Try building Timestamp metadata. spec_version = tuf.SPECIFICATION_VERSION version = 8 diff --git a/tuf/formats.py b/tuf/formats.py index 9846fa4f..2c5128db 100755 --- a/tuf/formats.py +++ b/tuf/formats.py @@ -516,9 +516,9 @@ def build_dict_conforming_to_schema(schema, **kwargs): """ # Check the schema argument type (must provide check_match and _required). - if not isinstance(schema, SCHEMA.Schema): + if not isinstance(schema, SCHEMA.Object): raise ValueError( - 'The first argument must be a schema.Schema object, but is not. ' + 'The first argument must be a schema.Object instance, but is not. ' 'Given schema: ' + repr(schema)) # Make a copy of the provided fields so that the caller's provided values