abso login says it is waiting, and never waits for ever
of the draft ·pinch·
Version 0 · Files at version 1
2 files, 38 lines added, 1 removed.
--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -174,6 +174,11 @@
177+/** The longest login waits for approval, whatever the server says. */ 178+const MAX_LOGIN_WAIT_S = 30 * 60; 179+/** How often login says it's still waiting. */ 180+const STILL_WAITING_MS = 60_000; 177182export interface LoginIo { 178183 readonly fetch?: typeof fetch; 179184 readonly sleep?: (ms: number) => Promise<void>; @@ -193,13 +198,21 @@
193198 const start = await call(server, "/login/device", { name: boxName(), client: "abso" }, undefined, fetcher); 194199 const { device_code: device, user_code: code, verification_uri_complete: link } = start.body; 195200 let interval = Number(start.body.interval) || 5; 196− const expiresIn = Number(start.body.expires_in) || 900;
201+ // The server says when its code runs out; a server that says never still gets an end. 202+ const expiresIn = Math.min(Number(start.body.expires_in) || 900, MAX_LOGIN_WAIT_S); 197203 if (typeof code !== "string" || typeof link !== "string" || typeof device !== "string") 198204 throw new UsageError(`${originOf(server)} didn't give a code to approve`); 199205 io.say(`To sign this box in, open ${link} and approve the code ${code}.`); 206+ io.say("Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out."); 200207 const until = now() + expiresIn * 1000; 201209 while (now() < until) { 202210 await sleep(interval * 1000); 211+ // A wait with no word looks like a hang, so say it's still waiting now and then. 212+ if (now() - toldAt >= STILL_WAITING_MS) { 213+ io.say(`Still waiting for the code ${code} to be approved.`); 203216 const a = await call(server, "/login/token", { device_code: device }, undefined, fetcher); 204217 if (a.status === 400) { 205218 if (a.body.error === "authorization_pending") continue; --- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -91,6 +91,7 @@
9292 assert.deepEqual(said, [ 9393 "To sign this box in, open https://abso.dev/login/box?code=WXYZ-BCDF and approve the code WXYZ-BCDF.", 94+ "Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.", 9596 assert.equal(readBox(SERVER, h)?.credential, CREDENTIAL); 9697 const files = readdirSync(join(h, ".abso", "boxes")); @@ -160,6 +161,29 @@
160161 assert.equal(readBox(SERVER, h), undefined); 164+test("login says it's still waiting about once a minute, and stops in the end whatever the server says", async () => { 166+ const said: string[] = []; 167+ const pending = Array.from({ length: 2000 }, (): [number, unknown] => [400, { error: "authorization_pending" }]); 168+ await assert.rejects( 172+ fetch: server([[200, { ...started, expires_in: 10 ** 9, interval: 5 }], ...pending], []), 175+ say: (line) => said.push(line), 179+ /nobody approved the code WXYZ-BCDF in time\. Run abso login again\./, 181+ assert.equal(c.slept(), 30 * 60 * 1000, "a server that says never still gets an end"); 182+ const still = said.filter((line) => line === "Still waiting for the code WXYZ-BCDF to be approved."); 183+ assert.equal(still.length, 30); 184+ assert.equal(said.length, 2 + 30); 163187test("a key is minted with the box credential, sent only to the box's own server", async () => { 164188 const seen: Seen = []; 165189 const minted = await mintKey(