cursedbelt-server 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,12 @@
38
38
  * an env var that pre-set someone's password would be exactly the "one credential opens
39
39
  * everybody" shape this replaces. A principal with no record is `awaitingEnrollment` —
40
40
  * locked, and offered the choose-a-password form.
41
+ *
42
+ * 🔴 That last sentence used to need an `enrollable: true` flag, and does not any more.
43
+ * Failing closed with an enrollment form is now what EVERY lock does when it holds no
44
+ * account (see `masterLock.ts`'s `unlocked`), so the flag that used to separate the two
45
+ * modes has nothing left to decide. What still makes this file per-PERSON is the key each
46
+ * record is stored under, which is the only thing it ever really was.
41
47
  */
42
48
  import { createHash } from "node:crypto";
43
49
  import { MasterLock, readRecord } from "./masterLock";
@@ -86,7 +92,6 @@ export class MasterLockDirectory {
86
92
  };
87
93
  const lock = new MasterLock({
88
94
  store,
89
- enrollable: true,
90
95
  ...(this.options.now ? { now: this.options.now } : {}),
91
96
  ...(this.options.log
92
97
  ? { log: (line) => this.options.log?.(`[${principalId}] ${line}`) }
@@ -1,5 +1,5 @@
1
1
  import { type MasterLockKdfParams } from "cursedbelt-core/master-lock/kdf";
2
- import type { MasterLockRecord } from "./masterLock";
2
+ import { type MasterLockRecord } from "./masterLock";
3
3
  /**
4
4
  * The idle window a freshly minted lock starts with.
5
5
  *
@@ -17,6 +17,10 @@ export interface MintMasterLockSeedOptions {
17
17
  idleMs?: number;
18
18
  /** Reuse existing params instead of generating a salt — for a rotation. */
19
19
  kdf?: MasterLockKdfParams;
20
+ /** What to call the tenant this seed creates. Defaults to `Account 1`. */
21
+ label?: string;
22
+ /** The owner's reminder for this password, shown on the lock page's "I forgot". */
23
+ hint?: string;
20
24
  }
21
25
  /**
22
26
  * `password` → the record an app can be seeded with.
@@ -24,6 +24,7 @@
24
24
  */
25
25
  import { DEFAULT_IDLE_MS } from "cursedbelt-core/master-lock/policy";
26
26
  import { deriveMasterLockVerifier, newMasterLockKdfParams, } from "cursedbelt-core/master-lock/kdf";
27
+ import { FIRST_ACCOUNT_ID } from "./masterLock";
27
28
  /**
28
29
  * The idle window a freshly minted lock starts with.
29
30
  *
@@ -52,8 +53,24 @@ export async function mintMasterLockSeed(password, options = {}) {
52
53
  const verifier = await deriveMasterLockVerifier(password, kdf);
53
54
  return {
54
55
  kdf,
55
- verifierHash: await Bun.password.hash(verifier, { algorithm: "argon2id" }),
56
56
  idleMs: options.idleMs ?? DEFAULT_SEED_IDLE_MS,
57
+ /*
58
+ * 🔴 ONE account, and its id is `FIRST_ACCOUNT_ID` rather than anything derived
59
+ * from `options`. A seed is what an app boots with before anybody has typed
60
+ * anything, so the tenant it names is the tenant whose rows the app already holds —
61
+ * and `readRecord` maps the legacy single-password shape onto the same id for
62
+ * exactly that reason. Two different "first" ids would give a seeded app and a
63
+ * migrated app different answers to "whose library is this".
64
+ */
65
+ accounts: [
66
+ {
67
+ id: FIRST_ACCOUNT_ID,
68
+ label: options.label ?? "Account 1",
69
+ hint: options.hint ?? "",
70
+ verifierHash: await Bun.password.hash(verifier, { algorithm: "argon2id" }),
71
+ createdAt: 0,
72
+ },
73
+ ],
57
74
  };
58
75
  }
59
76
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "2.1.0",
3
+ "version": "3.0.1",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "description": "The app-facing Bun/Hono server tier of the cursedbelt split \u2014 storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
@@ -200,7 +200,7 @@
200
200
  }
201
201
  },
202
202
  "dependencies": {
203
- "cursedbelt-core": "^1.2.0",
203
+ "cursedbelt-core": "^2.0.0",
204
204
  "cwip": "^4.1.0",
205
205
  "jose": "^6.2.3"
206
206
  },
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * ── Retention ───────────────────────────────────────────────────────────────
12
12
  * This package never deletes an event. An app whose stream is high-volume opts
