feat: auto-generate self-signed certs, hoover modal processing guard, refactor backends/proxy pages
This commit is contained in:
+25
-25
@@ -34,51 +34,51 @@ from daemon.server import ConflictError
|
||||
class TestGenerateSelfSigned:
|
||||
def test_generate_creates_files(self, tmp_path):
|
||||
with (
|
||||
patch("daemon.handlers.acme._ACME_HOME", tmp_path / "acme"),
|
||||
patch("daemon.handlers.acme.PROJECT_DIR", tmp_path),
|
||||
):
|
||||
result = generate_self_signed(None, {"domain": "test.local"})
|
||||
|
||||
assert result["domain"] == "test.local"
|
||||
assert result["generated"] is True
|
||||
cert_dir = tmp_path / "acme" / "test.local"
|
||||
assert result["cert"] == str(cert_dir / "fullchain.cer")
|
||||
assert result["key"] == str(cert_dir / "test.local.key")
|
||||
assert (cert_dir / "fullchain.cer").is_file()
|
||||
assert (cert_dir / "test.local.key").is_file()
|
||||
certs_dir = tmp_path / "data" / "certs"
|
||||
assert result["cert"] == str(certs_dir / "test.local.crt")
|
||||
assert result["key"] == str(certs_dir / "test.local.key")
|
||||
assert (certs_dir / "test.local.crt").is_file()
|
||||
assert (certs_dir / "test.local.key").is_file()
|
||||
|
||||
def test_generate_idempotent_skips_existing(self, tmp_path):
|
||||
cert_dir = tmp_path / "acme" / "test.local"
|
||||
cert_dir.mkdir(parents=True)
|
||||
(cert_dir / "fullchain.cer").write_text("dummy-cert")
|
||||
(cert_dir / "test.local.key").write_text("dummy-key")
|
||||
certs_dir = tmp_path / "data" / "certs"
|
||||
certs_dir.mkdir(parents=True)
|
||||
(certs_dir / "test.local.crt").write_text("dummy-cert")
|
||||
(certs_dir / "test.local.key").write_text("dummy-key")
|
||||
|
||||
with patch("daemon.handlers.acme._ACME_HOME", tmp_path / "acme"):
|
||||
with patch("daemon.handlers.acme.PROJECT_DIR", tmp_path):
|
||||
result = generate_self_signed(None, {"domain": "test.local"})
|
||||
|
||||
assert result["generated"] is False
|
||||
|
||||
def test_generate_partial_existing(self, tmp_path):
|
||||
cert_dir = tmp_path / "acme" / "test.local"
|
||||
cert_dir.mkdir(parents=True)
|
||||
(cert_dir / "fullchain.cer").write_text("dummy-cert")
|
||||
certs_dir = tmp_path / "data" / "certs"
|
||||
certs_dir.mkdir(parents=True)
|
||||
(certs_dir / "test.local.crt").write_text("dummy-cert")
|
||||
# key missing -> should regenerate
|
||||
|
||||
with patch("daemon.handlers.acme._ACME_HOME", tmp_path / "acme"):
|
||||
with patch("daemon.handlers.acme.PROJECT_DIR", tmp_path):
|
||||
result = generate_self_signed(None, {"domain": "test.local"})
|
||||
|
||||
assert result["generated"] is True
|
||||
|
||||
def test_generate_custom_days(self, tmp_path):
|
||||
with (
|
||||
patch("daemon.handlers.acme._ACME_HOME", tmp_path / "acme"),
|
||||
patch("daemon.handlers.acme.PROJECT_DIR", tmp_path),
|
||||
patch("subprocess.run") as mock_run,
|
||||
):
|
||||
|
||||
def _create_files(*args, **kwargs):
|
||||
cert_dir = tmp_path / "acme" / "test.local"
|
||||
cert_dir.mkdir(parents=True, exist_ok=True)
|
||||
(cert_dir / "fullchain.cer").touch()
|
||||
(cert_dir / "test.local.key").touch()
|
||||
certs_dir = tmp_path / "data" / "certs"
|
||||
certs_dir.mkdir(parents=True, exist_ok=True)
|
||||
(certs_dir / "test.local.crt").touch()
|
||||
(certs_dir / "test.local.key").touch()
|
||||
return Path("")
|
||||
|
||||
mock_run.side_effect = _create_files
|
||||
@@ -88,15 +88,15 @@ class TestGenerateSelfSigned:
|
||||
idx = args.index("-days")
|
||||
assert args[idx + 1] == "730"
|
||||
|
||||
cert_dir = tmp_path / "acme" / "test.local"
|
||||
if (cert_dir / "fullchain.cer").is_file():
|
||||
assert cert_dir.is_dir()
|
||||
certs_dir = tmp_path / "data" / "certs"
|
||||
if (certs_dir / "test.local.crt").is_file():
|
||||
assert certs_dir.is_dir()
|
||||
|
||||
def test_generate_creates_directory(self, tmp_path):
|
||||
with patch("daemon.handlers.acme._ACME_HOME", tmp_path / "acme"):
|
||||
with patch("daemon.handlers.acme.PROJECT_DIR", tmp_path):
|
||||
generate_self_signed(None, {"domain": "test.local"})
|
||||
|
||||
assert (tmp_path / "acme" / "test.local").is_dir()
|
||||
assert (tmp_path / "data" / "certs").is_dir()
|
||||
|
||||
def test_generate_requires_domain(self):
|
||||
with pytest.raises(ValueError, match="domain"):
|
||||
|
||||
Reference in New Issue
Block a user