feat: add certificate management module and schedule auto-renewal cron

This commit is contained in:
Fredrick Amnehagen 2026-02-05 20:36:15 +01:00
parent 42767fd8bc
commit f793ddd02f
6 changed files with 214 additions and 198 deletions

View file

@ -25,102 +25,82 @@ def test_dns_full_lifecycle(unique_id):
hostname = f"test-lifecycle-{unique_id}"
domain = f"dns-test-{unique_id}.fe.loopaware.com"
# 1. Add DHCP Host
print(f" Adding host {hostname}...")
res = run_infra(["dns", "add-host", mac, ip, hostname])
assert res.returncode == 0
# Add
assert run_infra(["dns", "add-host", mac, ip, hostname]).returncode == 0
assert run_infra(["dns", "add-dns", domain, ip]).returncode == 0
# 2. Add DNS Record
print(f" Adding DNS {domain}...")
res = run_infra(["dns", "add-dns", domain, ip])
assert res.returncode == 0
# 3. Verify both in list
# Verify
res = run_infra(["dns", "list"])
assert mac in res.stdout
assert domain in res.stdout
# 4. Remove both
print(" Cleaning up...")
# Cleanup
assert run_infra(["dns", "remove-host", mac]).returncode == 0
assert run_infra(["dns", "remove-dns", domain]).returncode == 0
# 5. Verify gone
res = run_infra(["dns", "list"])
assert mac not in res.stdout
assert domain not in res.stdout
def test_ingress_collision_and_update(unique_id):
domain = f"test-collision-{unique_id}.loopaware.com"
ip1 = "10.32.70.221"
ip2 = "10.32.70.222"
def test_cloudflare_lifecycle(unique_id):
test_domain = f"test-ddns-{unique_id}.org"
# Add first
res = run_infra(["ingress", "add", domain, ip1, "80"])
# 1. Add to DDNS list
res = run_infra(["cloudflare", "add-ddns", test_domain])
assert res.returncode == 0
# Update (add same domain with different IP)
res = run_infra(["ingress", "add", domain, ip2, "8080"])
# 2. Verify in list
res = run_infra(["cloudflare", "list-ddns"])
assert test_domain in res.stdout
# 3. Remove from list
res = run_infra(["cloudflare", "remove-ddns", test_domain])
assert res.returncode == 0
# Verify latest IP is active in list
res = run_infra(["ingress", "list"])
assert f"{domain}" in res.stdout
# (The list command prints the be_ backend name or IP depending on implementation)
# Cleanup
run_infra(["ingress", "remove", domain])
# 4. Verify gone
res = run_infra(["cloudflare", "list-ddns"])
assert test_domain not in res.stdout
def test_decommission_command_flow(unique_id):
# This tests the command structure and error handling (using non-existent resources)
# We expect it to complete even if individual parts "fail" cleanup
domain = f"ghost-{unique_id}.com"
res = run_infra(["decommission", "--domain", domain])
assert res.returncode == 0
assert "Decommission process complete" in res.stdout
def test_proxmox_template_resolution():
# Verify the alias resolves to something on a known node
res = run_infra(["proxmox", "list-lxcs", "--node", "la-vmh-11"])
assert res.returncode == 0
# The actual resolution happens inside create-lxc, but we can verify the command exists
def test_samba_group_management(unique_id):
username = f"group_test_{unique_id}"
password = "TestPassword123!"
group = "xmpp-users"
# 1. Add User
res = run_infra(["samba", "add-user", username, password])
assert res.returncode == 0
# 2. Add to Group
res = run_infra(["samba", "add-to-group", group, username])
assert res.returncode == 0
# 3. Verify (if we implement list-group-members later, for now check return code)
# Cleanup
# (Samba user deletion not yet implemented in CLI, but user will be stale)
pass
def test_proxmox_multi_node_listing():
nodes = ["la-vmh-11", "la-vmh-07", "la-vmh-12"]
for node in nodes:
print(f" Checking node {node}...")
res = run_infra(["proxmox", "list-lxcs", "--node", node])
assert res.returncode == 0
assert "VMID" in res.stdout
def test_router_error_handling():
# Test adding with invalid IP
res = run_infra(["router", "add", "invalid-ip", "tcp", "80", "999.999.999.999", "80"])
assert res.returncode != 0
assert "Invalid internal IP address" in res.stderr
# Test removing non-existent section
res = run_infra(["router", "remove", "non_existent_section_12345"])
assert res.returncode != 0
# Remove
res = run_infra(["router", "remove", section], env=env)
assert res.returncode == 0
# Add User & Group Join
assert run_infra(["samba", "add-user", username, password]).returncode == 0
assert run_infra(["samba", "add-to-group", group, username]).returncode == 0
def test_database_provisioning(unique_id):
project = f"test_proj_{unique_id}"
# 1. Provision
res = run_infra(["db", "provision", project])
assert res.returncode == 0
assert project in res.stdout
# 2. List and Verify
res = run_infra(["db", "list-dbs"])
assert project in res.stdout
assert project.lower().replace("-", "_") in res.stdout
def test_cert_cli():
# 1. List
res = run_infra(["cert", "list"])
assert res.returncode == 0
assert "loopaware.com.pem" in res.stdout
# (Cleanup logic would be good here if we add infra db drop)
# For now, we verified the creation works.
# 2. Status
res = run_infra(["cert", "status"])
assert res.returncode == 0
assert "notAfter" in res.stdout
def test_ip_discovery():
res = run_infra(["ip", "next-free"])
assert res.returncode == 0
assert "10.32." in res.stdout