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
Showing only changes of commit 829145c2e1 - Show all commits

View File

@ -51,7 +51,7 @@ def get_sha256_from_value(value: str):
def find_file_inside_zip_list(file_to_read: str, name_list: list) -> str: def find_file_inside_zip_list(file_to_read: str, name_list: list) -> str:
"""Return the first occurance of file_to_read insize a zip name_list""" """Return the first occurrence of file_to_read insize a zip name_list"""
for file_path in name_list: for file_path in name_list:
# Remove leading/trailing whitespace from file path # Remove leading/trailing whitespace from file path
file_path_stripped = file_path.strip() file_path_stripped = file_path.strip()
@ -61,15 +61,15 @@ def find_file_inside_zip_list(file_to_read: str, name_list: list) -> str:
return None return None
def find_files_inside_zip_list(file_extension: str, name_list: list) -> typing.Iterable[str]: def filter_file_paths_by_ext(paths: typing.Iterable[str], extension: str) -> typing.Iterable[str]:
"""Return a generator of list of files with a given extension a ZIP name_list.""" """Generate a list of paths having a given extension from a given list of file paths."""
for file_path in name_list: for file_path in paths:
# Remove leading/trailing whitespace from file path # Remove leading/trailing whitespace from file path
file_path_stripped = file_path.strip() file_path_stripped = file_path.strip()
# Get file's extension # Get file path's extension
_, file_path_ext = os.path.splitext(file_path_stripped) _, file_path_ext = os.path.splitext(file_path_stripped)
# Check if this file's extension matches the extension we are looking for # Check if this file's extension matches the extension we are looking for
if file_path_ext.lower() == file_extension.lower(): if file_path_ext.lower() == extension.lower():
yield file_path_stripped yield file_path_stripped
@ -91,7 +91,7 @@ def read_manifest_from_zip(archive_path):
# In case manifest TOML was successfully parsed, do additional type-specific validation # In case manifest TOML was successfully parsed, do additional type-specific validation
if toml_content['type'] == 'theme': if toml_content['type'] == 'theme':
theme_xmls = find_files_inside_zip_list('.xml', file_list) theme_xmls = filter_file_paths_by_ext(file_list, '.xml')
if len(list(theme_xmls)) != 1: if len(list(theme_xmls)) != 1:
error_codes.append('invalid_theme_multiple_xmls') error_codes.append('invalid_theme_multiple_xmls')