Extra validation of the uploaded ZIP #73

Merged
Anna Sirota merged 13 commits from validation-single-theme-xml into main 2024-04-11 12:32:50 +02:00
4 changed files with 5 additions and 5 deletions
Showing only changes of commit aef236cf25 - Show all commits

Binary file not shown.

View File

@ -78,6 +78,7 @@ EXPECTED_VALIDATION_ERRORS = {
'invalid-no-manifest.zip': {
'source': ['The manifest file is missing.'],
},
'invalid-manifest-toml.zip': {'source': ['Could not parse the manifest file.']},
}

View File

@ -143,18 +143,16 @@ class FileForm(forms.ModelForm):
errors.append(ValidationError(self.error_messages['invalid_zip_archive']))
manifest, error_codes = utils.read_manifest_from_zip(file_path)
for code in error_codes:
errors.append(ValidationError(self.error_messages[code]))
if manifest is None:
errors.append(ValidationError(self.error_messages['missing_manifest_toml']))
else:
if manifest:
ManifestValidator(manifest)
ExtensionIDManifestValidator(manifest, self.extension)
self.cleaned_data['metadata'] = manifest
self.cleaned_data['type'] = EXTENSION_SLUG_TYPES[manifest['type']]
for code in error_codes:
errors.append(ValidationError(self.error_messages[code]))
if errors:
self.add_error('source', errors)

View File

@ -110,6 +110,7 @@ def read_manifest_from_zip(archive_path):
if manifest_filepath is None:
logger.info(f"File '{manifest_name}' not found in the archive.")
error_codes.append('missing_manifest_toml')
return None, error_codes
# Manifest file is expected to be no deeper than one directory down