13
- * into the fleet standard (`docs/retention.md` in `cursed-satellites`) by
13
+ * into the fleet standard (`cursedbelt-server/retention`, in this package) by
14
14
  * declaring the table, which puts the number under the owner's control in the
15
15
  * station rather than in a constant here:
16
16
  *
@@ -0,0 +1,308 @@
1
+ /**
2
+ * 🔴 **The accounts model — a master password IS a tenant.**
3
+ *
4
+ * The owner's words, and the whole specification:
5
+ *
6
+ * > *"If I login with a master password I only see the files I added or removed with that
7
+ * > login. If I login with my other password I have not made yet I only see the other ones
8
+ * > I add in that login. The master passwords represent their own tenants or you can think
9
+ * > of it as a fully separate account even though I am the user in both cases."*
10
+ *
11
+ * This file proves the half that lives in the lock. The half that lives in an app — every
12
+ * query scoped by the id this hands out — is that app's own gate to prove.
13
+ *
14
+ * The claim each `describe` carries is the thing that would be catastrophic to get wrong,
15
+ * and three of them are catastrophic in a way that is SILENT: a tenant that cannot be
16
+ * reached looks exactly like a tenant with nothing in it.
17
+ */
18
+ import { beforeEach, describe, expect, test } from "bun:test";
19
+ import {
20
+ type MasterLockKdfParams,
21
+ deriveMasterLockVerifier,
22
+ } from "cursedbelt-core/master-lock";
23
+ import { FIRST_ACCOUNT_ID, MasterLock, readRecord } from "./masterLock";
24
+ import { createMemoryMasterLockStore } from "./store";
25
+
26
+ /** `iter: 1` — the ROUND COUNT is pinned in `cursedbelt-core`'s `kdf.spec.ts`; 600k × N
27
+ * argon2 verifies here would be minutes of gate for nothing this file is testing. */
28
+ const KDF: MasterLockKdfParams = {
29
+ v: 1,
30
+ alg: "PBKDF2-SHA256",
31
+ iter: 1,
32
+ salt: "AAECAwQFBgcICQoLDA0ODw",
33
+ };
34
+
35
+ const FIRST = "the owner's vault master password";
36
+ const SECOND = "password";
37
+
38
+ let firstVerifier = "";
39
+ let secondVerifier = "";
40
+ /** The LEGACY record: one password, no accounts — the shape every `MASTER_LOCK_SEED` in
41
+ * the fleet carries, and the shape every un-upgraded app already has in its database. */
42
+ let legacyJson = "";
43
+
44
+ beforeEach(async () => {
45
+ if (firstVerifier) return;
46
+ firstVerifier = await deriveMasterLockVerifier(FIRST, KDF);
47
+ secondVerifier = await deriveMasterLockVerifier(SECOND, KDF);
48
+ legacyJson = JSON.stringify({
49
+ kdf: KDF,
50
+ verifierHash: await Bun.password.hash(firstVerifier, { algorithm: "argon2id" }),
51
+ idleMs: 300_000,
52
+ });
53
+ });
54
+
55
+ const build = (stored?: string | null) => {
56
+ const store = createMemoryMasterLockStore(stored ?? null);
57
+ return { store, lock: new MasterLock({ store }) };
58
+ };
59
+
60
+ const req = (token: string): Request =>
61
+ new Request("http://app.test/", { headers: { cookie: `master_lock=${token}` } });
62
+
63
+ /** Unlock and hand back a request that presents the resulting token. */
64
+ async function open(lock: MasterLock, verifier: string) {
65
+ const result = await lock.unlock(verifier);
66
+ if (!result.ok) throw new Error("expected the unlock to succeed");
67
+ return { ...result, req: req(result.token) };
68
+ }
69
+
70
+ describe("🔴 claim 1 — the owner's existing password keeps opening everything he has", () => {
71
+ test("a legacy single-password record becomes acct-1, and that password still works", async () => {
72
+ // THE migration guarantee. `apps/collections` stamps its 279 existing rows with this
73
+ // id, so an id that moved — or a record that failed to parse and armed nothing —
74
+ // would orphan the entire library this migration exists to carry across.
75
+ const { lock } = build(legacyJson);
76
+ expect(lock.configured).toBe(true);
77
+ expect(lock.accounts.length).toBe(1);
78
+ expect(lock.accounts[0]?.id).toBe(FIRST_ACCOUNT_ID);
79
+
80
+ const opened = await open(lock, firstVerifier);
81
+ expect(opened.accountId).toBe(FIRST_ACCOUNT_ID);
82
+ // And nothing else was invented along the way.
83
+ expect(lock.idleMs).toBe(300_000);
84
+ });
85
+
86
+ test("the migration is a READ — it does not rewrite the row until something else does", async () => {
87
+ // A record that rewrote itself on boot would mean a rollback to the previous build
88
+ // could no longer read its own store. Nothing is persisted until a write happens for
89
+ // a reason of its own.
90
+ const { lock, store } = build(legacyJson);
91
+ expect(lock.configured).toBe(true);
92
+ expect(store.read()).toBe(legacyJson);
93
+
94
+ lock.setIdleMs(600_000);
95
+ const rewritten = readRecord(store.read());
96
+ expect(rewritten?.accounts[0]?.id).toBe(FIRST_ACCOUNT_ID);
97
+ expect(rewritten?.idleMs).toBe(600_000);
98
+ });
99
+ });
100
+
101
+ describe("🔴 claim 2 — a second password is a second tenant, and never the first one", () => {
102
+ test("adding one needs a live unlock AND the current password, re-typed", async () => {
103
+ const { lock } = build(legacyJson);
104
+
105
+ // No unlock at all.
106
+ expect(
107
+ await lock.addAccount(req("nope"), {
108
+ currentVerifier: firstVerifier,
109
+ verifier: secondVerifier,
110
+ label: "Account 2",
111
+ }),
112
+ ).toEqual({ ok: false, reason: "locked" });
113
+
114
+ const opened = await open(lock, firstVerifier);
115
+
116
+ // Unlocked, but the current password not proved.
117
+ expect(
118
+ await lock.addAccount(opened.req, {
119
+ currentVerifier: "not it",
120
+ verifier: secondVerifier,
121
+ label: "Account 2",
122
+ }),
123
+ ).toEqual({ ok: false, reason: "wrong" });
124
+ expect(lock.accounts.length).toBe(1);
125
+
126
+ const added = await lock.addAccount(opened.req, {
127
+ currentVerifier: firstVerifier,
128
+ verifier: secondVerifier,
129
+ label: "Account 2",
130
+ hint: "the obvious one",
131
+ });
132
+ expect(added.ok && added.account.id).toBe("acct-2");
133
+ });
134
+
135
+ test("each password opens its OWN account, and a token never reads as the other", async () => {
136
+ const { lock } = build(legacyJson);
137
+ const first = await open(lock, firstVerifier);
138
+ await lock.addAccount(first.req, {
139
+ currentVerifier: firstVerifier,
140
+ verifier: secondVerifier,
141
+ label: "Account 2",
142
+ });
143
+ const second = await open(lock, secondVerifier);
144
+
145
+ expect(first.accountId).toBe("acct-1");
146
+ expect(second.accountId).toBe("acct-2");
147
+ // The property everything else rests on: a token is bound to the account that minted
148
+ // it, so two browsers open at once are two tenants, not one ambient state.
149
+ expect(lock.accountFor(first.req)).toBe("acct-1");
150
+ expect(lock.accountFor(second.req)).toBe("acct-2");
151
+ });
152
+
153
+ test("creating a tenant does NOT enter it", async () => {
154
+ // Switching means typing that tenant's password. If creating one dropped you into
155
+ // it, the owner would add an account and watch his library apparently vanish.
156
+ const { lock } = build(legacyJson);
157
+ const first = await open(lock, firstVerifier);
158
+ await lock.addAccount(first.req, {
159
+ currentVerifier: firstVerifier,
160
+ verifier: secondVerifier,
161
+ label: "Account 2",
162
+ });
163
+ expect(lock.accountFor(first.req)).toBe("acct-1");
164
+ });
165
+
166
+ test("🔴 a password that already opens something is refused", async () => {
167
+ // Two accounts under one password would make `unlock` serve whichever the loop
168
+ // reached first — so the owner would type the password he has always typed and be
169
+ // handed an empty library, with his real one apparently gone.
170
+ const { lock } = build(legacyJson);
171
+ const first = await open(lock, firstVerifier);
172
+ expect(
173
+ await lock.addAccount(first.req, {
174
+ currentVerifier: firstVerifier,
175
+ verifier: firstVerifier,
176
+ label: "A clone",
177
+ }),
178
+ ).toEqual({ ok: false, reason: "duplicate" });
179
+ expect(lock.accounts.length).toBe(1);
180
+ });
181
+ });
182
+
183
+ describe("🔴 claim 3 — changing a password never changes which content it opens", () => {
184
+ test("the account id survives a rotation, and the siblings survive it too", async () => {
185
+ // The owner: *"If I change account 2 password it just changes how I get the access.
186
+ // For instance I could change it from 'password' to 'passwordIPicked' later and I
187
+ // would still access the same content afterward."*
188
+ const { lock } = build(legacyJson);
189
+ const first = await open(lock, firstVerifier);
190
+ await lock.addAccount(first.req, {
191
+ currentVerifier: firstVerifier,
192
+ verifier: secondVerifier,
193
+ label: "Account 2",
194
+ });
195
+
196
+ const second = await open(lock, secondVerifier);
197
+ const picked = await deriveMasterLockVerifier("passwordIPicked", KDF);
198
+ expect(
199
+ await lock.change(second.req, { currentVerifier: secondVerifier, verifier: picked }),
200
+ ).toEqual({ ok: true });
201
+
202
+ // The new password opens the SAME tenant…
203
+ const reopened = await open(lock, picked);
204
+ expect(reopened.accountId).toBe("acct-2");
205
+ // …the old one opens nothing…
206
+ expect((await lock.unlock(secondVerifier)).ok).toBe(false);
207
+ // …and account 1 is untouched, which is what a shared KDF salt is protecting.
208
+ const stillFirst = await open(lock, firstVerifier);
209
+ expect(stillFirst.accountId).toBe("acct-1");
210
+ });
211
+
212
+ test("a rotation cannot collide a password onto a sibling", async () => {
213
+ const { lock } = build(legacyJson);
214
+ const first = await open(lock, firstVerifier);
215
+ await lock.addAccount(first.req, {
216
+ currentVerifier: firstVerifier,
217
+ verifier: secondVerifier,
218
+ label: "Account 2",
219
+ });
220
+ const second = await open(lock, secondVerifier);
221
+ expect(
222
+ await lock.change(second.req, {
223
+ currentVerifier: secondVerifier,
224
+ verifier: firstVerifier,
225
+ }),
226
+ ).toEqual({ ok: false, reason: "invalid" });
227
+ });
228
+ });
229
+
230
+ describe("🔴 claim 4 — the hints are readable while locked, and nothing else is", () => {
231
+ test("a hint survives a rotation and can be rewritten without the password", async () => {
232
+ const { lock } = build(legacyJson);
233
+ const first = await open(lock, firstVerifier);
234
+ await lock.addAccount(first.req, {
235
+ currentVerifier: firstVerifier,
236
+ verifier: secondVerifier,
237
+ label: "Account 2",
238
+ hint: "the obvious one",
239
+ });
240
+
241
+ expect(lock.hints()).toEqual([
242
+ { label: "Account 1", hint: "" },
243
+ { label: "Account 2", hint: "the obvious one" },
244
+ ]);
245
+
246
+ const second = await open(lock, secondVerifier);
247
+ expect(lock.editAccount(second.req, { id: "acct-2", hint: "rhymes with lassword" })).toBe(true);
248
+ expect(lock.hints()[1]?.hint).toBe("rhymes with lassword");
249
+ });
250
+
251
+ test("🔴 one session cannot rewrite another tenant's label or hint", async () => {
252
+ // The hint is the one field designed to be read by somebody who is LOCKED OUT, so a
253
+ // session holding one password must not be able to rewrite the note that gets the
254
+ // other one back in.
255
+ const { lock } = build(legacyJson);
256
+ const first = await open(lock, firstVerifier);
257
+ await lock.addAccount(first.req, {
258
+ currentVerifier: firstVerifier,
259
+ verifier: secondVerifier,
260
+ label: "Account 2",
261
+ hint: "the obvious one",
262
+ });
263
+ expect(lock.editAccount(first.req, { id: "acct-2", hint: "overwritten" })).toBe(false);
264
+ expect(lock.hints()[1]?.hint).toBe("the obvious one");
265
+ });
266
+
267
+ test("a hint is trimmed and capped, so it cannot become a wall of text on the lock screen", async () => {
268
+ const { lock } = build(legacyJson);
269
+ const first = await open(lock, firstVerifier);
270
+ await lock.addAccount(first.req, {
271
+ currentVerifier: firstVerifier,
272
+ verifier: secondVerifier,
273
+ label: " Account\n\n2 ",
274
+ hint: `${"x".repeat(400)}`,
275
+ });
276
+ expect(lock.accounts[1]?.label).toBe("Account 2");
277
+ expect(lock.accounts[1]?.hint.length).toBe(200);
278
+ });
279
+ });
280
+
281
+ describe("🔴 claim 5 — a malformed row costs one account, never the keyring", () => {
282
+ test("an unreadable account is dropped and the others still open", async () => {
283
+ // This record is the ONLY thing that says which password opens which library.
284
+ // Refusing the whole file over one bad row would take every tenant down with it.
285
+ const good = await Bun.password.hash(firstVerifier, { algorithm: "argon2id" });
286
+ const stored = JSON.stringify({
287
+ kdf: KDF,
288
+ idleMs: 300_000,
289
+ accounts: [
290
+ { id: "acct-1", label: "Account 1", hint: "", verifierHash: good, createdAt: 1 },
291
+ { id: "acct-2", label: "Broken", hint: "", verifierHash: "not-a-hash", createdAt: 2 },
292
+ // A duplicate id, and an id shaped like something that could reach SQL.
293
+ { id: "acct-1", label: "Dupe", hint: "", verifierHash: good, createdAt: 3 },
294
+ { id: "../escape", label: "Nope", hint: "", verifierHash: good, createdAt: 4 },
295
+ ],
296
+ });
297
+ const { lock } = build(stored);
298
+ expect(lock.accounts.map((account) => account.id)).toEqual(["acct-1"]);
299
+ expect((await open(lock, firstVerifier)).accountId).toBe("acct-1");
300
+ });
301
+
302
+ test("an empty keyring is a legitimate state, not a parse failure", async () => {
303
+ const { lock } = build(JSON.stringify({ kdf: KDF, idleMs: 300_000, accounts: [] }));
304
+ expect(lock.configured).toBe(false);
305
+ expect(lock.awaitingEnrollment).toBe(true);
306
+ expect(lock.unlocked).toBe(false);
307
+ });
308
+ });
@@ -150,10 +150,77 @@ describe("while locked", () => {
150
150
  idleMs: 5 * 60_000,
151
151
  remainingMs: 0,
152
152
  retryAfterMs: 0,
153
+ // Locked, so there is no account to name.
154
+ accountId: null,
155
+ accountLabel: null,
153
156
  });
