mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Introduce name property for tuf.formats.ROLE_SCHEMA.
This commit is contained in:
parent
99ae000645
commit
03348f2dbb
2 changed files with 33 additions and 7 deletions
|
|
@ -267,11 +267,12 @@
|
|||
targets_directory=PATH_SCHEMA,
|
||||
backup_directory=PATH_SCHEMA))
|
||||
|
||||
# Role object in {'keyids': [keydids..], 'threshold': 1, 'paths':[filepaths..]}
|
||||
# format.
|
||||
# Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1,
|
||||
# 'paths':[filepaths..]} # format.
|
||||
ROLE_SCHEMA = SCHEMA.Object(
|
||||
object_name='role',
|
||||
keyids=SCHEMA.ListOf(KEYID_SCHEMA),
|
||||
name=SCHEMA.Optional(NAME_SCHEMA),
|
||||
threshold=THRESHOLD_SCHEMA,
|
||||
paths=SCHEMA.Optional(SCHEMA.ListOf(RELPATH_SCHEMA)))
|
||||
|
||||
|
|
@ -281,6 +282,9 @@
|
|||
key_schema=ROLENAME_SCHEMA,
|
||||
value_schema=ROLE_SCHEMA)
|
||||
|
||||
# Like ROLEDICT_SCHEMA, except that ROLE_SCHEMA instances are stored in order.
|
||||
ROLELIST_SCHEMA = SCHEMA.ListOf(ROLENAME_SCHEMA)
|
||||
|
||||
# The root: indicates root keys and top-level roles.
|
||||
ROOT_SCHEMA = SCHEMA.Object(
|
||||
object_name='root',
|
||||
|
|
@ -818,7 +822,7 @@ def make_fileinfo(length, hashes, custom=None):
|
|||
|
||||
|
||||
|
||||
def make_role_metadata(keyids, threshold, paths=None):
|
||||
def make_role_metadata(keyids, threshold, name=None, paths=None):
|
||||
"""
|
||||
<Purpose>
|
||||
Create a dictionary conforming to 'tuf.formats.ROLE_SCHEMA',
|
||||
|
|
@ -833,6 +837,9 @@ def make_role_metadata(keyids, threshold, paths=None):
|
|||
An integer denoting the number of required keys
|
||||
for the signing role.
|
||||
|
||||
name:
|
||||
A string that is the name of this role.
|
||||
|
||||
paths:
|
||||
The 'Target' role stores the paths of target files
|
||||
in its metadata file. 'paths' is a list of
|
||||
|
|
@ -856,6 +863,10 @@ def make_role_metadata(keyids, threshold, paths=None):
|
|||
role_meta = {}
|
||||
role_meta['keyids'] = keyids
|
||||
role_meta['threshold'] = threshold
|
||||
|
||||
if name is not None:
|
||||
role_meta['name'] = name
|
||||
|
||||
if paths is not None:
|
||||
role_meta['paths'] = paths
|
||||
|
||||
|
|
|
|||
|
|
@ -491,23 +491,38 @@ def test_make_role_metadata(self):
|
|||
keyids = ['123abc', 'abc123']
|
||||
threshold = 2
|
||||
paths = ['path1/', 'path2']
|
||||
name = '123'
|
||||
|
||||
ROLE_SCHEMA = tuf.formats.ROLE_SCHEMA
|
||||
make_role = tuf.formats.make_role_metadata
|
||||
self.assertTrue(ROLE_SCHEMA.matches(make_role(keyids, threshold, paths)))
|
||||
|
||||
self.assertTrue(ROLE_SCHEMA.matches(make_role(keyids, threshold)))
|
||||
self.assertTrue(ROLE_SCHEMA.matches(make_role(keyids, threshold, name=name)))
|
||||
self.assertTrue(ROLE_SCHEMA.matches(make_role(keyids, threshold, paths=paths)))
|
||||
self.assertTrue(ROLE_SCHEMA.matches(make_role(keyids, threshold, name=name, paths=paths)))
|
||||
|
||||
# Test conditions for invalid arguments.
|
||||
bad_keyids = 'bad'
|
||||
bad_threshold = 'bad'
|
||||
bad_paths = 'bad'
|
||||
bad_name = 123
|
||||
|
||||
self.assertRaises(tuf.FormatError, make_role, bad_keyids, threshold, paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, bad_threshold, paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, threshold, bad_paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, bad_keyids, threshold)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, bad_threshold)
|
||||
|
||||
self.assertRaises(tuf.FormatError, make_role, bad_keyids, threshold, paths=paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, bad_threshold, paths=paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, threshold, paths=bad_paths)
|
||||
|
||||
self.assertRaises(tuf.FormatError, make_role, bad_keyids, threshold, name=name)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, bad_threshold, name=name)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, threshold, name=bad_name)
|
||||
|
||||
self.assertRaises(tuf.FormatError, make_role, bad_keyids, threshold, name=name, paths=paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, bad_threshold, name=name, paths=paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, threshold, name=bad_name, paths=paths)
|
||||
self.assertRaises(tuf.FormatError, make_role, keyids, threshold, name=name, paths=bad_paths)
|
||||
|
||||
|
||||
|
||||
def test_get_role_class(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue