wg-easy + Traefik docker-compose stack (Phase 1) plus a stdlib-only control-plane API for box registration, WireGuard peer provisioning via wg-easy, and per-box route publish/unpublish backed by Traefik's file provider (Phase 2, single-tenant mode). SQLite holds accounts/boxes/routes so a later multi-tenant shared instance is the same schema with more rows, not a reshape. wg-easy's actual REST API was verified against its source rather than assumed: it has no bearer-token auth (session-cookie login via POST /api/auth/password) and no way to accept an externally-generated public key (it always mints the keypair itself, private key included) — both corrected from the original plan during implementation.
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from control_plane.db import Database, row_to_dict
|
|
|
|
|
|
def test_schema_created_and_roundtrips(tmp_path):
|
|
db = Database(db_path=tmp_path / "gateway.db")
|
|
|
|
db.execute(
|
|
"INSERT INTO accounts (id, email, created_at, registration_token_hash, "
|
|
"account_token_hash, box_limit, route_limit_per_box) "
|
|
"VALUES ('acc1', 'a@example.com', '2026-01-01T00:00:00', 'h1', 'h2', 5, 5)"
|
|
)
|
|
row = db.query_one("SELECT * FROM accounts WHERE id = ?", ("acc1",))
|
|
assert row["email"] == "a@example.com"
|
|
|
|
all_rows = db.query_all("SELECT id FROM accounts")
|
|
assert [r["id"] for r in all_rows] == ["acc1"]
|
|
|
|
|
|
def test_row_to_dict_converts_row(tmp_path):
|
|
db = Database(db_path=tmp_path / "gateway.db")
|
|
db.execute(
|
|
"INSERT INTO accounts (id, email, created_at, registration_token_hash, "
|
|
"account_token_hash, box_limit, route_limit_per_box) "
|
|
"VALUES ('acc1', 'a@example.com', '2026-01-01T00:00:00', 'h1', 'h2', 5, 5)"
|
|
)
|
|
row = db.query_one("SELECT * FROM accounts WHERE id = ?", ("acc1",))
|
|
as_dict = row_to_dict(row)
|
|
assert as_dict["id"] == "acc1"
|
|
assert as_dict["email"] == "a@example.com"
|
|
|
|
|
|
def test_row_to_dict_none():
|
|
assert row_to_dict(None) is None
|