summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_admin.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-15 02:16:39 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-15 02:21:01 +0200
commitbdefcd025604f2c3009fe5e0cc01213c2ba62a6a (patch)
treeeebd34aa234a9148045ca25b00bf7c8039e00ccf /packages/meshbay-hub/tests/test_admin.py
parent027e7d55f3bb57ba5150fd77e8f0114a0baf8d5c (diff)
downloadmeshbay-bdefcd025604f2c3009fe5e0cc01213c2ba62a6a.tar.gz
feat(hub): usernames are at least 8 characters at registration
Existing shorter accounts keep signing in. Test usernames padded to match. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XuNrwLf5EFWCMHzfoEvnpm
Diffstat (limited to 'packages/meshbay-hub/tests/test_admin.py')
-rw-r--r--packages/meshbay-hub/tests/test_admin.py56
1 files changed, 28 insertions, 28 deletions
diff --git a/packages/meshbay-hub/tests/test_admin.py b/packages/meshbay-hub/tests/test_admin.py
index ad48487..6f90ad0 100644
--- a/packages/meshbay-hub/tests/test_admin.py
+++ b/packages/meshbay-hub/tests/test_admin.py
@@ -33,7 +33,7 @@ async def _login(client, username, password="testpass99"):
return r.json()["access_token"]
-async def _setup_admin(client, admin_name="admin"):
+async def _setup_admin(client, admin_name="admin_test"):
user_id = await _register(client, admin_name, email=f"{admin_name}@x.com")
set_admin_usernames([admin_name])
token = await _login(client, admin_name)
@@ -44,8 +44,8 @@ async def _setup_admin(client, admin_name="admin"):
@pytest.mark.asyncio
async def test_admin_stats_requires_moderator(client):
- await _register(client, "normie")
- token = await _login(client, "normie")
+ await _register(client, "normie_test")
+ token = await _login(client, "normie_test")
r = await client.get("/v1/admin/stats", headers={"Authorization": f"Bearer {token}"})
assert r.status_code == 403
@@ -64,14 +64,14 @@ async def test_admin_stats_allowed_for_config_admin(client):
@pytest.mark.asyncio
async def test_admin_stats_allowed_for_db_moderator(client):
- _, admin_token = await _setup_admin(client, "boss")
- mod_id = await _register(client, "moduser")
+ _, admin_token = await _setup_admin(client, "boss_test")
+ mod_id = await _register(client, "moduser_test")
r = await client.patch(f"/v1/admin/users/{mod_id}",
json={"role": "moderator"},
headers={"Authorization": f"Bearer {admin_token}"})
assert r.status_code == 200
- mod_token = await _login(client, "moduser")
+ mod_token = await _login(client, "moduser_test")
r = await client.get("/v1/admin/stats", headers={"Authorization": f"Bearer {mod_token}"})
assert r.status_code == 200
@@ -81,8 +81,8 @@ async def test_admin_stats_allowed_for_db_moderator(client):
@pytest.mark.asyncio
async def test_admin_list_users(client):
_, token = await _setup_admin(client)
- await _register(client, "alice", email="a@x.com")
- await _register(client, "bob", email="b@x.com")
+ await _register(client, "alice_test", email="a@x.com")
+ await _register(client, "bob_test", email="b@x.com")
r = await client.get("/v1/admin/users", headers={"Authorization": f"Bearer {token}"})
assert r.status_code == 200
@@ -94,27 +94,27 @@ async def test_admin_list_users(client):
@pytest.mark.asyncio
async def test_admin_list_users_search(client):
_, token = await _setup_admin(client)
- await _register(client, "alice", email="a@x.com")
- await _register(client, "bob", email="b@x.com")
+ await _register(client, "alice_test", email="a@x.com")
+ await _register(client, "bob_test", email="b@x.com")
r = await client.get("/v1/admin/users?q=ali",
headers={"Authorization": f"Bearer {token}"})
assert r.status_code == 200
data = r.json()
assert data["total"] == 1
- assert data["users"][0]["username"] == "alice"
+ assert data["users"][0]["username"] == "alice_test"
@pytest.mark.asyncio
async def test_admin_get_user_detail(client):
_, token = await _setup_admin(client)
- uid = await _register(client, "alice", email="alice@example.com")
+ uid = await _register(client, "alice_test", email="alice@example.com")
r = await client.get(f"/v1/admin/users/{uid}",
headers={"Authorization": f"Bearer {token}"})
assert r.status_code == 200
data = r.json()
- assert data["username"] == "alice"
+ assert data["username"] == "alice_test"
assert data["role"] == "user"
assert data["status"] == "active"
assert data["group_count"] == 0
@@ -124,8 +124,8 @@ async def test_admin_get_user_detail(client):
@pytest.mark.asyncio
async def test_admin_suspend_unsuspend_user(client):
_, token = await _setup_admin(client)
- uid = await _register(client, "alice", email="a@x.com")
- alice_token = await _login(client, "alice")
+ uid = await _register(client, "alice_test", email="a@x.com")
+ alice_token = await _login(client, "alice_test")
r = await client.patch(f"/v1/admin/users/{uid}",
json={"status": "suspended"},
@@ -151,7 +151,7 @@ async def test_admin_suspend_unsuspend_user(client):
@pytest.mark.asyncio
async def test_admin_change_role(client):
_, token = await _setup_admin(client)
- uid = await _register(client, "alice", email="a@x.com")
+ uid = await _register(client, "alice_test", email="a@x.com")
r = await client.patch(f"/v1/admin/users/{uid}",
json={"role": "moderator"},
@@ -165,14 +165,14 @@ async def test_moderator_cannot_change_roles_or_revoke(client):
"""A moderator suspends and restores (reversible); it cannot promote anyone
or hard-revoke, which would be a path from the moderation role to full
instance control."""
- _, admin_token = await _setup_admin(client, "boss")
- mod_id = await _register(client, "moduser")
+ _, admin_token = await _setup_admin(client, "boss_test")
+ mod_id = await _register(client, "moduser_test")
await client.patch(f"/v1/admin/users/{mod_id}", json={"role": "moderator"},
headers={"Authorization": f"Bearer {admin_token}"})
- mod_token = await _login(client, "moduser")
+ mod_token = await _login(client, "moduser_test")
mod_h = {"Authorization": f"Bearer {mod_token}"}
- victim = await _register(client, "victim", email="v@x.com")
+ victim = await _register(client, "victim_test", email="v@x.com")
# No promoting an accomplice.
r = await client.patch(f"/v1/admin/users/{victim}", json={"role": "admin"},
@@ -185,7 +185,7 @@ async def test_moderator_cannot_change_roles_or_revoke(client):
assert r.status_code == 403
# No touching an admin's account.
- admin2 = await _register(client, "admin2", email="a2@x.com")
+ admin2 = await _register(client, "admin2_test", email="a2@x.com")
await client.patch(f"/v1/admin/users/{admin2}", json={"role": "admin"},
headers={"Authorization": f"Bearer {admin_token}"})
r = await client.patch(f"/v1/admin/users/{admin2}", json={"status": "suspended"},
@@ -210,7 +210,7 @@ async def test_admin_cannot_modify_self(client):
@pytest.mark.asyncio
async def test_admin_invalid_role_rejected(client):
_, token = await _setup_admin(client)
- uid = await _register(client, "alice", email="a@x.com")
+ uid = await _register(client, "alice_test", email="a@x.com")
r = await client.patch(f"/v1/admin/users/{uid}",
json={"role": "superuser"},
headers={"Authorization": f"Bearer {token}"})
@@ -256,7 +256,7 @@ async def test_admin_suspend_group(client):
@pytest.mark.asyncio
async def test_admin_logs(client):
_, token = await _setup_admin(client)
- await _register(client, "alice", email="a@x.com")
+ await _register(client, "alice_test", email="a@x.com")
r = await client.get("/v1/admin/logs",
headers={"Authorization": f"Bearer {token}"})
@@ -271,8 +271,8 @@ async def test_admin_logs(client):
@pytest.mark.asyncio
async def test_admin_logs_filter_by_event(client):
_, token = await _setup_admin(client)
- await _register(client, "alice", email="a@x.com")
- await _login(client, "alice")
+ await _register(client, "alice_test", email="a@x.com")
+ await _login(client, "alice_test")
r = await client.get("/v1/admin/logs?event=login",
headers={"Authorization": f"Bearer {token}"})
@@ -285,12 +285,12 @@ async def test_admin_logs_filter_by_event(client):
@pytest.mark.asyncio
async def test_users_me(client):
- await _register(client, "alice", email="a@x.com")
- token = await _login(client, "alice")
+ await _register(client, "alice_test", email="a@x.com")
+ token = await _login(client, "alice_test")
r = await client.get("/v1/users/me",
headers={"Authorization": f"Bearer {token}"})
assert r.status_code == 200
data = r.json()
- assert data["username"] == "alice"
+ assert data["username"] == "alice_test"
assert data["role"] == "user"
assert data["status"] == "active"