mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Merge pull request #705 from vladimir-v-diaz/forward_slashes_in_metadata
Ensure consistent style of slashes for paths in metadata
This commit is contained in:
commit
68c13abcb3
6 changed files with 13 additions and 21 deletions
|
|
@ -162,24 +162,12 @@ def test_create_new_project(self):
|
|||
|
||||
tuf.roledb.clear_roledb()
|
||||
tuf.keydb.clear_keydb()
|
||||
self.assertRaises(OSError, developer_tool.create_new_project ,project_name,
|
||||
self.assertRaises(OSError, developer_tool.create_new_project, project_name,
|
||||
metadata_directory, location_in_repository, targets_directory,
|
||||
project_key)
|
||||
|
||||
os.chmod(local_tmp, 0o0777)
|
||||
|
||||
shutil.rmtree(metadata_directory)
|
||||
os.chmod(local_tmp, 0o0555)
|
||||
|
||||
tuf.roledb.clear_roledb()
|
||||
tuf.keydb.clear_keydb()
|
||||
self.assertRaises(OSError, developer_tool.create_new_project ,project_name,
|
||||
metadata_directory, location_in_repository, targets_directory,
|
||||
project_key)
|
||||
|
||||
|
||||
os.chmod(local_tmp, 0o0777)
|
||||
shutil.rmtree(local_tmp)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -266,9 +266,9 @@ def test_with_tuf_mode_2(self):
|
|||
file1_target = self.repository_updater.get_one_valid_targetinfo('file1.txt')
|
||||
self.repository_updater.download_target(file1_target, self.client_directory)
|
||||
|
||||
# Verify that the specific 'tuf.exceptions.SlowRetrievalError' exception is raised by
|
||||
# each mirror. 'file1.txt' should be large enough to trigger a slow
|
||||
# retrieval attack, otherwise the expected exception may not be
|
||||
# Verify that the specific 'tuf.exceptions.SlowRetrievalError' exception is
|
||||
# raised by each mirror. 'file1.txt' should be large enough to trigger a
|
||||
# slow retrieval attack, otherwise the expected exception may not be
|
||||
# consistently raised.
|
||||
except tuf.exceptions.NoWorkingMirrorError as exception:
|
||||
for mirror_url, mirror_error in six.iteritems(exception.mirror_errors):
|
||||
|
|
@ -276,7 +276,7 @@ def test_with_tuf_mode_2(self):
|
|||
url_file = os.path.join(url_prefix, 'targets', 'file1.txt')
|
||||
|
||||
# Verify that 'file1.txt' is the culprit.
|
||||
self.assertEqual(url_file, mirror_url)
|
||||
self.assertEqual(url_file.replace('\\', '/'), mirror_url)
|
||||
self.assertTrue(isinstance(mirror_error, tuf.exceptions.SlowRetrievalError))
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1047,7 +1047,8 @@ def test_6_get_one_valid_targetinfo(self):
|
|||
|
||||
# Test: invalid target path.
|
||||
self.assertRaises(tuf.exceptions.UnknownTargetError,
|
||||
self.repository_updater.get_one_valid_targetinfo, self.random_path().lstrip(os.sep))
|
||||
self.repository_updater.get_one_valid_targetinfo,
|
||||
self.random_path().lstrip(os.sep).lstrip('/'))
|
||||
|
||||
# Test updater.get_one_valid_targetinfo() backtracking behavior (enabled by
|
||||
# default.)
|
||||
|
|
|
|||
|
|
@ -2629,6 +2629,8 @@ def get_one_valid_targetinfo(self, target_filepath):
|
|||
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
|
||||
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)
|
||||
|
||||
target_filepath = target_filepath.replace('\\', '/')
|
||||
|
||||
if target_filepath.startswith('/'):
|
||||
raise tuf.exceptions.FormatError('The requested target file cannot'
|
||||
' contain a leading path separator: ' + repr(target_filepath))
|
||||
|
|
|
|||
|
|
@ -1397,7 +1397,7 @@ def generate_targets_metadata(targets_directory, target_files, version,
|
|||
if len(custom):
|
||||
custom_data = custom
|
||||
|
||||
filedict[relative_targetpath] = \
|
||||
filedict[relative_targetpath.replace('\\', '/').lstrip('/')] = \
|
||||
get_metadata_fileinfo(target_path, custom_data)
|
||||
|
||||
# Copy 'target_path' to 'digest_target' if consistent hashing is enabled.
|
||||
|
|
|
|||
|
|
@ -1924,7 +1924,7 @@ def add_target(self, filepath, custom=None):
|
|||
# targets directory.
|
||||
targets_directory_length = len(self._targets_directory) + 1
|
||||
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
|
||||
relative_path = filepath[targets_directory_length:]
|
||||
relative_path = filepath[targets_directory_length:].replace('\\', '/')
|
||||
|
||||
if relative_path not in roleinfo['paths']:
|
||||
logger.debug('Adding new target: ' + repr(relative_path))
|
||||
|
|
@ -1996,7 +1996,8 @@ def add_targets(self, list_of_targets):
|
|||
filepath = os.path.join(self._targets_directory, target)
|
||||
|
||||
if os.path.isfile(filepath):
|
||||
relative_list_of_targets.append(filepath[targets_directory_length+1:])
|
||||
relative_list_of_targets.append(
|
||||
filepath[targets_directory_length + 1:].replace('\\', '/'))
|
||||
|
||||
else:
|
||||
raise securesystemslib.exceptions.Error(repr(filepath) + ' is not'
|
||||
|
|
|
|||
Loading…
Reference in a new issue