feat: add unique super administrator and role management

This commit is contained in:
wlx committed 2026-09-17 19:03:51 +08:00
1 parent 9e731e47b9
commit 386d15cde2
16 files changed
+455 -24

No files matched your search

+4 -3
View File
@@ -207,10 +207,11 @@ def smoke(config, mode, login=False):
if login:
api = config["services"]["moyi-api"]["environment"]
request("/api/auth/login", payload={"account": api["ADMIN_ACCOUNT"], "password": api["ADMIN_PASSWORD"]})
if json.loads(request("/api/auth/me"))["user"]["role"] != "admin":
fail("Admin login/cookie verification failed.")
if json.loads(request("/api/auth/me"))["user"]["role"] != "super_admin":
fail("Super administrator login/cookie verification failed.")
request("/api/admin/users")
request("/api/auth/logout", 204, {})
print("Initial admin login + session cookie OK. Audit records were created.")
print("Initial super administrator login + session cookie OK. Audit records were created.")
print("Frontend, backend, authentication boundary and management endpoint checks passed.")
+35
View File
@@ -4,6 +4,7 @@ import shutil
import subprocess
from pathlib import Path
import tempfile
from types import SimpleNamespace
import unittest
from unittest.mock import patch
@@ -36,6 +37,40 @@ def configuration():
class DeploymentTests(unittest.TestCase):
def test_login_smoke_requires_super_admin_and_checks_management(self):
cfg = configuration()
cfg["services"]["moyi-api"]["environment"]["ADMIN_ACCOUNT"] = "adimin"
for role in ("super_admin", "admin", "user"):
paths = []
def response(request, timeout):
path = deploy.urllib.parse.urlsplit(request.full_url).path
paths.append(path)
if path == "/":
code, body = 200, b"<html></html>"
elif path == "/health":
code, body = 200, b'{"status":"ok"}'
elif path == "/api/auth/me" and paths.count(path) == 2:
code, body = 200, json.dumps({"user": {"role": role}}).encode()
elif path in ("/api/auth/me", "/v1/models"):
code, body = 401, b"{}"
elif path == "/actuator/health":
code, body = 404, b"{}"
elif path == "/api/auth/logout":
code, body = 204, b""
else:
code, body = 200, b"{}"
return SimpleNamespace(code=code, read=lambda: body)
with self.subTest(role=role), patch.object(deploy.urllib.request, "build_opener", return_value=SimpleNamespace(open=response)):
if role == "super_admin":
deploy.smoke(cfg, "tunnel", True)
self.assertIn("/api/admin/users", paths)
self.assertEqual(paths[-1], "/api/auth/logout")
else:
with self.assertRaisesRegex(ValueError, "Super administrator"):
deploy.smoke(cfg, "tunnel", True)
def test_tunnel_config(self):
deploy.validate_config(configuration(), "tunnel")