Install authenticated native web proxy with user autostart

Register the existing native supervisor with launchd/systemd, include the dependency-free authenticated web proxy, detect Node, and keep the API loopback by default. Preserve existing web credentials and configured host harness defaults. Clarify single-step setup, lifecycle selection, and optional ntfy limits.

Checks: 44 mocked native installer/lifecycle tests; 8 entrypoint tests; 42 Docker installer tests; GOPROXY=off GOTOOLCHAIN=local go test ./internal/installation ./cmd/pipelines; sh -n install install.sh; git diff --check. No live install, deployment, restart, downloads, real autostart/login verification or native Linux verification.
This commit is contained in:
2026-10-20 21:30:07 +01:00
parent b56d6af180
commit ae6ba6ae10
6 changed files with 397 additions and 46 deletions
+56 -1
View File
@@ -4,7 +4,7 @@ from pathlib import Path
import signal
import tempfile
import unittest
from unittest.mock import patch
from unittest.mock import MagicMock, patch
spec = importlib.util.spec_from_file_location("manage_native", Path(__file__).with_name("manage.py"))
manage = importlib.util.module_from_spec(spec)
@@ -37,6 +37,61 @@ class ManageNativeTests(unittest.TestCase):
self.assertEqual(manage.ntfy_mode({"ntfy": {"mode": "native"}}), "native")
self.assertEqual(manage.ntfy_health_url({"ntfy_port": 8090}), "http://127.0.0.1:8090/v1/health")
def test_registered_start_commands_on_both_platforms(self):
for system in ("Darwin", "Linux"):
with self.subTest(system=system), tempfile.TemporaryDirectory() as directory:
config = self.config(Path(directory))
config["registration"] = str(Path(directory) / "service")
with patch.object(manage.platform, "system", return_value=system), \
patch.object(manage, "run") as run, patch.object(manage, "wait_health"):
manage.start(config)
calls = [call.args[0] for call in run.call_args_list]
if system == "Linux":
self.assertEqual(calls, [["systemctl", "--user", "daemon-reload"],
["systemctl", "--user", "enable", "--now", "net.a-wan.pipelines.service"]])
else:
self.assertEqual(calls[0], ["launchctl", "enable", f"gui/{os.getuid()}/net.a-wan.pipelines"])
self.assertIn(["launchctl", "kickstart", f"gui/{os.getuid()}/net.a-wan.pipelines"], calls)
def test_supervisor_spawns_authenticated_web_and_cleans_up_on_exit(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "logs").mkdir()
config = self.config(root)
config["web"] = {"node": "/bin/node", "script": "/prefix/lib/web/serve.mjs",
"host": "0.0.0.0", "port": 8082, "auth_file": "/private/auth.json"}
ntfy, server, web = MagicMock(), MagicMock(), MagicMock()
ntfy.poll.return_value = None
server.poll.return_value = None
web.poll.side_effect = [1, None]
with patch.object(manage, "ntfy_start", return_value=ntfy), \
patch.object(manage, "wait_health"), patch.object(manage.signal, "signal"), \
patch.dict(os.environ, {"PIPELINES_WEB_AUTH": "disabled"}), \
patch.object(manage.subprocess, "Popen", side_effect=[server, web]) as popen:
with self.assertRaisesRegex(RuntimeError, "web proxy exited"):
manage.supervise(config)
call = popen.call_args_list[1]
self.assertEqual(call.args[0], ["/bin/node", "/prefix/lib/web/serve.mjs", "--port", "8082",
"--host", "0.0.0.0", "--pipelines", "127.0.0.1:8080"])
self.assertNotIn("PIPELINES_WEB_AUTH", call.kwargs["env"])
self.assertEqual(call.kwargs["env"]["PIPELINES_WEB_AUTH_FILE"], "/private/auth.json")
web.terminate.assert_called_once()
server.terminate.assert_called_once()
ntfy.terminate.assert_called_once()
def test_start_checks_web_login_readiness(self):
with tempfile.TemporaryDirectory() as directory:
config = self.config(Path(directory))
config["registration"] = "/scratch/service"
config["web"] = {"host": "0.0.0.0", "port": 8123}
response = MagicMock()
response.__enter__.return_value.status = 200
with patch.object(manage.platform, "system", return_value="Linux"), \
patch.object(manage, "run"), patch.object(manage, "wait_health"), \
patch.object(manage.urllib.request, "urlopen", return_value=response) as open_url:
manage.start(config)
open_url.assert_called_once_with("http://127.0.0.1:8123/login", timeout=2)
def test_server_address_uses_the_manifest_bind_and_defaults_to_loopback(self):
self.assertEqual(manage.server_address({"server_port": 8080, "bind_address": "0.0.0.0"}), "0.0.0.0:8080")
self.assertEqual(manage.server_address({"server_port": 8080, "bind_address": "10.0.0.75"}), "10.0.0.75:8080")