154
157
  expect(JSON.stringify(body)).not.toContain("argon2");
155
158
  });
156
159
 
160
+ test("🔴 a rotation carrying a STALE kdf is refused, not silently honoured", async () => {
161
+ // The pre-accounts wire minted a fresh salt on every rotation. Every account now
162
+ // derives under one shared descriptor, so honouring that would store a verifier hash
163
+ // nothing can ever match — the owner sets a new password, the rotation logs him out,
164
+ // and neither the old nor the new one opens the app. `409 stale-client` is the one
165
+ // refusal here that is deliberately distinguishable from a wrong password.
166
+ const { guard } = build();
167
+ const cookie = await open(guard);
168
+ const stale = await guard.handle(
169
+ post(
170
+ MASTER_LOCK_PATHS.change,
171
+ {
172
+ currentVerifier: VERIFIER,
173
+ kdf: { v: 1, alg: "PBKDF2-SHA256", iter: 600_000, salt: "ZZZZZZZZZZZZZZZZZZZZZZ" },
174
+ verifier: "whatever-that-salt-produced",
175
+ },
176
+ cookie,
177
+ ),
178
+ );
179
+ expect(stale?.status).toBe(409);
180
+ expect(await stale?.json()).toEqual({ error: "stale-client" });
181
+ // And the password that already worked still does.
182
+ expect((await guard.handle(post(MASTER_LOCK_PATHS.unlock, { verifier: VERIFIER })))?.status).toBe(200);
183
+ });
184
+
185
+ test("🔴 status never says how many accounts this app has", async () => {
186
+ // The lock screen must read identically whether the owner keeps one tenant or ten:
187
+ // the number of master passwords is itself a fact worth hiding, and `status` is
188
+ // served to anyone who got past the app's own sign-in, before they prove anything
189
+ // else. `hints` is the one surface that discloses it, behind a deliberate click.
190
+ const { lock, guard } = build();
191
+ const cookie = await open(guard);
192
+ const added = await guard.handle(
193
+ post(
194
+ MASTER_LOCK_PATHS.accounts,
195
+ {
196
+ currentVerifier: VERIFIER,
197
+ verifier: await deriveMasterLockVerifier("second tenant", KDF),
198
+ label: "Second",
199
+ },
200
+ cookie,
201
+ ),
202
+ );
203
+ expect(added?.status).toBe(200);
204
+ expect(lock.accounts.length).toBe(2);
205
+
206
+ const res = await guard.handle(xhr(MASTER_LOCK_PATHS.status));
207
+ const body = (await res?.json()) as Record<string, unknown>;
208
+ expect(Object.keys(body).sort()).toEqual([
209
+ "accountId",
210
+ "accountLabel",
211
+ "configured",
212
+ "enrollable",
213
+ "idleMs",
214
+ "kdf",
215
+ "locked",
216
+ "remainingMs",
217
+ "retryAfterMs",
218
+ ]);
219
+ const serialized = JSON.stringify(body);
220
+ expect(serialized).not.toContain("Second");
221
+ expect(serialized).not.toContain("acct-2");
222
+ });
223
+
157
224
  test("an `allow` path is passed through — that is where a machine surface lives", async () => {
158
225
  const { guard } = build((url) => url.pathname === "/healthz");
159
226
  expect(await guard.handle(xhr("/healthz"))).toBeNull();
@@ -249,11 +316,12 @@ describe("while unlocked", () => {
249
316
  test("rotation needs the current password and locks the site behind it", async () => {
250
317
  const { guard } = build();
251
318
  const cookie = await open(guard);
252
- const nextKdf = newMasterLockKdfParams();
253
- const nextVerifier = await deriveMasterLockVerifier("something else", nextKdf);
319
+ // 🔴 Derived under the app's OWN params, not a fresh set. Every account shares one
320
+ // descriptor, so a rotation that minted a new salt would invalidate the others.
321
+ const nextVerifier = await deriveMasterLockVerifier("something else", KDF);
254
322
 
255
323
  const refused = await guard.handle(
256
- post(MASTER_LOCK_PATHS.change, { currentVerifier: "no", kdf: nextKdf, verifier: nextVerifier }, cookie),
324
+ post(MASTER_LOCK_PATHS.change, { currentVerifier: "no", verifier: nextVerifier }, cookie),
257
325
  );
258
326
  expect(refused?.status).toBe(400);
259
327
  expect(await refused?.json()).toEqual({ error: "wrong" });
@@ -261,7 +329,7 @@ describe("while unlocked", () => {
261
329
  const done = await guard.handle(
262
330
  post(
263
331
  MASTER_LOCK_PATHS.change,
264
- { currentVerifier: VERIFIER, kdf: nextKdf, verifier: nextVerifier },
332
+ { currentVerifier: VERIFIER, verifier: nextVerifier },
265
333
  cookie,
266
334
  ),
267
335
  );
@@ -272,12 +340,31 @@ describe("while unlocked", () => {
272
340
  });
273
341
 
274
342
  describe("an app with no master password configured", () => {
275
- test("is served normally — an unopenable lock would brick it", async () => {
343
+ test("🔴 boots to NOTHING, and offers to take a first password", async () => {
344
+ // This INVERTS what it asserted until the accounts model. "Unconfigured means open"
345
+ // was right while the lock only decided whether a UI was visible — failing closed
346
+ // would have bricked an app nobody could type a password into. Both halves of that
347
+ // reasoning are gone: `enroll` means an unconfigured app offers to take one, and the
348
+ // password now decides WHOSE DATA the app serves, so "open with no password" has no
349
+ // tenant it could answer with. The owner ruled the same way: *"It would be booting
350
+ // to nothing until the password is created."*
276
351
  const lock = new MasterLock({ store: createMemoryMasterLockStore(), seedJson: null });
277
352
  const guard = createMasterLockGuard({ lock, appLabel: "Test App" });
278
- expect(await guard.handle(doc("/"))).toBeNull();
353
+
354
+ const page = await guard.handle(doc("/"));
355
+ expect(page?.status).toBe(200);
356
+ expect(await page?.text()).toContain("master password");
357
+ // And no tenant is invented for a caller who has typed nothing.
358
+ expect(guard.accountFor(doc("/"))).toBeNull();
359
+
279
360
  const status = await guard.handle(xhr(MASTER_LOCK_PATHS.status));
280
- expect(await status?.json()).toMatchObject({ configured: false, locked: false, kdf: null });
361
+ expect(await status?.json()).toMatchObject({
362
+ configured: false,
363
+ locked: true,
364
+ enrollable: true,
365
+ kdf: null,
366
+ accountId: null,
367
+ });
281
368
  });
282
369
  });
283
370