Skip to content

Commit 963f868

Browse files
committed
fix(tests): replace is_sandbox_available() with landlock_supported()
It's cleaner to check for Landlock's availability by executing a syscall with an empty ruleset. Plus it was already used by the rust part of our python library.
1 parent 9cc53d4 commit 963f868

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

python/unblob/testing.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import binascii
22
import glob
33
import io
4-
import platform
54
import shlex
65
import subprocess
76
from pathlib import Path
@@ -17,7 +16,6 @@
1716
from unblob.models import ProcessResult
1817
from unblob.processing import ExtractionConfig
1918
from unblob.report import ExtractCommandFailedReport
20-
from unblob.sandbox import AccessFS, SandboxError, restrict_access
2119

2220

2321
@pytest.fixture(scope="session", autouse=True)
@@ -219,17 +217,3 @@ def start(self, s):
219217
rv.write(line.data)
220218

221219
return rv.getvalue()
222-
223-
224-
def is_sandbox_available():
225-
is_sandbox_available = True
226-
227-
try:
228-
restrict_access(AccessFS.read_write("/"))
229-
except SandboxError:
230-
is_sandbox_available = False
231-
232-
if platform.architecture == "x86_64" and platform.system == "linux":
233-
assert is_sandbox_available, "Sandboxing should work at least on Linux-x86_64"
234-
235-
return is_sandbox_available

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from click.testing import CliRunner
88

99
import unblob.cli
10+
from rust.test_sandbox import landlock_supported
1011
from unblob.extractors import Command
1112
from unblob.extractors.command import MultiFileCommand
1213
from unblob.handlers import BUILTIN_HANDLERS
@@ -18,7 +19,6 @@
1819
DEFAULT_SKIP_MAGIC,
1920
ExtractionConfig,
2021
)
21-
from unblob.testing import is_sandbox_available
2222
from unblob.ui import (
2323
NullProgressReporter,
2424
ProgressReporter,
@@ -431,7 +431,7 @@ def test_clear_skip_magics(
431431

432432

433433
@pytest.mark.skipif(
434-
not is_sandbox_available(), reason="Sandboxing is only available on Linux"
434+
not landlock_supported(), reason="Sandboxing is only available on Linux"
435435
)
436436
def test_sandbox_escape(tmp_path: Path):
437437
runner = CliRunner()

tests/test_sandbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import pytest
44

5+
from rust.test_sandbox import landlock_supported
56
from unblob.processing import ExtractionConfig
67
from unblob.sandbox import Sandbox
7-
from unblob.testing import is_sandbox_available
88

99
pytestmark = pytest.mark.skipif(
10-
not is_sandbox_available(), reason="Sandboxing only works on Linux"
10+
not landlock_supported(), reason="Sandboxing only works on Linux"
1111
)
1212

1313

0 commit comments

Comments
 (0)