from __future__ import annotations def test_license_server_api_activates_card(tmp_path): from fastapi.testclient import TestClient from license_server import api from license_server.core import DEV_PRIVATE_KEY_PEM, LicenseService db_path = tmp_path / "license.db" service = LicenseService(db_path=db_path, private_key_pem=DEV_PRIVATE_KEY_PEM) card = service.create_cards(days=5, count=1, customer="api-user")[0] client = TestClient(api.create_app(service=service)) health = client.get("/api/v1/health") resp = client.post( "/api/v1/activate", json={"card_key": card.code, "machine_fingerprint": "machine-api"}, ) assert health.status_code == 200 assert health.json()["ok"] is True assert resp.status_code == 200 body = resp.json() assert body["ok"] is True assert body["license"]["payload"]["customer"] == "api-user" assert body["license"]["payload"]["machine_fingerprint"] == "machine-api" def test_license_server_api_rejects_unknown_card(tmp_path): from fastapi.testclient import TestClient from license_server import api from license_server.core import DEV_PRIVATE_KEY_PEM, LicenseService service = LicenseService(db_path=tmp_path / "license.db", private_key_pem=DEV_PRIVATE_KEY_PEM) client = TestClient(api.create_app(service=service)) resp = client.post( "/api/v1/activate", json={"card_key": "DG-NOPE-NOPE-NOPE", "machine_fingerprint": "machine-api"}, ) assert resp.status_code == 404 assert resp.json()["reason"] == "not_found"