From d3ad243c4ae3a273f623bd5fc631e3266aa4d0e4 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Wed, 30 Sep 2026 11:49:56 +0200 Subject: fix: only the owner decides who hosts a group, and nobody is made a member unasked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hub: a node may host a group only if its account owns it or the owner approved that node (new `group_hosts`). Membership was the ceiling, and every member holds the group key, so any member's node could register as a host and be the one clients kept. A node claiming a group it may not host is recorded as a request; the owner is notified once and approves or refuses it (GET/POST/DELETE /v1/groups/{id}/hosts[/{node_id}]), which takes effect on a connected node at once. - hub: an owner adding a username creates an invitation (new `group_invitations`), accepted or declined by the invitee (/v1/groups/invitations, /{id}/invitation/accept|decline). Until then the group is not listed, not dialled, not searched and not in any token. Invitation links, open joins and group creation still make members directly: they are the account's own act. - hub: the MNP token names only the group it is minted for (group_id is now required), so a node operator no longer learns a member's other groups. - SPA: invitations on the home page; invited people and host requests in the group's settings; the transport sends group_id. Ten catalogues. - Browser probes for both screens, run in Chrome and Firefox. - Design §5.2, §7.2, §7.3, AV32, AV33; protocol §6.3; user guide. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-hub/tests/membership.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/meshbay-hub/tests/membership.py (limited to 'packages/meshbay-hub/tests/membership.py') diff --git a/packages/meshbay-hub/tests/membership.py b/packages/meshbay-hub/tests/membership.py new file mode 100644 index 0000000..041eb74 --- /dev/null +++ b/packages/meshbay-hub/tests/membership.py @@ -0,0 +1,39 @@ +""" +Making somebody a member, the way the product does it. + +An owner adding a username creates an *invitation*; the account becomes a +member only when it accepts (`POST /v1/groups/{id}/invitation/accept`). Tests +that need a member go through both steps, with a token of the invitee's own — +a shortcut that wrote `GroupMember` directly would test a hub where adding +someone still made them a member without asking, which is the hole this +closed. +""" + +from meshbay_hub.auth import issue_access_token +from meshbay_hub.db.engine import get_session_factory +from meshbay_hub.db.models import User +from sqlalchemy import select + + +async def token_of(username: str) -> str: + async with get_session_factory()() as db: + uid = await db.scalar(select(User.id).where(User.username == username)) + assert uid, f"no such account {username!r}" + return issue_access_token(uid) + + +async def accept_invitation(client, group_id: str, username: str) -> None: + tok = await token_of(username) + r = await client.post(f"/v1/groups/{group_id}/invitation/accept", + headers={"Authorization": f"Bearer {tok}"}) + assert r.status_code == 200, r.text + + +async def add_member(client, group_id: str, username: str, owner_headers: dict): + """Invite, then accept as the invitee. Returns the invitation response.""" + r = await client.post(f"/v1/groups/{group_id}/members/{username}", json={}, + headers=owner_headers) + assert r.status_code in (200, 201), r.text + if r.json().get("status") == "invited": + await accept_invitation(client, group_id, username) + return r -- cgit v1.2.3