tests: Adapt Qubes tests

Adapt Qubes tests to the addition of the conversion process in
doc_to_pixels() call.
This commit is contained in:
Alex Pyrgiotis 2024-02-19 18:09:14 +02:00
parent bc55a64864
commit d376e1da00
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
2 changed files with 20 additions and 35 deletions

View file

@ -32,25 +32,15 @@ class IsolationProviderTest:
pdf_11k_pages: str, pdf_11k_pages: str,
provider: base.IsolationProvider, provider: base.IsolationProvider,
mocker: MockerFixture, mocker: MockerFixture,
monkeypatch: MonkeyPatch,
tmpdir: str, tmpdir: str,
) -> None: ) -> None:
provider.progress_callback = mocker.MagicMock() provider.progress_callback = mocker.MagicMock()
doc = Document(pdf_11k_pages) doc = Document(pdf_11k_pages)
proc = None p = provider.start_doc_to_pixels_proc()
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
)
with pytest.raises(errors.ConverterProcException): with pytest.raises(errors.ConverterProcException):
provider.doc_to_pixels(doc, tmpdir) provider.doc_to_pixels(doc, tmpdir, p)
assert provider.get_proc_exception(proc) == errors.MaxPagesException # type: ignore [arg-type] assert provider.get_proc_exception(p) == errors.MaxPagesException
def test_max_pages_client_enforcement( def test_max_pages_client_enforcement(
self, self,
@ -64,8 +54,9 @@ class IsolationProviderTest:
"dangerzone.conversion.errors.MAX_PAGES", 1 "dangerzone.conversion.errors.MAX_PAGES", 1
) # sample_doc has 4 pages > 1 ) # sample_doc has 4 pages > 1
doc = Document(sample_doc) doc = Document(sample_doc)
p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.MaxPagesException): with pytest.raises(errors.MaxPagesException):
provider.doc_to_pixels(doc, tmpdir) provider.doc_to_pixels(doc, tmpdir, p)
def test_max_dimensions( def test_max_dimensions(
self, self,
@ -76,7 +67,10 @@ class IsolationProviderTest:
tmpdir: str, tmpdir: str,
) -> None: ) -> None:
provider.progress_callback = mocker.MagicMock() provider.progress_callback = mocker.MagicMock()
p = provider.start_doc_to_pixels_proc()
with pytest.raises(errors.MaxPageWidthException): 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): with pytest.raises(errors.MaxPageHeightException):
provider.doc_to_pixels(Document(sample_bad_height), tmpdir) provider.doc_to_pixels(Document(sample_bad_height), tmpdir, p)

View file

@ -40,25 +40,16 @@ class TestQubes(IsolationProviderTest):
) -> None: ) -> None:
provider.progress_callback = mocker.MagicMock() provider.progress_callback = mocker.MagicMock()
proc = None proc = subprocess.Popen(
# XXX error 126 simulates a qrexec-policy failure. Source:
def start_doc_to_pixels_proc() -> subprocess.Popen: # https://github.com/QubesOS/qubes-core-qrexec/blob/fdcbfd7/daemon/qrexec-daemon.c#L1022
proc = subprocess.Popen( ["exit 126"],
# XXX error 126 simulates a qrexec-policy failure. Source: stdin=subprocess.PIPE,
# https://github.com/QubesOS/qubes-core-qrexec/blob/fdcbfd7/daemon/qrexec-daemon.c#L1022 stdout=subprocess.PIPE,
["exit 126"], stderr=subprocess.PIPE,
stdin=subprocess.PIPE, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
return proc
monkeypatch.setattr(
provider, "start_doc_to_pixels_proc", start_doc_to_pixels_proc
) )
with pytest.raises(errors.ConverterProcException) as e: with pytest.raises(errors.ConverterProcException) as e:
doc = Document(sample_doc) doc = Document(sample_doc)
provider.doc_to_pixels(doc, tmpdir) provider.doc_to_pixels(doc, tmpdir, proc)
assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed # type: ignore [arg-type] assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed