Initial commit: SSL proxy / firewall appliance
Flask WebUI behind nginx reverse proxy with zone-based firewall, DHCP, WireGuard, and ACME certificate management.
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
import sys
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, "/home/wall/vacuum-wall")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
from webui.server import app
|
||||
|
||||
app.config["TESTING"] = True
|
||||
return app.test_client()
|
||||
|
||||
|
||||
class TestTemplateFilters:
|
||||
@pytest.fixture
|
||||
def env(self):
|
||||
from webui.server import app
|
||||
|
||||
return app.jinja_env
|
||||
|
||||
def test_timestamp_filter_valid(self, env):
|
||||
result = env.filters["timestamp"]("2026-04-01T12:00:00Z")
|
||||
assert "2026-04-01" in result
|
||||
|
||||
def test_timestamp_filter_empty(self, env):
|
||||
assert env.filters["timestamp"]("") == ""
|
||||
assert env.filters["timestamp"](None) == ""
|
||||
|
||||
def test_timestamp_filter_invalid(self, env):
|
||||
result = env.filters["timestamp"]("not-a-date")
|
||||
assert result == "not-a-date"
|
||||
|
||||
def test_bytes_filter_zero(self, env):
|
||||
assert env.filters["bytes"](0) == "0.0 B"
|
||||
|
||||
def test_bytes_filter_kb(self, env):
|
||||
result = env.filters["bytes"](1536)
|
||||
assert "KB" in result
|
||||
|
||||
def test_bytes_filter_mb(self, env):
|
||||
result = env.filters["bytes"](1500000)
|
||||
assert "MB" in result
|
||||
|
||||
def test_bytes_filter_negative(self, env):
|
||||
assert env.filters["bytes"](-1) == "0 B"
|
||||
|
||||
def test_bytes_filter_invalid(self, env):
|
||||
assert env.filters["bytes"]("not-a-number") == "not-a-number"
|
||||
|
||||
def test_duration_filter_zero(self, env):
|
||||
assert env.filters["duration"](0) == "0s"
|
||||
|
||||
def test_duration_filter_seconds(self, env):
|
||||
assert env.filters["duration"](65) == "1m 5s"
|
||||
|
||||
def test_duration_filter_hours(self, env):
|
||||
result = env.filters["duration"](3661)
|
||||
assert "1h" in result
|
||||
|
||||
def test_duration_filter_days(self, env):
|
||||
result = env.filters["duration"](90000)
|
||||
assert "1d" in result
|
||||
|
||||
def test_duration_filter_invalid(self, env):
|
||||
assert env.filters["duration"]("bad") == "bad"
|
||||
|
||||
def test_json_pretty_filter(self, env):
|
||||
result = env.filters["json_pretty"]({"key": "value"})
|
||||
assert '{"key": "value"}' in result or "key" in result
|
||||
|
||||
|
||||
class TestSafelyHelper:
|
||||
def test_returns_result(self):
|
||||
from webui.server import _safely
|
||||
|
||||
result = _safely(lambda: 42)
|
||||
assert result == 42
|
||||
|
||||
def test_returns_default_on_exception(self):
|
||||
from webui.server import _safely
|
||||
|
||||
result = _safely(lambda: 1 / 0, default=None)
|
||||
assert result is None
|
||||
|
||||
def test_returns_custom_default(self):
|
||||
from webui.server import _safely
|
||||
|
||||
result = _safely(lambda: 1 / 0, default="fallback")
|
||||
assert result == "fallback"
|
||||
|
||||
|
||||
class TestPageRoutes:
|
||||
@patch("webui.server.get_active_zones")
|
||||
@patch("webui.server.get_interfaces")
|
||||
@patch("webui.server.dnsmasq_status")
|
||||
@patch("webui.server.get_domains")
|
||||
@patch("webui.server.list_certs")
|
||||
@patch("webui.server.wg_status")
|
||||
def test_dashboard_no_crash(
|
||||
self,
|
||||
mock_wg,
|
||||
mock_certs,
|
||||
mock_domains,
|
||||
mock_dnsmasq,
|
||||
mock_ifaces,
|
||||
mock_zones,
|
||||
client,
|
||||
):
|
||||
mock_zones.return_value = {}
|
||||
mock_ifaces.return_value = []
|
||||
mock_dnsmasq.return_value = {}
|
||||
mock_domains.return_value = []
|
||||
mock_certs.return_value = []
|
||||
mock_wg.return_value = {}
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
Reference in New Issue
Block a user