Extra validation of the uploaded ZIP #73
@ -78,6 +78,7 @@ EXPECTED_VALIDATION_ERRORS = {
|
||||
'source': ['The manifest file is missing.'],
|
||||
},
|
||||
'invalid-manifest-toml.zip': {'source': ['Could not parse the manifest file.']},
|
||||
'invalid-theme-multiple-xmls.zip': {'source': ['A theme should have exactly one XML file.']},
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ class FileForm(forms.ModelForm):
|
||||
# TODO: surface TOML parsing errors?
|
||||
'invalid_manifest_toml': _('Could not parse the manifest file.'),
|
||||
'invalid_missing_init': _('An add-on should have an __init__.py file.'),
|
||||
'invalid_theme_multiple_xmls': _('A theme should only have one XML file.'),
|
||||
'missing_or_multiple_theme_xml': _('A theme should have exactly one XML file.'),
|
||||
'invalid_zip_archive': msg_only_zip_files,
|
||||
'missing_manifest_toml': _('The manifest file is missing.'),
|
||||
}
|
||||
|
@ -101,6 +101,12 @@ def read_manifest_from_zip(archive_path):
|
||||
error_codes = []
|
||||
try:
|
||||
with zipfile.ZipFile(archive_path) as myzip:
|
||||
bad_file = myzip.testzip()
|
||||
if bad_file is not None:
|
||||
logger.error('Bad file in ZIP')
|
||||
error_codes.append('invalid_zip_archive')
|
||||
return None, error_codes
|
||||
|
||||
file_list = myzip.namelist()
|
||||
manifest_filepath = find_path_by_name(file_list, manifest_name)
|
||||
|
||||
@ -123,7 +129,7 @@ def read_manifest_from_zip(archive_path):
|
||||
if type_slug == 'theme':
|
||||
theme_xmls = filter_paths_by_ext(file_list, '.xml')
|
||||
if len(list(theme_xmls)) != 1:
|
||||
error_codes.append('invalid_theme_multiple_xmls')
|
||||
error_codes.append('missing_or_multiple_theme_xml')
|
||||
elif type_slug == 'add-on':
|
||||
# __init__.py is expected to be next to the manifest
|
||||
expected_init_path = os.path.join(os.path.dirname(manifest_filepath), '__init__.py')
|
||||
|
Loading…
Reference in New Issue
Block a user