Modified a conditional statement of mirrors.py, where introducing a new file type might lead to a bug in get_list_of_mirrors()

This commit is contained in:
vladdd 2013-02-26 20:26:31 -05:00
parent a99282d22a
commit cf58b747a5

View file

@ -24,6 +24,10 @@
import tuf.util
import tuf.formats
# The type of file to be downloaded from a repository. The
# 'get_list_of_mirrors' function supports these file types.
_SUPPORTED_FILE_TYPES = ['meta', 'target']
def get_list_of_mirrors(file_type, file_path, mirrors_dict):
"""
@ -47,17 +51,18 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
keys are strings and values are MIRROR_SCHEMA. An example format
of MIRROR_SCHEMA:
{'url_prefix': 'http://localhost:8001'
'metadata_path': 'metadata/'
'targets_path': 'targets/'
'confined_target_dirs': ['targets/release1/', ...]
{'url_prefix': 'http://localhost:8001',
'metadata_path': 'metadata/',
'targets_path': 'targets/',
'confined_target_dirs': ['targets/release1/', ...],
'custom': {...}}
The 'custom' field is optional.
<Exceptions>
tuf.Error on unknown file type.
tuf.FormatError on bad argument.
tuf.Error, on unknown file type.
tuf.FormatError, on bad argument.
<Return>
List of mirror urls corresponding to the file_type and file_path. If no
@ -70,10 +75,10 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
tuf.formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict)
tuf.formats.NAME_SCHEMA.check_match(file_type)
if file_type not in ['meta', 'target']:
msg = ('Invalid input: \'file_type\' has to be either \'meta\' or '+
'\'target\'.')
raise tuf.FormatError(msg)
if file_type not in _SUPPORTED_FILE_TYPES:
message = 'Invalid file_type argument. '+ \
'Supported file types: '+repr(_SUPPORTED_FILE_TYPES)
raise tuf.FormatError(message)
# Reference to 'tuf.util.file_in_confined_directories()' (improve readability).
# This function checks whether a mirror should serve a file to the client.
@ -86,14 +91,17 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
for mirror_name, mirror_info in mirrors_dict.items():
if file_type == 'meta':
base = mirror_info['url_prefix']+'/'+mirror_info['metadata_path']
else:
elif file_type == 'target':
targets_path = mirror_info['targets_path']
full_filepath = os.path.join(targets_path, file_path)
if not in_confined_directory(full_filepath,
mirror_info['confined_target_dirs']):
continue
base = mirror_info['url_prefix']+'/'+mirror_info['targets_path']
else:
message = repr(file_type)+' is not a supported file type. '+ \
'Supported file types: '+repr(_SUPPORTED_FILE_TYPES)
raise tuf.FormatError(message)
# urllib.quote(string) replaces special characters in string using the %xx
# escape. This is done to avoid parsing issues of the URL on the server