Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(tests): stub-kit and popen-guard samples no longer depend on the host's ufw

Juan Denis0e8ab745fbf9
diff --git a/backend/tests/test_popen_guard.py b/backend/tests/test_popen_guard.py
index 23381f5e..1546e937 100644
--- a/backend/tests/test_popen_guard.py
+++ b/backend/tests/test_popen_guard.py
@@ -167,9 +167,11 @@ def test_calls_routed_through_the_helper_module_are_not_condemned(tmp_path):
with patch('popen_guard.shutil.which', side_effect=_which_only_in_sbin):
# The guard stays silent; the real Popen runs and reports the honest
- # FileNotFoundError for a binary absent on this machine.
+ # FileNotFoundError. The head must be a binary that exists on NO
+ # machine — 'ufw' really is installed on CI runners, and a real exec
+ # succeeding here read as DID NOT RAISE.
with pytest.raises(FileNotFoundError):
- mod.call(['ufw', 'status'])
+ mod.call(['serverkit-no-such-binary', 'status'])
def test_a_bypass_from_anywhere_else_still_fires(tmp_path):
diff --git a/backend/tests/test_subprocess_stub.py b/backend/tests/test_subprocess_stub.py
index dc58d447..cfc7c8d8 100644
--- a/backend/tests/test_subprocess_stub.py
+++ b/backend/tests/test_subprocess_stub.py
@@ -10,11 +10,22 @@ import os
import subprocess
import pytest
+from unittest.mock import patch
from subprocess_stub import (FakePopen, FakeProc, ScriptedSubprocess,
UnscriptedCommand, normalize_argv)
+def _ufw_absent():
+ """Make the sbin guard see 'ufw' as absent on this machine.
+
+ These tests use ufw as an arbitrary example argv for the DISPATCH
+ mechanics; on machines where ufw really exists sbin-only (CI runners)
+ the popen guard would fire first and test the wrong thing.
+ """
+ return patch('popen_guard.shutil.which', return_value=None)
+
+
class TestNormalisation:
"""One scripted rule must match on a root box, a sudo box, and a dev box."""
@@ -65,7 +76,7 @@ class TestUnscriptedIsAnError:
except Exception:
return {'success': False, 'error': 'not installed'}
- with pytest.raises(UnscriptedCommand):
+ with _ufw_absent(), pytest.raises(UnscriptedCommand):
service_style_call()
@@ -89,12 +100,12 @@ class TestDispatch:
def test_raises_scripts_an_exception(self, fake_subprocess):
fake_subprocess.script(['ufw'], raises=FileNotFoundError)
- with pytest.raises(FileNotFoundError):
+ with _ufw_absent(), pytest.raises(FileNotFoundError):
subprocess.run(['ufw', 'status'])
def test_raises_accepts_an_instance(self, fake_subprocess):
fake_subprocess.script(['ufw'], raises=subprocess.TimeoutExpired('ufw', 5))
- with pytest.raises(subprocess.TimeoutExpired):
+ with _ufw_absent(), pytest.raises(subprocess.TimeoutExpired):
subprocess.run(['ufw', 'status'])
def test_when_gives_the_responder_argv_and_kwargs(self, fake_subprocess):