Skip to content

Commit

Permalink
tests: Adapt Qubes tests
Browse files Browse the repository at this point in the history
Adapt Qubes tests to the addition of the conversion process in
doc_to_pixels() call.
  • Loading branch information
apyrgio committed Feb 20, 2024
1 parent bc55a64 commit d376e1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
26 changes: 10 additions & 16 deletions tests/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,15 @@ def test_max_pages_server_enforcement(
pdf_11k_pages: str,
provider: base.IsolationProvider,
mocker: MockerFixture,
monkeypatch: MonkeyPatch,
tmpdir: str,
) -> None:
provider.progress_callback = mocker.MagicMock()
doc = Document(pdf_11k_pages)

proc = None
provider.old_start_doc_to_pixels_proc = provider.start_doc_to_pixels_proc # type: ignore [attr-defined]

def start_doc_to_pixels_proc() -> subprocess.Popen:
proc = provider.old_start_doc_to_pixels_proc() # type: ignore [attr-defined]
return proc

monkeypatch.setattr(
provider, "start_doc_to_pixels_proc", start_doc_to_pixels_proc
)
p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.ConverterProcException):
provider.doc_to_pixels(doc, tmpdir)
assert provider.get_proc_exception(proc) == errors.MaxPagesException # type: ignore [arg-type]
provider.doc_to_pixels(doc, tmpdir, p)
assert provider.get_proc_exception(p) == errors.MaxPagesException

def test_max_pages_client_enforcement(
self,
Expand All @@ -64,8 +54,9 @@ def test_max_pages_client_enforcement(
"dangerzone.conversion.errors.MAX_PAGES", 1
) # sample_doc has 4 pages > 1
doc = Document(sample_doc)
p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.MaxPagesException):
provider.doc_to_pixels(doc, tmpdir)
provider.doc_to_pixels(doc, tmpdir, p)

def test_max_dimensions(
self,
Expand All @@ -76,7 +67,10 @@ def test_max_dimensions(
tmpdir: str,
) -> None:
provider.progress_callback = mocker.MagicMock()
p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.MaxPageWidthException):
provider.doc_to_pixels(Document(sample_bad_width), tmpdir)
provider.doc_to_pixels(Document(sample_bad_width), tmpdir, p)

p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.MaxPageHeightException):
provider.doc_to_pixels(Document(sample_bad_height), tmpdir)
provider.doc_to_pixels(Document(sample_bad_height), tmpdir, p)
29 changes: 10 additions & 19 deletions tests/isolation_provider/test_qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,16 @@ def test_out_of_ram(
) -> None:
provider.progress_callback = mocker.MagicMock()

proc = None

def start_doc_to_pixels_proc() -> subprocess.Popen:
proc = subprocess.Popen(
# XXX error 126 simulates a qrexec-policy failure. Source:
# https://github.com/QubesOS/qubes-core-qrexec/blob/fdcbfd7/daemon/qrexec-daemon.c#L1022
["exit 126"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
return proc

monkeypatch.setattr(
provider, "start_doc_to_pixels_proc", start_doc_to_pixels_proc
proc = subprocess.Popen(
# XXX error 126 simulates a qrexec-policy failure. Source:
# https://github.com/QubesOS/qubes-core-qrexec/blob/fdcbfd7/daemon/qrexec-daemon.c#L1022
["exit 126"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)

with pytest.raises(errors.ConverterProcException) as e:
doc = Document(sample_doc)
provider.doc_to_pixels(doc, tmpdir)
assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed # type: ignore [arg-type]
provider.doc_to_pixels(doc, tmpdir, proc)
assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed

0 comments on commit d376e1d

Please sign in to comment.