web: 'Invite someone' page with the command to join through this node
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
@@ -206,6 +206,8 @@ export interface GatewayOptions {
|
||||
regions?: string[];
|
||||
/** The device certificate the node reports in /status; unset, it says nothing (an older node). */
|
||||
cert?: { expires_at: number; can_renew: boolean };
|
||||
/** The addresses the node says others can join through; unset, it says nothing (an older node). */
|
||||
share?: string[];
|
||||
}
|
||||
|
||||
export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
@@ -294,6 +296,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
listings: opts.listings.length,
|
||||
difficulty: DIFFICULTY,
|
||||
message_difficulty: 6,
|
||||
...(opts.share ? { share: opts.share } : {}),
|
||||
...(opts.cert ? { cert_expires_at: opts.cert.expires_at, can_renew: opts.cert.can_renew } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -194,3 +194,45 @@ test("the difficulty reported by the node is enforced as a minimum", async () =>
|
||||
await g.close();
|
||||
}
|
||||
});
|
||||
|
||||
const SHARE = "/ip4/8.8.8.8/tcp/4001/p2p/12D3KooWTest";
|
||||
|
||||
test("the invite page shows the command to join through this node", async () => {
|
||||
const g = await startGateway({ listings: [], share: [SHARE, "/ip4/1.1.1.1/tcp/4001/p2p/12D3KooWRelay/p2p-circuit/p2p/12D3KooWTest"] });
|
||||
try {
|
||||
const page = openPage(g.url, "#/invite");
|
||||
await page.waitFor(() => page.document.querySelector(".invite-command") !== null, "the command");
|
||||
assert.equal(page.document.querySelector(".invite-command")!.textContent, `allmende run --bootstrap ${SHARE}`);
|
||||
assert.match(page.document.querySelector("ul")!.textContent!, /p2p-circuit/, "the second address is listed");
|
||||
page.close();
|
||||
} finally {
|
||||
await g.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("the invite page says so when the node has no address to share, and for an older node", async () => {
|
||||
for (const share of [[], undefined]) {
|
||||
const g = await startGateway({ listings: [], ...(share ? { share } : {}) });
|
||||
try {
|
||||
const page = openPage(g.url, "#/invite", "de");
|
||||
await page.waitFor(() => /noch keine Adresse/.test(page.document.body.textContent!), "the explanation");
|
||||
assert.equal(page.document.querySelector(".invite-command"), null);
|
||||
page.close();
|
||||
} finally {
|
||||
await g.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("an address in the invite page is shown as text, never as HTML", async () => {
|
||||
const g = await startGateway({ listings: [], share: [SHARE, `<img src=x onerror="window.__pwned=3">`] });
|
||||
try {
|
||||
const page = openPage(g.url, "#/invite");
|
||||
await page.waitFor(() => page.document.querySelector("ul code") !== null, "the list");
|
||||
assert.equal(page.document.querySelector("ul img"), null);
|
||||
assert.equal((page.window as unknown as { __pwned?: number }).__pwned, undefined);
|
||||
page.close();
|
||||
} finally {
|
||||
await g.close();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user