mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 09:52:37 +02:00
Add dummy isolation provider to CLI
When enabled, the conversion part does nothing but print some simulated output. This can be useful for testing non-conversion code (e.g. GUI). Activated with the hidden flag --unsafe-dummy-conversion.
This commit is contained in:
parent
538df18709
commit
da0cb6b3c5
5 changed files with 30 additions and 7 deletions
|
@ -33,6 +33,9 @@ def print_header(s: str) -> None:
|
|||
flag_value=True,
|
||||
help=f"Archives the unsafe version in a subdirectory named '{ARCHIVE_SUBDIR}'",
|
||||
)
|
||||
@click.option(
|
||||
"--unsafe-dummy-conversion", "dummy_conversion", flag_value=True, hidden=True
|
||||
)
|
||||
@click.argument(
|
||||
"filenames",
|
||||
required=True,
|
||||
|
@ -47,9 +50,14 @@ def cli_main(
|
|||
ocr_lang: Optional[str],
|
||||
filenames: List[str],
|
||||
archive: bool,
|
||||
dummy_conversion: bool,
|
||||
) -> None:
|
||||
setup_logging()
|
||||
dangerzone = DangerzoneCore()
|
||||
|
||||
if getattr(sys, "dangerzone_dev", False) and dummy_conversion:
|
||||
dangerzone = DangerzoneCore(Dummy())
|
||||
else:
|
||||
dangerzone = DangerzoneCore(Container())
|
||||
|
||||
display_banner()
|
||||
if len(filenames) == 1 and output_filename:
|
||||
|
|
|
@ -13,7 +13,7 @@ from PySide2 import QtCore, QtGui, QtWidgets
|
|||
if platform.system() == "Linux":
|
||||
from xdg.DesktopEntry import DesktopEntry
|
||||
|
||||
from ..isolation_provider.base import IsolationProvider
|
||||
from ..isolation_provider.container import Container
|
||||
from ..logic import DangerzoneCore
|
||||
from ..settings import Settings
|
||||
from ..util import get_resource_path
|
||||
|
@ -27,7 +27,7 @@ class DangerzoneGui(DangerzoneCore):
|
|||
"""
|
||||
|
||||
def __init__(self, app: QtWidgets.QApplication) -> None:
|
||||
super().__init__()
|
||||
super().__init__(isolation_provider=Container())
|
||||
|
||||
# Qt app
|
||||
self.app = app
|
||||
|
|
|
@ -12,9 +12,9 @@ from typing import Callable, List, Optional
|
|||
import appdirs
|
||||
import colorama
|
||||
|
||||
from . import errors, isolation_provider
|
||||
from . import errors
|
||||
from .document import Document
|
||||
from .isolation_provider.container import Container
|
||||
from .isolation_provider.base import IsolationProvider
|
||||
from .settings import Settings
|
||||
from .util import get_resource_path
|
||||
|
||||
|
@ -26,7 +26,7 @@ class DangerzoneCore(object):
|
|||
Singleton of shared state / functionality throughout the app
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, isolation_provider: IsolationProvider) -> None:
|
||||
# Initialize terminal colors
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
|
@ -42,7 +42,7 @@ class DangerzoneCore(object):
|
|||
|
||||
self.documents: List[Document] = []
|
||||
|
||||
self.isolation_provider = Container()
|
||||
self.isolation_provider = isolation_provider
|
||||
|
||||
def add_document_from_filename(
|
||||
self,
|
||||
|
|
BIN
share/dummy_document.pdf
Normal file
BIN
share/dummy_document.pdf
Normal file
Binary file not shown.
|
@ -263,6 +263,21 @@ class TestCliConversion(TestCliBasic):
|
|||
assert os.path.exists(archived_doc_path)
|
||||
assert os.path.exists(safe_doc_path)
|
||||
|
||||
def test_dummy_conversion(self, tmp_path: Path) -> None:
|
||||
result = self.run_cli([self.sample_doc, "--unsafe-dummy-conversion"])
|
||||
result.assert_success()
|
||||
|
||||
def test_dummy_conversion_bulk(self, tmp_path: Path) -> None:
|
||||
filenames = ["1.pdf", "2.pdf", "3.pdf"]
|
||||
file_paths = []
|
||||
for filename in filenames:
|
||||
doc_path = str(tmp_path / filename)
|
||||
shutil.copyfile(self.sample_doc, doc_path)
|
||||
file_paths.append(doc_path)
|
||||
|
||||
result = self.run_cli(["--unsafe-dummy-conversion", *file_paths])
|
||||
result.assert_success()
|
||||
|
||||
|
||||
class TestSecurity(TestCli):
|
||||
def test_suspicious_double_dash_file(self, tmp_path: Path) -> None:
|
||||
|
|
Loading…
Reference in a new issue