Sichere Caddy- und DNS-Stilllegung: tests/test_app.py
This commit is contained in:
parent
a324b136df
commit
14c757bbd2
1 changed files with 37 additions and 0 deletions
|
|
@ -240,6 +240,43 @@ def test_iso_builder_restore_defaults_to_dry_run_and_has_no_free_target(monkeypa
|
|||
assert "/app-config/ansible" in decoded
|
||||
|
||||
|
||||
def test_caddy_site_remove_defaults_to_dry_run(monkeypatch):
|
||||
payload = {"hostname": "wiki.sascha-lutz.de", "dry_run": True, "found": True, "line_start": 10, "line_end": 13}
|
||||
calls = []
|
||||
monkeypatch.setattr(app, "_ssh", lambda host, command, timeout=600: (calls.append((host, command, timeout)) or (0, __import__("json").dumps(payload), "")))
|
||||
with TestClient(app.app) as client:
|
||||
response = client.delete("/caddy/site/wiki.sascha-lutz.de", headers={"Authorization": "Bearer test-token"})
|
||||
assert response.status_code == 200
|
||||
assert response.json()["dry_run"] is True
|
||||
assert calls[0][0] == app.CADDY_HOST
|
||||
assert calls[0][2] == 90
|
||||
|
||||
|
||||
def test_caddy_site_remove_rejects_unmanaged_hostname_before_ssh(monkeypatch):
|
||||
monkeypatch.setattr(app, "_ssh", lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("must not SSH")))
|
||||
with TestClient(app.app) as client:
|
||||
response = client.delete("/caddy/site/example.com", headers={"Authorization": "Bearer test-token"})
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_dns_rrset_dry_run_returns_only_selected_records(monkeypatch):
|
||||
async def fake_lookup(zone):
|
||||
assert zone == "sascha-lutz.de"
|
||||
return {"id": 96805, "name": zone}, [
|
||||
{"name": "wiki", "type": "A", "records": [{"value": "46.225.230.72"}]},
|
||||
{"name": "wiki", "type": "AAAA", "records": [{"value": "::1"}]},
|
||||
{"name": "git", "type": "A", "records": [{"value": "46.225.230.72"}]},
|
||||
], {"Authorization": "Bearer hidden"}
|
||||
monkeypatch.setattr(app, "_hetzner_zone_and_rrsets", fake_lookup)
|
||||
with TestClient(app.app) as client:
|
||||
response = client.delete("/dns/rrset/sascha-lutz.de/wiki", headers={"Authorization": "Bearer test-token"})
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["dry_run"] is True
|
||||
assert [item["type"] for item in body["rrsets"]] == ["A", "AAAA"]
|
||||
assert body["deleted"] == []
|
||||
|
||||
|
||||
def test_invalid_log_target_is_rejected_before_ssh():
|
||||
with TestClient(app.app) as client:
|
||||
response = client.get(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue