Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ingestors/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from pathlib import PurePath

import py7zr
from py7zr.exceptions import ArchiveError
from py7zr.exceptions import ArchiveError, PasswordRequired

from ingestors.exc import ProcessingException
from ingestors.exc import ENCRYPTED_MSG, ProcessingException
from ingestors.ingestor import Ingestor
from ingestors.support.package import PackageSupport
from ingestors.support.shell import ShellSupport
Expand All @@ -29,7 +29,10 @@ def unpack(self, file_path, entity, temp_dir):

try:
with py7zr.SevenZipFile(str(pure_file_path), mode="r") as extractor:
extractor.extractall(path=temp_dir)
try:
extractor.extractall(path=temp_dir)
except PasswordRequired:
raise ProcessingException(ENCRYPTED_MSG)
except ArchiveError as e:
raise ProcessingException(f"Error: {e}")

Expand Down
9 changes: 5 additions & 4 deletions ingestors/support/package.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import shutil
import logging
import shutil

from followthemoney import model

from ingestors.support.temp import TempFileSupport
from ingestors.support.encoding import EncodingSupport
from ingestors.directory import DirectoryIngestor
from ingestors.exc import ProcessingException
from ingestors.support.encoding import EncodingSupport
from ingestors.support.temp import TempFileSupport

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,7 +37,7 @@ def ingest(self, file_path, entity):
self.manager.delegate(DirectoryIngestor, temp_dir, entity)
except ProcessingException as e:
raise ProcessingException(
"Could not unpack the contents of this file."
f"Could not unpack the contents of this file. {e}"
) from e

def unpack(self, file_path, entity, temp_dir):
Expand Down
Binary file added tests/fixtures/500_pages_password.7z
Binary file not shown.
11 changes: 10 additions & 1 deletion tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pprint import pprint # noqa

from .support import TestCase
from tests.support import TestCase


class PackagesTest(TestCase):
Expand All @@ -22,3 +22,12 @@ def test_tar(self):
self.manager.ingest(fixture_path, entity)
self.assertEqual(entity.first("processingStatus"), self.manager.STATUS_SUCCESS)
self.assertEqual(entity.schema.name, "Package")

def test_password_protected_7z(self):
fixture_path, entity = self.fixture("500_pages_password.7z")
self.manager.ingest(fixture_path, entity)
self.assertEqual(entity.first("processingStatus"), self.manager.STATUS_FAILURE)
self.assertEqual(
entity.get("processingError")[0],
"Could not unpack the contents of this file. The document might be protected with a password. Try removing the password protection and re-uploading the documents.",
)
Loading