From 943bab2def63d34e3dd985ab6765787b28615397 Mon Sep 17 00:00:00 2001 From: deeplow Date: Wed, 10 Jan 2024 11:26:54 +0000 Subject: [PATCH] Move Qubes-specific tests also to containers Now that Qubes and Containers essentially share the same code, we can have both run the same tests. --- tests/isolation_provider/base.py | 38 +++++++++++++++++++++- tests/isolation_provider/test_container.py | 9 ++++- tests/isolation_provider/test_qubes.py | 29 ----------------- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/tests/isolation_provider/base.py b/tests/isolation_provider/base.py index 8c95fc0..d03a2b1 100644 --- a/tests/isolation_provider/base.py +++ b/tests/isolation_provider/base.py @@ -9,7 +9,14 @@ from dangerzone.document import Document from dangerzone.isolation_provider import base from dangerzone.isolation_provider.qubes import running_on_qubes -from .. import pdf_11k_pages, sanitized_text, uncommon_text +from .. import ( + pdf_11k_pages, + sample_bad_height, + sample_bad_width, + sample_doc, + sanitized_text, + uncommon_text, +) @pytest.mark.skipif( @@ -30,3 +37,32 @@ class IsolationProviderTest: with pytest.raises(errors.ConverterProcException): provider.doc_to_pixels(doc, tmpdir) assert provider.get_proc_exception() == errors.MaxPagesException + + def test_max_pages_client_enforcement( + self, + sample_doc: str, + provider: base.IsolationProvider, + mocker: MockerFixture, + tmpdir: str, + ) -> None: + provider.progress_callback = mocker.MagicMock() + mocker.patch( + "dangerzone.conversion.errors.MAX_PAGES", 1 + ) # sample_doc has 4 pages > 1 + doc = Document(sample_doc) + with pytest.raises(errors.MaxPagesException): + provider.doc_to_pixels(doc, tmpdir) + + def test_max_dimensions( + self, + sample_bad_width: str, + sample_bad_height: str, + provider: base.IsolationProvider, + mocker: MockerFixture, + tmpdir: str, + ) -> None: + provider.progress_callback = mocker.MagicMock() + with pytest.raises(errors.MaxPageWidthException): + provider.doc_to_pixels(Document(sample_bad_width), tmpdir) + with pytest.raises(errors.MaxPageHeightException): + provider.doc_to_pixels(Document(sample_bad_height), tmpdir) diff --git a/tests/isolation_provider/test_container.py b/tests/isolation_provider/test_container.py index 8fedc85..3bef55c 100644 --- a/tests/isolation_provider/test_container.py +++ b/tests/isolation_provider/test_container.py @@ -9,7 +9,14 @@ from dangerzone.document import Document from dangerzone.isolation_provider.container import Container # XXX Fixtures used in abstract Test class need to be imported regardless -from .. import pdf_11k_pages, sanitized_text, uncommon_text +from .. import ( + pdf_11k_pages, + sample_bad_height, + sample_bad_width, + sample_doc, + sanitized_text, + uncommon_text, +) from .base import IsolationProviderTest diff --git a/tests/isolation_provider/test_qubes.py b/tests/isolation_provider/test_qubes.py index c4d36c2..bf8b6af 100644 --- a/tests/isolation_provider/test_qubes.py +++ b/tests/isolation_provider/test_qubes.py @@ -30,35 +30,6 @@ def provider() -> Qubes: @pytest.mark.skipif(not running_on_qubes(), reason="Not on a Qubes system") class TestQubes(IsolationProviderTest): - def test_max_pages_client_enforcement( - self, - sample_doc: str, - provider: Qubes, - mocker: MockerFixture, - tmpdir: str, - ) -> None: - provider.progress_callback = mocker.MagicMock() - mocker.patch( - "dangerzone.conversion.errors.MAX_PAGES", 1 - ) # sample_doc has 4 pages > 1 - doc = Document(sample_doc) - with pytest.raises(errors.MaxPagesException): - provider.doc_to_pixels(doc, tmpdir) - - def test_max_dimensions( - self, - sample_bad_width: str, - sample_bad_height: str, - provider: Qubes, - mocker: MockerFixture, - tmpdir: str, - ) -> None: - provider.progress_callback = mocker.MagicMock() - with pytest.raises(errors.MaxPageWidthException): - provider.doc_to_pixels(Document(sample_bad_width), tmpdir) - with pytest.raises(errors.MaxPageHeightException): - provider.doc_to_pixels(Document(sample_bad_height), tmpdir) - def test_out_of_ram( self, provider: Qubes,