Skip to content

Commit d1a91a1

Browse files
matt2eclaude
andcommitted
fix(communities): accept invite links and bare hosts in Join a community
Join a community refused the invite link Buzz itself mints (https://<host>/invite/<code>). It also refused a bare host such as secondary.example, telling the user to enter a wss:// or https:// relay URL. The no-community landing accepted the link but refused bare hosts, while the native first-run field accepted both. Both fields now read input through parsePastedInvite: - Its final fallback is enteredRelayOrigin instead of communityDestination, so a bare host is read as wss:// and then passes the same secure-origin checks. - The dialog's destination step parses with it and keeps the communityDestination check on the parsed origin. An invite link's code fills Invite code, as the invite prop does. - An unreadable value gets the native field's copy, "Enter a community address or invite link." - ws://, http://, credentials, other paths, query and fragment are still rejected. - An origin supplied by an OS invite parses with no code, so it leaves the prefilled code alone. Accepted consequences: - Typed text on the landing no longer resolves BUZZ_COMMUNITY_ALIASES, matching the rule that typed addresses never resolve aliases. - A dotted bare code such as v2.invite now reads as https://v2.invite and fails at lookup rather than inline. - Edit connection shares the destination step, so it also takes bare hosts and invite links. - The native CommunityUrlField and the relay's invite URL format are unchanged. docs/communities.md now describes bare hosts and invite links, and the help guide says Join a community takes either. Tests: - invite-link adds bare-host accepts, moves v2.invite to the accept list, and adds rejects for the bare-host forms of the refused inputs. - CommunityDialog swaps not-a-relay for "not a relay" with the new copy, and adds invite-link and bare-host lookups. - CommunityLanding adds a bare-host lookup. - All 9 new or changed cases fail against main's production code and pass with the fix. Validation on this snapshot: - Unit tests for invite-link, CommunityDialog, CommunityLanding and CommunityUrlField: 92 passed, with CommunityUrlField unchanged. - tests/browser/dialog-actions.spec.mjs and navigation-join.spec.mjs: 4/4 in Chromium and 4/4 in WebKit. - pnpm typecheck and pnpm lint pass. After-fix recording check: PASSED. The note's flow, rec2-community-join-invite-link, asserts the old refusals, so it was re-run as a copy with the same stubs and steps and inverted expectations (Chromium 1280x800, browser build of this tree). - In Join a community, the minted link opens Your profile, and Back shows Invite code "fixture" under https://primary.example. - secondary.example is looked up as https://secondary.example with no Invite code field, and wss://secondary.example still works. - On the no-community landing, both secondary.example and the minted link reach Your profile, with no inline refusal. Not checked: - The native desktop build was not run. - The policy-message interaction with the unmerged relay trust policy PR depends on that PR keeping communityDestination in the destination step, which this change does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 0b2dfbf commit d1a91a1

7 files changed

Lines changed: 107 additions & 14 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ the interface unless an available tool actually supports that action.
5959
**Settings → Buzz → Identity → Organization sign-in**.
6060
- A community invite or address connects someone to a community; creating an
6161
identity alone does not grant membership. The same identity can be used in
62-
more than one community.
62+
more than one community. To add another, choose **Join a community** in the
63+
community picker and paste an invite link or type an address such as
64+
`relay.example.com`; an invite link fills in its invite code.
6365
- Set or clear your status from the profile menu, or with **Update status** /
6466
**Set a status** on your own profile.
6567
- Where a community verifies names, the profile check appears beside the verified

‎docs/communities.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ no community saved, the picker is labeled **Communities**; otherwise it shows th
2323
selected community's icon or the Personal space globe. There
2424
is no destination dropdown. Accepts `wss://` or `https://` origins, for example
2525
`wss://relay.example.com` or `wss://other.example.com`, and other
26-
Buzz-compatible community relays. No community is pre-joined; a packaged build
27-
that sets [`BUZZ_DEFAULT_COMMUNITY_URL`](configuration.md) only preselects one.
26+
Buzz-compatible community relays; a bare host such as `relay.example.com` is
27+
read as `wss://`. The relay's invite link, `https://<host>/invite/<code>`, is
28+
looked up at its origin and its code fills **Invite code**. The no-community
29+
landing reads its field the same way. No community is pre-joined; a packaged
30+
build that sets [`BUZZ_DEFAULT_COMMUNITY_URL`](configuration.md) only preselects
31+
one.
2832

2933
Surrounding whitespace, host case, a final DNS dot, default port 443 and a single
3034
root slash normalize to the same HTTPS origin. Non-default ports are preserved.
31-
Credentials, insecure schemes, non-root paths, query and fragment are rejected,
35+
Credentials, insecure schemes, other paths, query and fragment are rejected,
3236
not silently stripped. Continue starts discovery and authenticated profile reads;
3337
typing does not contact a relay. The canonical origin stays visible before policy
3438
acceptance or profile publication. Failed setup keeps the typed input and current

‎src/features/communities/CommunityDialog.test.tsx‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ it("keeps join unavailable after native identity hydration, but still saves a lo
415415
}
416416
});
417417

