Extra validation of the uploaded ZIP #73
BIN
extensions/tests/files/invalid-manifest-toml.zip
Normal file
BIN
extensions/tests/files/invalid-manifest-toml.zip
Normal file
Binary file not shown.
@ -78,6 +78,7 @@ EXPECTED_VALIDATION_ERRORS = {
|
|||||||
'invalid-no-manifest.zip': {
|
'invalid-no-manifest.zip': {
|
||||||
'source': ['The manifest file is missing.'],
|
'source': ['The manifest file is missing.'],
|
||||||
},
|
},
|
||||||
|
'invalid-manifest-toml.zip': {'source': ['Could not parse the manifest file.']},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,18 +143,16 @@ class FileForm(forms.ModelForm):
|
|||||||
errors.append(ValidationError(self.error_messages['invalid_zip_archive']))
|
errors.append(ValidationError(self.error_messages['invalid_zip_archive']))
|
||||||
|
|
||||||
manifest, error_codes = utils.read_manifest_from_zip(file_path)
|
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:
|
if manifest:
|
||||||
errors.append(ValidationError(self.error_messages['missing_manifest_toml']))
|
|
||||||
else:
|
|
||||||
ManifestValidator(manifest)
|
ManifestValidator(manifest)
|
||||||
ExtensionIDManifestValidator(manifest, self.extension)
|
ExtensionIDManifestValidator(manifest, self.extension)
|
||||||
|
|
||||||
self.cleaned_data['metadata'] = manifest
|
self.cleaned_data['metadata'] = manifest
|
||||||
self.cleaned_data['type'] = EXTENSION_SLUG_TYPES[manifest['type']]
|
self.cleaned_data['type'] = EXTENSION_SLUG_TYPES[manifest['type']]
|
||||||
|
|
||||||
|
for code in error_codes:
|
||||||
|
errors.append(ValidationError(self.error_messages[code]))
|
||||||
if errors:
|
if errors:
|
||||||
self.add_error('source', errors)
|
self.add_error('source', errors)
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ def read_manifest_from_zip(archive_path):
|
|||||||
|
|
||||||
if manifest_filepath is None:
|
if manifest_filepath is None:
|
||||||
logger.info(f"File '{manifest_name}' not found in the archive.")
|
logger.info(f"File '{manifest_name}' not found in the archive.")
|
||||||
|
error_codes.append('missing_manifest_toml')
|
||||||
return None, error_codes
|
return None, error_codes
|
||||||
|
|
||||||
# Manifest file is expected to be no deeper than one directory down
|
# Manifest file is expected to be no deeper than one directory down
|
||||||
|
Loading…
Reference in New Issue
Block a user