Rename TARGETFILE_SCHEMA to TARGETINFO_SCHEMA

This commit is contained in:
Vladimir Diaz 2016-11-07 11:41:34 -05:00
parent 3e08ea3b0b
commit e6a4b5eef0
4 changed files with 45 additions and 44 deletions

View file

@ -124,13 +124,13 @@ def test_schemas(self):
'hashes': {'sha256': 'ABCD123'},
'custom': {'type': 'metadata'}}}),
'TARGETFILE_SCHEMA': (tuf.formats.TARGETFILE_SCHEMA,
'TARGETINFO_SCHEMA': (tuf.formats.TARGETINFO_SCHEMA,
{'filepath': 'targets/target1.gif',
'fileinfo': {'length': 1024,
'hashes': {'sha256': 'ABCD123'},
'custom': {'type': 'target'}}}),
'TARGETFILES_SCHEMA': (tuf.formats.TARGETFILES_SCHEMA,
'TARGETINFOS_SCHEMA': (tuf.formats.TARGETINFOS_SCHEMA,
[{'filepath': 'targets/target1.gif',
'fileinfo': {'length': 1024,
'hashes': {'sha256': 'ABCD123'},

View file

@ -779,13 +779,13 @@ def test_3__targets_of_role(self):
self.repository_updater.metadata['current']['targets']['targets']
# Test: normal case.
targets_list = self.repository_updater._targets_of_role('targets')
targetinfos_list = self.repository_updater._targets_of_role('targets')
# Verify that the list of targets was returned, and that it contains valid
# target files.
self.assertTrue(tuf.formats.TARGETFILES_SCHEMA.matches(targets_list))
for target in targets_list:
self.assertTrue((target['filepath'], target['fileinfo']) in six.iteritems(targets_in_metadata))
self.assertTrue(tuf.formats.TARGETINFOS_SCHEMA.matches(targetinfos_list))
for targetinfo in targetinfos_list:
self.assertTrue((targetinfo['filepath'], targetinfo['fileinfo']) in six.iteritems(targets_in_metadata))
@ -893,8 +893,8 @@ def test_5_all_targets(self):
all_targets = self.repository_updater.all_targets()
# Verify format of 'all_targets', it should correspond to
# 'TARGETFILES_SCHEMA'.
self.assertTrue(tuf.formats.TARGETFILES_SCHEMA.matches(all_targets))
# 'TARGETINFOS_SCHEMA'.
self.assertTrue(tuf.formats.TARGETINFOS_SCHEMA.matches(all_targets))
# Verify that there is a correct number of records in 'all_targets' list,
# and the expected filepaths specified in the metadata. On the targets
@ -934,7 +934,7 @@ def test_5_targets_of_role(self):
# Test: normal case.
targets_list = self.repository_updater.targets_of_role('role1')
targetinfos = self.repository_updater.targets_of_role('role1')
# Verify that the expected role files were downloaded and installed.
os.path.exists(os.path.join(self.client_metadata_current, 'targets.json'))
@ -945,9 +945,9 @@ def test_5_targets_of_role(self):
# Verify that list of targets was returned and that it contains valid
# target files.
self.assertTrue(tuf.formats.TARGETFILES_SCHEMA.matches(targets_list))
for target in targets_list:
self.assertTrue((target['filepath'], target['fileinfo']) in six.iteritems(expected_targets))
self.assertTrue(tuf.formats.TARGETINFOS_SCHEMA.matches(targetinfos))
for targetinfo in targetinfos:
self.assertTrue((targetinfo['filepath'], targetinfo['fileinfo']) in six.iteritems(expected_targets))
# Test: Invalid arguments.
@ -974,10 +974,10 @@ def test_6_target(self):
filepath, fileinfo = target_files.popitem()
target_files[filepath] = fileinfo
target_fileinfo = self.repository_updater.target(filepath)
self.assertTrue(tuf.formats.TARGETFILE_SCHEMA.matches(target_fileinfo))
self.assertEqual(target_fileinfo['filepath'], filepath)
self.assertEqual(target_fileinfo['fileinfo'], fileinfo)
target_targetinfo = self.repository_updater.target(filepath)
self.assertTrue(tuf.formats.TARGETINFO_SCHEMA.matches(target_targetinfo))
self.assertEqual(target_targetinfo['filepath'], filepath)
self.assertEqual(target_targetinfo['fileinfo'], fileinfo)
# Test: invalid target path.
self.assertRaises(tuf.UnknownTargetError, self.repository_updater.target,
@ -1072,8 +1072,8 @@ def test_6_download_target(self):
# will be used to test against download_target() and a repository with
# 'consistent_snapshot' set to True.
target_filepath1 = target_filepaths.pop()
target_fileinfo = self.repository_updater.target(target_filepath1)
self.repository_updater.download_target(target_fileinfo,
targetinfo = self.repository_updater.target(target_filepath1)
self.repository_updater.download_target(targetinfo,
destination_directory)
download_filepath = \
@ -1084,10 +1084,10 @@ def test_6_download_target(self):
# Add any 'custom' data from the repository's target fileinfo to the
# 'download_targetfileinfo' object being tested.
if 'custom' in target_fileinfo['fileinfo']:
download_targetfileinfo['custom'] = target_fileinfo['fileinfo']['custom']
if 'custom' in targetinfo['fileinfo']:
download_targetfileinfo['custom'] = targetinfo['fileinfo']['custom']
self.assertEqual(target_fileinfo['fileinfo'], download_targetfileinfo)
self.assertEqual(targetinfo['fileinfo'], download_targetfileinfo)
# Test when consistent snapshots is set. First, create a valid
# repository with consistent snapshots set (root.json contains a
@ -1119,8 +1119,8 @@ def test_6_download_target(self):
self.repository_updater.refresh()
target_filepath2 = target_filepaths.pop()
target_fileinfo2 = self.repository_updater.target(target_filepath2)
self.repository_updater.download_target(target_fileinfo2,
targetinfo2 = self.repository_updater.target(target_filepath2)
self.repository_updater.download_target(targetinfo2,
destination_directory)
# Test: Invalid arguments.
@ -1128,7 +1128,7 @@ def test_6_download_target(self):
8, destination_directory)
self.assertRaises(tuf.FormatError, self.repository_updater.download_target,
target_fileinfo, 8)
targetinfo, 8)
# Test:
# Attempt a file download of a valid target, however, a download exception
@ -1141,7 +1141,7 @@ def test_6_download_target(self):
mirrors[mirror_name]['confined_target_dirs'] = [self.random_path()]
try:
self.repository_updater.download_target(target_fileinfo,
self.repository_updater.download_target(targetinfo,
destination_directory)
except tuf.NoWorkingMirrorError as exception:

View file

@ -1739,6 +1739,7 @@ def _fileinfo_has_changed(self, metadata_filename, new_fileinfo):
metadadata_filename:
The metadata filename for the role. For the 'root' role,
'metadata_filename' would be 'root.json'.
new_fileinfo:
A dict object representing the new file information for
'metadata_filename'. 'new_fileinfo' may be 'None' when
@ -1985,7 +1986,7 @@ def all_targets(self):
on the repository. This list also includes all the targets of
delegated roles. Targets of the list returned are ordered according
the trusted order of the delegated roles, where parent roles come before
children. The list conforms to 'tuf.formats.TARGETFILES_SCHEMA'
children. The list conforms to 'tuf.formats.TARGETINFOS_SCHEMA'
and has the form:
[{'filepath': 'a/b/c.txt',
@ -2008,7 +2009,7 @@ def all_targets(self):
The metadata for target roles is updated and stored.
<Returns>
A list of targets, conformant to 'tuf.formats.TARGETFILES_SCHEMA'.
A list of targets, conformant to 'tuf.formats.TARGETINFOS_SCHEMA'.
"""
# Load the most up-to-date targets of the 'targets' role and all
@ -2115,7 +2116,7 @@ def _targets_of_role(self, rolename, targets=None, skip_refresh=False):
<Purpose>
Non-public method that returns the target information of all the targets
of 'rolename'. The returned information is a list conformant to
'tuf.formats.TARGETFILES_SCHEMA', and has the form:
'tuf.formats.TARGETINFOS_SCHEMA', and has the form:
[{'filepath': 'a/b/c.txt',
'fileinfo': {'length': 13323,
@ -2129,7 +2130,7 @@ def _targets_of_role(self, rolename, targets=None, skip_refresh=False):
targets:
A list of targets containing target information, conformant to
'tuf.formats.TARGETFILES_SCHEMA'.
'tuf.formats.TARGETINFOS_SCHEMA'.
skip_refresh:
A boolean indicating if the target metadata for 'rolename'
@ -2144,7 +2145,7 @@ def _targets_of_role(self, rolename, targets=None, skip_refresh=False):
<Returns>
A list of dict objects containing the target information of all the
targets of 'rolename'. Conformant to 'tuf.formats.TARGETFILES_SCHEMA'.
targets of 'rolename'. Conformant to 'tuf.formats.TARGETINFOS_SCHEMA'.
"""
if targets is None:
@ -2186,7 +2187,7 @@ def targets_of_role(self, rolename='targets'):
<Purpose>
Return a list of trusted targets directly specified by 'rolename'.
The returned information is a list conformant to
'tuf.formats.TARGETFILES_SCHEMA', and has the form:
'tuf.formats.TARGETINFOS_SCHEMA', and has the form:
[{'filepath': 'a/b/c.txt',
'fileinfo': {'length': 13323,
@ -2216,7 +2217,7 @@ def targets_of_role(self, rolename='targets'):
The metadata of updated delegated roles are downloaded and stored.
<Returns>
A list of targets, conformant to 'tuf.formats.TARGETFILES_SCHEMA'.
A list of targets, conformant to 'tuf.formats.TARGETINFOS_SCHEMA'.
"""
# Does 'rolename' have the correct format?
@ -2259,7 +2260,7 @@ def target(self, target_filepath):
<Returns>
The target information for 'target_filepath', conformant to
'tuf.formats.TARGETFILE_SCHEMA'.
'tuf.formats.TARGETINFO_SCHEMA'.
"""
# Does 'target_filepath' have the correct format?
@ -2313,7 +2314,7 @@ def _preorder_depth_first_walk(self, target_filepath):
<Returns>
The target information for 'target_filepath', conformant to
'tuf.formats.TARGETFILE_SCHEMA'.
'tuf.formats.TARGETINFO_SCHEMA'.
"""
target = None
@ -2426,7 +2427,7 @@ def _get_target_from_targets_role(self, role_name, targets, target_filepath):
<Returns>
The target information for 'target_filepath', conformant to
'tuf.formats.TARGETFILE_SCHEMA'.
'tuf.formats.TARGETINFO_SCHEMA'.
"""
target = None
@ -2669,7 +2670,7 @@ def updated_targets(self, targets, destination_directory):
located there has mismatched file properties.
The returned information is a list conformant to
'tuf.formats.TARGETFILES_SCHEMA' and has the form:
'tuf.formats.TARGETINFOS_SCHEMA' and has the form:
[{'filepath': 'a/b/c.txt',
'fileinfo': {'length': 13323,
@ -2692,12 +2693,12 @@ def updated_targets(self, targets, destination_directory):
The files in 'targets' are read and their hashes computed.
<Returns>
A list of targets, conformant to 'tuf.formats.TARGETFILES_SCHEMA'.
A list of targets, conformant to 'tuf.formats.TARGETINFOS_SCHEMA'.
"""
# Do the arguments have the correct format?
# Raise 'tuf.FormatError' if there is a mismatch.
tuf.formats.TARGETFILES_SCHEMA.check_match(targets)
tuf.formats.TARGETINFOS_SCHEMA.check_match(targets)
tuf.formats.PATH_SCHEMA.check_match(destination_directory)
# Keep track of the target objects and filepaths of updated targets.
@ -2758,7 +2759,7 @@ def download_target(self, target, destination_directory):
<Arguments>
target:
The target to be downloaded. Conformant to
'tuf.formats.TARGETFILE_SCHEMA'.
'tuf.formats.TARGETINFO_SCHEMA'.
destination_directory:
The directory to save the downloaded target file.
@ -2786,7 +2787,7 @@ def download_target(self, target, destination_directory):
# number of objects and object types, and that all dict
# keys are properly named.
# Raise 'tuf.FormatError' if the check fail.
tuf.formats.TARGETFILE_SCHEMA.check_match(target)
tuf.formats.TARGETINFO_SCHEMA.check_match(target)
tuf.formats.PATH_SCHEMA.check_match(destination_directory)
# Extract the target file information.

View file

@ -301,13 +301,13 @@
value_schema = FILEINFO_SCHEMA)
# A dict holding a target file.
TARGETFILE_SCHEMA = SCHEMA.Object(
object_name = 'TARGETFILE_SCHEMA',
TARGETINFO_SCHEMA = SCHEMA.Object(
object_name = 'TARGETINFO_SCHEMA',
filepath = RELPATH_SCHEMA,
fileinfo = FILEINFO_SCHEMA)
# A list of TARGETFILE_SCHEMA.
TARGETFILES_SCHEMA = SCHEMA.ListOf(TARGETFILE_SCHEMA)
# A list of TARGETINFO_SCHEMA.
TARGETINFOS_SCHEMA = SCHEMA.ListOf(TARGETINFO_SCHEMA)
# A single signature of an object. Indicates the signature, the ID of the
# signing key, and the signing method.