Renew the device certificate from the browser, with the recovery phrase
Within the last 30 days the owner page offers it. The node signs a new certificate for the same device key (peer ID and listings stay), saves it, and signs again own listings that would outlive the old certificate. The phrase is used for one request and not kept; another identity's phrase and no-phrase identities are refused. Device.Current gives the certificate to sign with while a renewal happens. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
Vendored
+97
-5
@@ -233,6 +233,16 @@ var de = {
|
||||
"rep.done": "Gemeldet.",
|
||||
"rep.withdrawn": "Zur\xFCckgezogen.",
|
||||
"rep.mine": "Deine Meldung: {what}.",
|
||||
"cert.title": "Ger\xE4te-Zertifikat",
|
||||
"cert.soon": "Das Zertifikat dieses Knotens l\xE4uft am {date} ab (in {n} Tagen). Danach geht der Knoten nicht mehr an und deine Anzeigen verschwinden.",
|
||||
"cert.expired": "Das Zertifikat dieses Knotens ist am {date} abgelaufen. Erneuere es jetzt.",
|
||||
"cert.noPhrase": "Diese Identit\xE4t hat keine Wiederherstellungsphrase und l\xE4sst sich nicht erneuern. Lege mit \u201Eallmende init --no-phrase\u201C in einem leeren Datenverzeichnis eine neue an.",
|
||||
"cert.intro": "Gib die zw\xF6lf W\xF6rter deiner Wiederherstellungsphrase ein. Der Knoten stellt damit ein neues Zertifikat aus und vergisst sie sofort wieder. Der Schl\xFCssel des Ger\xE4ts bleibt gleich, nichts wird widerrufen.",
|
||||
"cert.phrase": "Die zw\xF6lf W\xF6rter",
|
||||
"cert.renew": "Zertifikat erneuern",
|
||||
"cert.working": "Wird erneuert \u2026",
|
||||
"cert.done": "Erneuert. Das Zertifikat gilt jetzt bis zum {date}.",
|
||||
"cert.fail": "Das hat nicht geklappt: {detail}",
|
||||
"rep.title": "Meldungen",
|
||||
"rep.tipsIntro": "Hinweise von Besuchern dieses Knotens. Sie blenden nichts aus: du entscheidest, ob du selbst meldest.",
|
||||
"rep.none": "Keine Hinweise von Besuchern.",
|
||||
@@ -521,6 +531,16 @@ var en = {
|
||||
"rep.done": "Reported.",
|
||||
"rep.withdrawn": "Withdrawn.",
|
||||
"rep.mine": "Your report: {what}.",
|
||||
"cert.title": "Device certificate",
|
||||
"cert.soon": "This node's certificate expires on {date} (in {n} days). After that the node will not start and your listings disappear.",
|
||||
"cert.expired": "This node's certificate expired on {date}. Renew it now.",
|
||||
"cert.noPhrase": "This identity has no recovery phrase, so it cannot be renewed. Make a new one with \u201Callmende init --no-phrase\u201D in an empty data directory.",
|
||||
"cert.intro": "Enter the twelve words of your recovery phrase. The node signs a new certificate with them and forgets them at once. The device key stays the same and nothing is revoked.",
|
||||
"cert.phrase": "The twelve words",
|
||||
"cert.renew": "Renew certificate",
|
||||
"cert.working": "Renewing\u2026",
|
||||
"cert.done": "Renewed. The certificate is now valid until {date}.",
|
||||
"cert.fail": "That did not work: {detail}",
|
||||
"rep.title": "Reports",
|
||||
"rep.tipsIntro": "Tips from visitors of this node. They hide nothing: you decide whether to report yourself.",
|
||||
"rep.none": "No tips from visitors.",
|
||||
@@ -5021,6 +5041,9 @@ async function deleteAddress(listing) {
|
||||
async function setRegions(regions) {
|
||||
return (await call("PUT", "/api/v1/regions", { regions })).regions;
|
||||
}
|
||||
async function renewCertificate(phrase) {
|
||||
return (await call("PUT", "/api/v1/certificate", { phrase })).cert_expires_at;
|
||||
}
|
||||
async function createListing(d) {
|
||||
return await call("POST", "/api/v1/listings", d);
|
||||
}
|
||||
@@ -5039,6 +5062,74 @@ async function renewListing(author, id, days = MAX_LIFETIME_DAYS) {
|
||||
return updateListing(id, draftFromListing(l, days));
|
||||
}
|
||||
|
||||
// src/certificate.ts
|
||||
var RENEW_WINDOW_DAYS = 30;
|
||||
function describe2(e2) {
|
||||
if (e2 instanceof Unauthorized) return t("reg.signedOut");
|
||||
if (e2 instanceof HttpError) return e2.detail;
|
||||
return t("send.network");
|
||||
}
|
||||
function certificatePanel() {
|
||||
const expires = state.node?.cert_expires_at;
|
||||
if (expires === void 0) return null;
|
||||
const days = Math.floor((expires - nowSeconds()) / 86400);
|
||||
if (days > RENEW_WINDOW_DAYS) return null;
|
||||
const root = h("section", { class: "panel certificate" });
|
||||
const lead = days >= 0 ? t("cert.soon", { date: date(expires), n: days }) : t("cert.expired", { date: date(expires) });
|
||||
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { class: "note warn", role: "status" }, lead)]);
|
||||
if (!state.node?.can_renew) {
|
||||
append(root, [h("p", { class: "muted" }, t("cert.noPhrase"))]);
|
||||
return root;
|
||||
}
|
||||
const phrase = h("input", {
|
||||
type: "password",
|
||||
name: "phrase",
|
||||
autocomplete: "off",
|
||||
autocapitalize: "none",
|
||||
spellcheck: "false",
|
||||
// a bare false would drop the attribute
|
||||
"aria-label": t("cert.phrase"),
|
||||
placeholder: t("cert.phrase")
|
||||
});
|
||||
const status = h("p", { class: "muted", role: "status" });
|
||||
const problem = h("p", { class: "error", role: "alert" });
|
||||
const button = h("button", { type: "submit", class: "btn primary" }, t("cert.renew"));
|
||||
const form = h(
|
||||
"form",
|
||||
{
|
||||
class: "compose",
|
||||
onsubmit: (ev) => {
|
||||
ev.preventDefault();
|
||||
const words = phrase.value.trim();
|
||||
problem.textContent = "";
|
||||
if (!words) {
|
||||
problem.textContent = t("cert.fail", { detail: t("cert.phrase") });
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
status.textContent = t("cert.working");
|
||||
void renewCertificate(words).then((until) => {
|
||||
phrase.value = "";
|
||||
if (state.node) state.node.cert_expires_at = until;
|
||||
clear(root);
|
||||
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { role: "status" }, t("cert.done", { date: date(until) }))]);
|
||||
}).catch((e2) => {
|
||||
button.disabled = false;
|
||||
status.textContent = "";
|
||||
problem.textContent = t("cert.fail", { detail: describe2(e2) });
|
||||
});
|
||||
}
|
||||
},
|
||||
h("p", { class: "muted" }, t("cert.intro")),
|
||||
phrase,
|
||||
h("div", { class: "actions" }, button),
|
||||
status,
|
||||
problem
|
||||
);
|
||||
root.append(form);
|
||||
return root;
|
||||
}
|
||||
|
||||
// src/owner.ts
|
||||
var VALID_DAYS = [1, 3, 7, 14, 30];
|
||||
var DEFAULT_DAYS = 7;
|
||||
@@ -5097,6 +5188,7 @@ async function showOwner(listingId, thread) {
|
||||
const listingsPane = h(
|
||||
"section",
|
||||
{ class: "pane pane-listings" },
|
||||
certificatePanel(),
|
||||
h("h2", { class: "pane-title" }, t("own.listings")),
|
||||
h("p", null, h("a", { class: "btn primary", href: "#/mine/new" }, t("own.new"))),
|
||||
listingsBox,
|
||||
@@ -5634,7 +5726,7 @@ async function sendTip(author, id, category, note) {
|
||||
await mine(body, bits);
|
||||
await postSignal(canonicalize(body));
|
||||
}
|
||||
function describe2(e2) {
|
||||
function describe3(e2) {
|
||||
if (e2 instanceof Unauthorized) return t("reg.signedOut");
|
||||
if (e2 instanceof HttpError) return e2.detail;
|
||||
return t("send.network");
|
||||
@@ -5695,7 +5787,7 @@ function visitorForm(l) {
|
||||
}).catch((e2) => {
|
||||
button.disabled = false;
|
||||
status.textContent = "";
|
||||
problem.textContent = t("rep.fail", { detail: describe2(e2) });
|
||||
problem.textContent = t("rep.fail", { detail: describe3(e2) });
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -5717,7 +5809,7 @@ function operatorForm(l, changed) {
|
||||
status.textContent = t(done);
|
||||
changed();
|
||||
}).catch((e2) => {
|
||||
problem.textContent = t("rep.fail", { detail: describe2(e2) });
|
||||
problem.textContent = t("rep.fail", { detail: describe3(e2) });
|
||||
});
|
||||
};
|
||||
return h(
|
||||
@@ -5769,7 +5861,7 @@ async function showReports() {
|
||||
tips = await getTips();
|
||||
} catch (e2) {
|
||||
if (e2 instanceof Unauthorized) return renderLogin(true);
|
||||
problem.textContent = describe2(e2);
|
||||
problem.textContent = describe3(e2);
|
||||
return;
|
||||
}
|
||||
clear(list);
|
||||
@@ -5786,7 +5878,7 @@ async function showReports() {
|
||||
function card(group, reload, problem) {
|
||||
const first = group[0];
|
||||
const fail2 = (e2) => {
|
||||
problem.textContent = describe2(e2);
|
||||
problem.textContent = describe3(e2);
|
||||
};
|
||||
const categories = [...new Set(group.map((g) => g.category))];
|
||||
return h(
|
||||
|
||||
@@ -14,6 +14,10 @@ export interface Status {
|
||||
difficulty: number;
|
||||
/** Proof-of-work bits a message needs; absent on nodes without messaging. */
|
||||
message_difficulty?: number;
|
||||
/** When this node's device certificate runs out, in unix seconds; absent on older nodes. */
|
||||
cert_expires_at?: number;
|
||||
/** Whether the owner can renew that certificate here (it needs the recovery phrase). */
|
||||
can_renew?: boolean;
|
||||
}
|
||||
|
||||
async function getJSON(url: string): Promise<unknown> {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// Renewing the node's device certificate from the browser.
|
||||
//
|
||||
// A certificate lasts at most a year. Within the last 30 days the owner's page
|
||||
// says so and offers the renewal: the owner types the twelve words once, the
|
||||
// node signs a new certificate with them and forgets them. The device key does
|
||||
// not change, so the node keeps its peer ID and every listing stays valid.
|
||||
|
||||
import { HttpError } from "./api.ts";
|
||||
import { append, clear, h } from "./dom.ts";
|
||||
import { date } from "./format.ts";
|
||||
import { t } from "./i18n.ts";
|
||||
import { Unauthorized, renewCertificate } from "./ownerApi.ts";
|
||||
import { nowSeconds, state } from "./state.ts";
|
||||
|
||||
/** How long before the end the page starts asking. */
|
||||
export const RENEW_WINDOW_DAYS = 30;
|
||||
|
||||
function describe(e: unknown): string {
|
||||
if (e instanceof Unauthorized) return t("reg.signedOut");
|
||||
if (e instanceof HttpError) return e.detail;
|
||||
return t("send.network");
|
||||
}
|
||||
|
||||
/**
|
||||
* The renewal panel, or null when there is nothing to say: the certificate has
|
||||
* plenty of time left, or the node is too old to report it.
|
||||
*/
|
||||
export function certificatePanel(): HTMLElement | null {
|
||||
const expires = state.node?.cert_expires_at;
|
||||
if (expires === undefined) return null;
|
||||
const days = Math.floor((expires - nowSeconds()) / 86_400);
|
||||
if (days > RENEW_WINDOW_DAYS) return null;
|
||||
|
||||
const root = h("section", { class: "panel certificate" });
|
||||
const lead = days >= 0 ? t("cert.soon", { date: date(expires), n: days }) : t("cert.expired", { date: date(expires) });
|
||||
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { class: "note warn", role: "status" }, lead)]);
|
||||
|
||||
if (!state.node?.can_renew) {
|
||||
append(root, [h("p", { class: "muted" }, t("cert.noPhrase"))]);
|
||||
return root;
|
||||
}
|
||||
|
||||
const phrase = h("input", {
|
||||
type: "password",
|
||||
name: "phrase",
|
||||
autocomplete: "off",
|
||||
autocapitalize: "none",
|
||||
spellcheck: "false", // a bare false would drop the attribute
|
||||
"aria-label": t("cert.phrase"),
|
||||
placeholder: t("cert.phrase"),
|
||||
}) as HTMLInputElement;
|
||||
const status = h("p", { class: "muted", role: "status" });
|
||||
const problem = h("p", { class: "error", role: "alert" });
|
||||
const button = h("button", { type: "submit", class: "btn primary" }, t("cert.renew")) as HTMLButtonElement;
|
||||
const form = h(
|
||||
"form",
|
||||
{
|
||||
class: "compose",
|
||||
onsubmit: (ev: Event) => {
|
||||
ev.preventDefault();
|
||||
const words = phrase.value.trim();
|
||||
problem.textContent = "";
|
||||
if (!words) {
|
||||
problem.textContent = t("cert.fail", { detail: t("cert.phrase") });
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
status.textContent = t("cert.working");
|
||||
void renewCertificate(words)
|
||||
.then((until) => {
|
||||
phrase.value = ""; // the words are not kept anywhere on this page
|
||||
if (state.node) state.node.cert_expires_at = until;
|
||||
clear(root);
|
||||
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { role: "status" }, t("cert.done", { date: date(until) }))]);
|
||||
})
|
||||
.catch((e: unknown) => {
|
||||
button.disabled = false;
|
||||
status.textContent = "";
|
||||
problem.textContent = t("cert.fail", { detail: describe(e) });
|
||||
});
|
||||
},
|
||||
},
|
||||
h("p", { class: "muted" }, t("cert.intro")),
|
||||
phrase,
|
||||
h("div", { class: "actions" }, button),
|
||||
status,
|
||||
problem,
|
||||
);
|
||||
root.append(form);
|
||||
return root;
|
||||
}
|
||||
@@ -94,6 +94,16 @@ const de = {
|
||||
"rep.done": "Gemeldet.",
|
||||
"rep.withdrawn": "Zurückgezogen.",
|
||||
"rep.mine": "Deine Meldung: {what}.",
|
||||
"cert.title": "Geräte-Zertifikat",
|
||||
"cert.soon": "Das Zertifikat dieses Knotens läuft am {date} ab (in {n} Tagen). Danach geht der Knoten nicht mehr an und deine Anzeigen verschwinden.",
|
||||
"cert.expired": "Das Zertifikat dieses Knotens ist am {date} abgelaufen. Erneuere es jetzt.",
|
||||
"cert.noPhrase": "Diese Identität hat keine Wiederherstellungsphrase und lässt sich nicht erneuern. Lege mit „allmende init --no-phrase“ in einem leeren Datenverzeichnis eine neue an.",
|
||||
"cert.intro": "Gib die zwölf Wörter deiner Wiederherstellungsphrase ein. Der Knoten stellt damit ein neues Zertifikat aus und vergisst sie sofort wieder. Der Schlüssel des Geräts bleibt gleich, nichts wird widerrufen.",
|
||||
"cert.phrase": "Die zwölf Wörter",
|
||||
"cert.renew": "Zertifikat erneuern",
|
||||
"cert.working": "Wird erneuert …",
|
||||
"cert.done": "Erneuert. Das Zertifikat gilt jetzt bis zum {date}.",
|
||||
"cert.fail": "Das hat nicht geklappt: {detail}",
|
||||
"rep.title": "Meldungen",
|
||||
"rep.tipsIntro": "Hinweise von Besuchern dieses Knotens. Sie blenden nichts aus: du entscheidest, ob du selbst meldest.",
|
||||
"rep.none": "Keine Hinweise von Besuchern.",
|
||||
@@ -407,6 +417,16 @@ const en: Record<keyof typeof de, string> = {
|
||||
"rep.done": "Reported.",
|
||||
"rep.withdrawn": "Withdrawn.",
|
||||
"rep.mine": "Your report: {what}.",
|
||||
"cert.title": "Device certificate",
|
||||
"cert.soon": "This node's certificate expires on {date} (in {n} days). After that the node will not start and your listings disappear.",
|
||||
"cert.expired": "This node's certificate expired on {date}. Renew it now.",
|
||||
"cert.noPhrase": "This identity has no recovery phrase, so it cannot be renewed. Make a new one with “allmende init --no-phrase” in an empty data directory.",
|
||||
"cert.intro": "Enter the twelve words of your recovery phrase. The node signs a new certificate with them and forgets them at once. The device key stays the same and nothing is revoked.",
|
||||
"cert.phrase": "The twelve words",
|
||||
"cert.renew": "Renew certificate",
|
||||
"cert.working": "Renewing…",
|
||||
"cert.done": "Renewed. The certificate is now valid until {date}.",
|
||||
"cert.fail": "That did not work: {detail}",
|
||||
"rep.title": "Reports",
|
||||
"rep.tipsIntro": "Tips from visitors of this node. They hide nothing: you decide whether to report yourself.",
|
||||
"rep.none": "No tips from visitors.",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// with textContent only, never as links.
|
||||
|
||||
import { HttpError } from "./api.ts";
|
||||
import { certificatePanel } from "./certificate.ts";
|
||||
import { append, clear, h, sendOnCtrlEnter } from "./dom.ts";
|
||||
import { keepFresh } from "./fresh.ts";
|
||||
import { date, price, when } from "./format.ts";
|
||||
@@ -87,6 +88,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
const listingsPane = h(
|
||||
"section",
|
||||
{ class: "pane pane-listings" },
|
||||
certificatePanel(),
|
||||
h("h2", { class: "pane-title" }, t("own.listings")),
|
||||
h("p", null, h("a", { class: "btn primary", href: "#/mine/new" }, t("own.new"))),
|
||||
listingsBox,
|
||||
|
||||
@@ -224,6 +224,15 @@ export async function setRegions(regions: string[]): Promise<string[]> {
|
||||
return ((await call("PUT", "/api/v1/regions", { regions })) as { regions: string[] }).regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renews the node's device certificate from the recovery phrase, which is
|
||||
* used for this one request. The device key stays, so nothing else changes.
|
||||
* Returns when the new certificate runs out, in unix seconds.
|
||||
*/
|
||||
export async function renewCertificate(phrase: string): Promise<number> {
|
||||
return ((await call("PUT", "/api/v1/certificate", { phrase })) as { cert_expires_at: number }).cert_expires_at;
|
||||
}
|
||||
|
||||
export async function createListing(d: Draft): Promise<Listing> {
|
||||
return (await call("POST", "/api/v1/listings", d)) as Listing;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { afterEach, test } from "node:test";
|
||||
|
||||
import { NOW, openPage, startGateway, type Gateway, type Page } from "./helpers.ts";
|
||||
|
||||
const TOKEN = "ef56".repeat(16);
|
||||
const DAY = 86_400;
|
||||
const PHRASE = "legal winner thank year wave sausage worth useful legal winner thank yellow";
|
||||
|
||||
let gw: Gateway | undefined;
|
||||
let page: Page | undefined;
|
||||
let calls: { method: string; path: string; body: string; auth: string }[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
page?.close();
|
||||
page = undefined;
|
||||
await gw?.close();
|
||||
gw = undefined;
|
||||
});
|
||||
|
||||
/** A node whose certificate runs out in `days` days, with an owner who may sign in. */
|
||||
async function node(days: number | null, canRenew = true, answer?: { status: number; body: unknown }): Promise<void> {
|
||||
gw = await startGateway({ listings: [], ...(days === null ? {} : { cert: { expires_at: NOW + days * DAY, can_renew: canRenew } }) });
|
||||
calls = [];
|
||||
gw.owner = (r) => {
|
||||
calls.push({ method: r.method, path: r.path, body: r.body, auth: r.auth });
|
||||
if (r.auth !== `Bearer ${TOKEN}`) return { status: 401, body: { error: "unauthorized" } };
|
||||
if (r.path === "/api/v1/mine") return { status: 200, body: [] };
|
||||
if (r.path === "/api/v1/certificate" && r.method === "PUT") {
|
||||
return answer ?? { status: 200, body: { cert_expires_at: NOW + 365 * DAY } };
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
page = openPage(gw.url, `#/login/${TOKEN}`);
|
||||
await page.waitFor(() => page!.document.querySelector(".pane-listings") !== null, "the owner page");
|
||||
}
|
||||
|
||||
const text = () => page!.document.body.textContent ?? "";
|
||||
const panel = () => page!.document.querySelector("section.certificate");
|
||||
const renew = () => [...page!.document.querySelectorAll("button")].find((b) => b.textContent === "Renew certificate") as HTMLButtonElement | undefined;
|
||||
|
||||
function submit(words: string): void {
|
||||
const form = panel()!.querySelector("form")!;
|
||||
(form.querySelector("input[name=phrase]") as HTMLInputElement).value = words;
|
||||
form.dispatchEvent(new page!.window.Event("submit", { cancelable: true }));
|
||||
}
|
||||
|
||||
test("with plenty of time left the owner page says nothing about the certificate", async () => {
|
||||
await node(200);
|
||||
assert.equal(panel(), null);
|
||||
assert.doesNotMatch(text(), /certificate/i);
|
||||
});
|
||||
|
||||
test("an older node that does not report the certificate shows no panel", async () => {
|
||||
await node(null);
|
||||
assert.equal(panel(), null);
|
||||
});
|
||||
|
||||
test("in the last 30 days it says when the certificate ends and offers to renew it", async () => {
|
||||
await node(12);
|
||||
assert.ok(panel(), "the panel");
|
||||
assert.match(panel()!.textContent!, /expires on .* \(in 12 days\)/);
|
||||
assert.ok(renew(), "the renew button");
|
||||
const input = panel()!.querySelector("input[name=phrase]") as HTMLInputElement;
|
||||
assert.equal(input.type, "password", "the words are not shown while typing");
|
||||
assert.equal(input.getAttribute("autocomplete"), "off");
|
||||
});
|
||||
|
||||
test("exactly 30 days left is the first day it asks, 31 is not", async () => {
|
||||
await node(30);
|
||||
assert.ok(panel(), "30 days left");
|
||||
page!.close();
|
||||
await gw!.close();
|
||||
await node(31);
|
||||
assert.equal(panel(), null, "31 days left");
|
||||
});
|
||||
|
||||
test("renewing sends the words once, with the token, and the panel then confirms", async () => {
|
||||
await node(12);
|
||||
submit(` ${PHRASE} `);
|
||||
await page!.waitFor(() => /Renewed\. The certificate is now valid until/.test(text()), "the confirmation");
|
||||
const puts = calls.filter((c) => c.path === "/api/v1/certificate");
|
||||
assert.equal(puts.length, 1);
|
||||
assert.equal(puts[0]!.method, "PUT");
|
||||
assert.equal(puts[0]!.auth, `Bearer ${TOKEN}`);
|
||||
assert.deepEqual(JSON.parse(puts[0]!.body), { phrase: PHRASE }, "the words arrive trimmed, in a JSON body");
|
||||
assert.equal(panel()!.querySelector("form"), null, "the form is gone");
|
||||
const left = [...page!.document.querySelectorAll("input, textarea")].filter((i) => (i as HTMLInputElement).value.includes("winner"));
|
||||
assert.equal(left.length, 0, "the words are not left in any field on the page");
|
||||
});
|
||||
|
||||
test("empty words are not sent", async () => {
|
||||
await node(12);
|
||||
submit(" ");
|
||||
assert.match(panel()!.textContent!, /That did not work/);
|
||||
assert.equal(calls.filter((c) => c.path === "/api/v1/certificate").length, 0);
|
||||
});
|
||||
|
||||
test("a refusal is shown, the words stay for another try, and the button works again", async () => {
|
||||
await node(12, true, { status: 409, body: { error: "these words belong to a different identity than this node" } });
|
||||
submit(PHRASE);
|
||||
await page!.waitFor(() => /different identity/.test(text()), "the refusal");
|
||||
assert.match(panel()!.textContent!, /That did not work: these words belong to a different identity than this node/);
|
||||
assert.equal(renew()!.disabled, false);
|
||||
assert.equal((panel()!.querySelector("input[name=phrase]") as HTMLInputElement).value, PHRASE);
|
||||
assert.ok(panel()!.querySelector("form"), "the form is still there");
|
||||
});
|
||||
|
||||
test("an identity without a recovery phrase is told so and gets no form", async () => {
|
||||
await node(5, false);
|
||||
assert.match(panel()!.textContent!, /no recovery phrase/);
|
||||
assert.equal(panel()!.querySelector("form"), null);
|
||||
assert.equal(renew(), undefined);
|
||||
});
|
||||
|
||||
test("a certificate that already ran out says so", async () => {
|
||||
await node(-2);
|
||||
assert.match(panel()!.textContent!, /expired on/);
|
||||
assert.ok(renew(), "it can still be renewed while the node runs");
|
||||
});
|
||||
+4
-1
@@ -204,6 +204,8 @@ export interface GatewayOptions {
|
||||
statusFails?: boolean;
|
||||
/** The regions the node reports; default ["u1x"]. */
|
||||
regions?: string[];
|
||||
/** The device certificate the node reports in /status; unset, it says nothing (an older node). */
|
||||
cert?: { expires_at: number; can_renew: boolean };
|
||||
}
|
||||
|
||||
export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
@@ -245,7 +247,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
}
|
||||
// The owner's token-protected routes are played by the test, if it sets `owner`.
|
||||
const writesListing = req.method !== "GET" && /^\/api\/v1\/listings(\/[0-9a-f]{32})?$/.test(url.pathname);
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions|blocked|signals|reports)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions|blocked|signals|reports|certificate)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
@@ -292,6 +294,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
listings: opts.listings.length,
|
||||
difficulty: DIFFICULTY,
|
||||
message_difficulty: 6,
|
||||
...(opts.cert ? { cert_expires_at: opts.cert.expires_at, can_renew: opts.cert.can_renew } : {}),
|
||||
});
|
||||
}
|
||||
if (url.pathname === "/api/v1/listings") {
|
||||
|
||||
Reference in New Issue
Block a user