diff --git a/Dockerfile b/Dockerfile index d76e7af64..29500bb0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ LABEL org.opencontainers.image.licenses MIT LABEL org.opencontainers.image.source https://github.com/alephdata/ingest-file # Enable non-free archive for `unrar`. -RUN echo "deb http://http.us.debian.org/debian stable non-free" >/etc/apt/sources.list.d/nonfree.list \ +RUN echo "deb http://http.us.debian.org/debian bookworm non-free" >/etc/apt/sources.list.d/nonfree.list \ && apt-get -qq -y update \ && apt-get -qq -y install build-essential locales \ # python deps (mostly to install their dependencies) diff --git a/ingestors/packages/__init__.py b/ingestors/packages/__init__.py index f1da6b99c..df8413292 100644 --- a/ingestors/packages/__init__.py +++ b/ingestors/packages/__init__.py @@ -32,6 +32,8 @@ def unpack(self, file_path, entity, temp_dir): z.extractall(path=temp_dir) except ArchiveError as e: raise ProcessingException(f"Error: {e}") + except py7zr.PasswordRequired: + raise ProcessingException("Password protected 7z archive") class SingleFilePackageIngestor(PackageSupport, Ingestor): diff --git a/requirements.txt b/requirements.txt index 738f3aba3..18998e542 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,7 @@ py7zr==1.0.0 pytest==8.3.5 pytest-cov==6.1.0 click==8.1.8 +fakeredis==2.30.3 # File format support dbf==0.99.10 diff --git a/tests/fixtures/7z_password.7z b/tests/fixtures/7z_password.7z new file mode 100644 index 000000000..3fc90ae20 Binary files /dev/null and b/tests/fixtures/7z_password.7z differ diff --git a/tests/test_packages.py b/tests/test_packages.py index 05243aa82..bb8d34cb0 100644 --- a/tests/test_packages.py +++ b/tests/test_packages.py @@ -89,3 +89,12 @@ def test_7zip_symlink_escape(self): assert len(self.manager.entities) == 1 assert self.manager.entities[0].first("fileName") == "bad7zip.7z" assert self.manager.entities[0].first("processingStatus") == "failure" + + def test_7zip_password(self): + fixture_path, entity = self.fixture("7z_password.7z") + + self.manager.ingest(fixture_path, entity) + + assert len(self.manager.entities) == 1 + assert self.manager.entities[0].first("fileName") == "7z_password.7z" + assert self.manager.entities[0].first("processingStatus") == "failure"