fix(2): mattermost functional tests share a deterministic admin bootstrap (_mm.bootstrap_admin) — only ONE unauthenticated first-user creation is allowed, so the multi-user test no longer collides with create_message
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -19,43 +19,20 @@ import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
|
||||
import _mm # noqa: E402
|
||||
from harness import http as harness_http # noqa: E402
|
||||
|
||||
# Password must satisfy mattermost's default policy (>=5 chars; use a clearly strong one).
|
||||
_ADMIN_PW = "Ccci-Test-Pw-2026!"
|
||||
|
||||
|
||||
def _bearer(token: str) -> dict[str, str]:
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
def test_create_message_roundtrip(live_app):
|
||||
base = f"https://{live_app}/api/v4"
|
||||
uniq = uuid.uuid4().hex[:10]
|
||||
|
||||
# 1) Bootstrap first user (system admin on a fresh server). username: lowercase alnum.
|
||||
username = f"ccci{uniq}"
|
||||
email = f"{username}@ccci.example.com"
|
||||
status, user = harness_http.http_post(
|
||||
f"{base}/users",
|
||||
data={"email": email, "username": username, "password": _ADMIN_PW},
|
||||
timeout=30,
|
||||
)
|
||||
assert status in (200, 201) and isinstance(user, dict) and user.get("id"), (
|
||||
f"first-user creation failed: HTTP {status}, body={user!r}"
|
||||
)
|
||||
|
||||
# 2) Login → token in the `Token` response header.
|
||||
status, _, hdrs = harness_http.post_with_headers(
|
||||
f"{base}/users/login",
|
||||
data={"login_id": email, "password": _ADMIN_PW},
|
||||
timeout=30,
|
||||
)
|
||||
assert status == 200, f"login failed: HTTP {status}"
|
||||
token = hdrs.get("Token") or hdrs.get("token")
|
||||
assert token, f"login returned no Token header; headers={list(hdrs.keys())}"
|
||||
auth = _bearer(token)
|
||||
# 1-2) Bootstrap the shared system admin (first user on a fresh server, else log in as it).
|
||||
# mattermost allows only ONE unauthenticated first-user creation, and several functional tests
|
||||
# share this deployment — so all bootstrap the same deterministic admin (see _mm.bootstrap_admin).
|
||||
auth = _mm.bearer(_mm.bootstrap_admin(base))
|
||||
|
||||
# 3) Create a team, then an open channel in it.
|
||||
status, team = harness_http.http_post(
|
||||
|
||||
Reference in New Issue
Block a user