theseus/dev/signin-sites.test.cjs
Local Dev a6f7b335a5 Vault: PIN setup steps, 6-8 digit PINs, save and offer logins, keep sign-ins
The PIN could only be six digits and was set from three bare inputs; the
unlock prompt sat at the top of the page; and the password manager only
filled when you found the key chip, never offered to save, and "Clear
cookies on quit" signed you out of every site, including the ones whose
login the vault already holds.

- PINs are 6 to 8 digits. The PIN record stores its length so pads draw the
  right number of dots and submit on the last digit; a PIN of the wrong
  length is refused without a strike, so an older Aegis pad cannot burn the
  count against an 8-digit PIN.
- Settings sets a PIN in steps: master password, choose the PIN on a pad
  (6/7/8), repeat it, done. The locked vault opens Theseus's own prompt,
  which is now centred, with the PIN pad or the master password field.
- After a sign-in or sign-up form is sent and the page moves on, Theseus
  offers to save (or update) the login, with an optional "ask for my PIN or
  password before filling it". Focusing a login form offers the saved
  logins under it; on a locked vault it offers to unlock first. A failed
  login (the password field still showing) gets no offer.
- "Keep sign-ins for sites in your vault" (on): the quit clear spares the
  cookies and site storage of sites with a saved login. Their hostnames are
  kept sealed with the OS keystore so the list is readable at quit while
  the vault is locked. Verified end to end on a scratch profile: signed in,
  restarted, still signed in; another site's cookie was cleared.
2026-10-04 20:23:43 +02:00

49 lines
2.3 KiB
JavaScript

// node --test TheseusNavigator/dev/signin-sites.test.cjs
"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { createSigninSites, keepOrigins, normHost } = require("../lib/signin-sites.cjs");
const fakeSafe = {
isEncryptionAvailable: () => true,
getSelectedStorageBackend: () => "gnome_libsecret",
encryptString: (s) => Buffer.from("SEALED:" + s),
decryptString: (b) => { const s = b.toString(); if (!s.startsWith("SEALED:")) throw new Error("bad seal"); return s.slice(7); },
};
const tmpFile = () => path.join(fs.mkdtempSync(path.join(os.tmpdir(), "sis-")), "signin-sites.json");
test("keepOrigins: www twin for names, none for IPs or one-label hosts", () => {
assert.deepEqual(keepOrigins(["github.com"]).sort(),
["http://github.com", "http://www.github.com", "https://github.com", "https://www.github.com"]);
assert.deepEqual(keepOrigins(["www.example.org"]).sort(),
["http://example.org", "http://www.example.org", "https://example.org", "https://www.example.org"]);
assert.deepEqual(keepOrigins(["127.0.0.1"]).sort(), ["http://127.0.0.1", "https://127.0.0.1"]);
assert.deepEqual(keepOrigins(["localhost"]).sort(), ["http://localhost", "https://localhost"]);
assert.deepEqual(keepOrigins(["bad host", "", "a/b", "evil.com:80"]), []);
});
test("normHost lower-cases and trims a trailing dot", () => {
assert.equal(normHost("GitHub.COM."), "github.com");
assert.equal(normHost("x y"), "");
});
test("the list is sealed on disk and survives a reload", () => {
const file = tmpFile();
const a = createSigninSites({ file, safeStorage: fakeSafe });
assert.equal(a.save(["b.com", "a.com", "a.com", "nope nope"]), true);
assert.ok(!fs.readFileSync(file, "utf8").includes("a.com"), "hostnames must not be readable in the file");
const b = createSigninSites({ file, safeStorage: fakeSafe });
assert.deepEqual(b.load(), ["a.com", "b.com"]);
});
test("without an OS keystore nothing is stored", () => {
const file = tmpFile();
const noSafe = { isEncryptionAvailable: () => false };
const s = createSigninSites({ file, safeStorage: noSafe });
assert.equal(s.save(["a.com"]), false);
assert.equal(fs.existsSync(file), false);
assert.deepEqual(createSigninSites({ file, safeStorage: noSafe }).load(), []);
});