mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
WIP: Remove all provider wait lines
This commit is contained in:
parent
e749e92425
commit
130ba92e34
3 changed files with 4 additions and 63 deletions
|
@ -21,31 +21,6 @@ def provider() -> Container:
|
||||||
return Container()
|
return Container()
|
||||||
|
|
||||||
|
|
||||||
class ContainerWait(Container):
|
|
||||||
"""Container isolation provider that blocks until the container has started."""
|
|
||||||
|
|
||||||
def exec_container(self, *args, **kwargs): # type: ignore [no-untyped-def]
|
|
||||||
# Check every 100ms if a container with the expected name has showed up.
|
|
||||||
# Else, closing the file descriptors may not work.
|
|
||||||
name = kwargs["name"]
|
|
||||||
runtime = self.get_runtime()
|
|
||||||
p = super().exec_container(*args, **kwargs)
|
|
||||||
for i in range(50):
|
|
||||||
containers = subprocess.run(
|
|
||||||
[runtime, "ps"], capture_output=True
|
|
||||||
).stdout.decode()
|
|
||||||
if name in containers:
|
|
||||||
return p
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
raise RuntimeError(f"Container {name} did not start within 5 seconds")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def provider_wait() -> ContainerWait:
|
|
||||||
return ContainerWait()
|
|
||||||
|
|
||||||
|
|
||||||
class TestContainer(IsolationProviderTest):
|
class TestContainer(IsolationProviderTest):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
from dangerzone.conversion import errors
|
from dangerzone.conversion import errors
|
||||||
from dangerzone.document import Document
|
|
||||||
from dangerzone.isolation_provider.base import IsolationProvider
|
from dangerzone.isolation_provider.base import IsolationProvider
|
||||||
from dangerzone.isolation_provider.dummy import Dummy
|
from dangerzone.isolation_provider.dummy import Dummy
|
||||||
|
|
||||||
|
@ -16,24 +14,6 @@ if not os.environ.get("DUMMY_CONVERSION", False):
|
||||||
pytest.skip("Dummy conversion is not enabled", allow_module_level=True)
|
pytest.skip("Dummy conversion is not enabled", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
class DummyWait(Dummy):
|
|
||||||
"""Dummy isolation provider that spawns a blocking process."""
|
|
||||||
|
|
||||||
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
|
|
||||||
return subprocess.Popen(
|
|
||||||
["python3"],
|
|
||||||
stdin=subprocess.PIPE,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
start_new_session=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def provider_wait() -> DummyWait:
|
|
||||||
return DummyWait()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def provider() -> Dummy:
|
def provider() -> Dummy:
|
||||||
return Dummy()
|
return Dummy()
|
||||||
|
@ -42,21 +22,12 @@ def provider() -> Dummy:
|
||||||
class TestDummyTermination(IsolationProviderTermination):
|
class TestDummyTermination(IsolationProviderTermination):
|
||||||
def test_failed(
|
def test_failed(
|
||||||
self,
|
self,
|
||||||
provider_wait: IsolationProvider,
|
provider: IsolationProvider,
|
||||||
mocker: MockerFixture,
|
mocker: MockerFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
mocker.patch.object(
|
mocker.patch.object(
|
||||||
provider_wait,
|
provider,
|
||||||
"get_proc_exception",
|
"get_proc_exception",
|
||||||
return_value=errors.DocFormatUnsupported(),
|
return_value=errors.DocFormatUnsupported(),
|
||||||
)
|
)
|
||||||
super().test_failed(provider_wait, mocker)
|
super().test_failed(provider, mocker)
|
||||||
|
|
||||||
def test_linger_unkillable(
|
|
||||||
self,
|
|
||||||
provider_wait: IsolationProvider,
|
|
||||||
mocker: MockerFixture,
|
|
||||||
) -> None:
|
|
||||||
# We have to spawn a blocking process here, else we can't imitate an
|
|
||||||
# "unkillable" process.
|
|
||||||
super().test_linger_unkillable(provider_wait, mocker)
|
|
||||||
|
|
|
@ -20,11 +20,6 @@ elif os.environ.get("DUMMY_CONVERSION", False):
|
||||||
pytest.skip("Dummy conversion is enabled", allow_module_level=True)
|
pytest.skip("Dummy conversion is enabled", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def provider() -> Qubes:
|
|
||||||
return Qubes()
|
|
||||||
|
|
||||||
|
|
||||||
class QubesWait(Qubes):
|
class QubesWait(Qubes):
|
||||||
"""Qubes isolation provider that blocks until the disposable qube has started."""
|
"""Qubes isolation provider that blocks until the disposable qube has started."""
|
||||||
|
|
||||||
|
@ -53,7 +48,7 @@ class QubesWait(Qubes):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def provider_wait() -> QubesWait:
|
def provider() -> QubesWait:
|
||||||
return QubesWait()
|
return QubesWait()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue