feat: add unique super administrator and role management
This commit is contained in:
1 parent
9e731e47b9
commit
386d15cde2
16 files changed
+455
-24
No files matched your search
@@ -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")
|
||||
|
||||
|
||||
Reference in new issue
Block a user