418-
it.each(["", "not-a-relay"])(
418+
it.each(["", "not a relay"])(
419419
"shows inline relay validation for %j without contacting a relay",
420420
async (value) => {
421421
const user = userEvent.setup();
@@ -439,11 +439,11 @@ it.each(["", "not-a-relay"])(
439439
if (value) await user.type(input, value);
440440
await user.click(screen.getByRole("button", { name: "Continue" }));
441441
expect(await screen.findByRole("alert")).toHaveTextContent(
442-
"Enter a wss:// or https:// relay URL",
442+
"Enter a community address or invite link.",
443443
);
444444
expect(input).toHaveAttribute("aria-invalid", "true");
445445
expect(input).toHaveAccessibleDescription(
446-
/Enter a wss:\/\/ or https:\/\/ relay URL/,
446+
/Enter a community address or invite link\./,
447447
);
448448
expect(fetch).not.toHaveBeenCalled();
449449
await user.clear(input);
@@ -452,6 +452,50 @@ it.each(["", "not-a-relay"])(
452452
},
453453
);
454454

455+
it.each([
456+
["an invite link", "https://Relay.Example/invite/v2.abc", "v2.abc"],
457+
["a bare host", "relay.example", undefined],
458+
])(
459+
"looks up the community for %s and prefills only an invite link's code",
460+
async (_, value, code) => {
461+
const user = userEvent.setup();
462+
const requests = vi.fn(async (url: string) => {
463+
const route = String(url).split("/").at(-1);
464+
if (route === "register") return Response.json({ id: "x" });
465+
if (route === "info")
466+
return Response.json({ name: "Fixture", membershipRequired: false });
467+
throw new Error(`Unexpected request: ${url}`);
468+
});
469+
vi.stubGlobal("fetch", requests);
470+
const communities = {
471+
snapshot: () => ({
472+
status: "ready",
473+
relayAvailable: true,
474+
profile: { name: "", picture: "" },
475+
}),
476+
} as unknown as Communities;
477+
render(
478+
<CommunityDialog
479+
communities={communities}
480+
mode="join"
481+
close={() => {}}
482+
/>,
483+
);
484+
await user.click(screen.getByLabelText("Community URL"));
485+
await user.paste(value);
486+
await user.click(screen.getByRole("button", { name: "Continue" }));
487+
// The access step names the canonical origin the lookup went to.
488+
expect(await screen.findByText("https://relay.example")).toBeVisible();
489+
expect(requests).toHaveBeenCalledWith(
490+
`/api/relay/${encodeURIComponent("https://relay.example")}/info`,
491+
expect.anything(),
492+
);
493+
if (code) expect(screen.getByLabelText("Invite code")).toHaveValue(code);
494+
else expect(screen.queryByLabelText("Invite code")).toBeNull();
495+
expect(screen.queryByRole("alert")).toBeNull();
496+
},
497+
);
498+
455499
it("prefills an invite but requires explicit discovery and claim before membership", async () => {
456500
const user = userEvent.setup();
457501
const requests = vi.fn(async (url: string, init?: RequestInit) => {

‎src/features/communities/CommunityDialog.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { Button } from "../../shared/design-system/ui/Button";
99
import { communityRequest, inspectProfile, type CommunityInfo } from "./api";
1010
import type { Communities, PersonalProfile } from "./service";
1111
import { canSaveProfile, ProfileFields, profilesEqual } from "./ProfileFields";
12-
import { communityDestination, relayOrigin } from "./destination";
12+
import { communityDestination } from "./destination";
13+
import { parsePastedInvite } from "./invite-link";
1314
import { nativeIdentityEnabled } from "../identity/service";
1415
import { readErrorKind } from "../relay/errors";
1516
import { createJoinJournal, type PendingJoin } from "./join-journal";
@@ -161,7 +162,15 @@ export function CommunityDialog({
161162
if (uploading || unavailable) return;
162163
if (step === "destination") {
163164
await work(async () => {
164-
const next = communityDestination(relayOrigin(url));
165+
const entered = parsePastedInvite(url);
166+
if (!entered)
167+
throw new Error("Enter a community address or invite link.");
168+
const next = communityDestination(entered.community);
169+
// A pasted invite link carries its code the way an opened invite does.
170+
if (entered.code) {
171+
setCode(entered.code);
172+
setNeedsInvite(true);
173+
}
165174
setDestination(next);
166175
const value = await communityRequest<CommunityInfo>(next.id, "info");
167176
if (!mounted.current) return;

‎src/features/communities/CommunityLanding.test.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ it("opens the join steps from a community address", async () => {
9999
);
100100
});
101101

102+
it("reads a bare host as a secure community address", async () => {
103+
const user = userEvent.setup();
104+
landing();
105+
await user.type(
106+
screen.getByLabelText("Invite link or community URL"),
107+
"relay.example",
108+
);
109+
await user.click(screen.getByRole("button", { name: "Join" }));
110+
const dialog = await screen.findByRole("main");
111+
expect(await within(dialog).findByLabelText("Invite code")).toHaveValue("");
112+
expect(communityRequest).toHaveBeenLastCalledWith(
113+
"https://relay.example",
114+
"info",
115+
);
116+
});
117+
102118
it("asks for an invite link or community URL when the pasted value is neither", async () => {
103119
const user = userEvent.setup();
104120
landing();

‎src/features/communities/invite-link.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,29 @@ it.each([
7979
{ community: "https://relay.example", code: "v2.invite" },
8080
],
8181
["wss://relay.example", { community: "https://relay.example", code: "" }],
82+
// A typed address may omit its scheme, as in the native first-run field.
83+
["relay.example", { community: "https://relay.example", code: "" }],
84+
[
85+
" Relay.Example.com:8443 ",
86+
{ community: "https://relay.example.com:8443", code: "" },
87+
],
88+
["localhost:3000", { community: "https://localhost:3000", code: "" }],
89+
// A bare invite code with a dot reads as a host, so it fails at lookup.
90+
["v2.invite", { community: "https://v2.invite", code: "" }],
8291
])("reads a pasted invite or address: %s", (input, expected) => {
8392
expect(parsePastedInvite(input)).toEqual(expected);
8493
});
8594

8695
it.each([
8796
"",
88-
"v2.invite",
97+
"not a relay",
98+
"ws://relay.example",
99+
"http://relay.example",
100+
"wss://user:[email protected]",
101+
102+
"relay.example/invite/x",
103+
"relay.example?x=1",
104+
"relay.example#x",
89105
"http://relay.example/invite/x",
90106
"https://[email protected]/invite/x",
91107
"https://relay.example/invite/x?redirect=evil",

‎src/features/communities/invite-link.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { communityDestination } from "./destination";
1+
import { communityDestination, enteredRelayOrigin } from "./destination";
22

33
export type InviteLink = Readonly<{
44
community: string;
@@ -46,7 +46,9 @@ export function parseInviteLink(input: string): InviteLink | null {
4646
}
4747
}
4848

49-
/** A pasted invite: the app link, the relay's invite page, or a bare community address. */
49+
/** Typed or pasted community input: the app link, the relay's invite page, or
50+
* a community address, where a bare host is a secure relay. A typed address
51+
* never resolves an alias. */
5052
export function parsePastedInvite(input: string): InviteLink | null {
5153
const value = input.trim();
5254
if (value.length > 4096) return null;
@@ -67,10 +69,10 @@ export function parsePastedInvite(input: string): InviteLink | null {
6769
: null;
6870
}
6971
} catch {
70-
// Not a URL; a bare address still fails closed below.
72+
// Not a URL; a bare host is read as wss:// below.
7173
}
7274
try {
73-
return { community: communityDestination(value).url, code: "" };
75+
return { community: enteredRelayOrigin(value), code: "" };
7476
} catch {
7577
return null;
7678
}

0 commit comments

Comments
 (0)