@coffre/conformance 0.3.0 → 0.4.0

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.
package/dist/main.js CHANGED
@@ -52,9 +52,10 @@ const KEYS = {
52
52
  * The built app as `wrangler dev` can run it: its own build, behind an entry
53
53
  * that, once the app has answered, reads whatever the request still sends
54
54
  * before passing the answer on. Locally, and only there, a Worker built
55
- * unbundled with static assets fails every request after one whose body it
56
- * left unread, which every refusal does, and reading it later, after the
57
- * answer, is too late; deployed, Cloudflare discards such a body, as
55
+ * unbundled with static assets may fail the request after one whose body it
56
+ * left unread, which every refusal does: wrangler retries a GET, not a POST
57
+ * (cloudflare/workers-sdk#15203). Reading it later, after the answer, is too
58
+ * late; deployed, Cloudflare discards such a body, as
58
59
  * `vite dev` and `vite preview` do. The app itself must never wait so on what
59
60
  * a caller sends; this harness sends only bodies that end. The entry and its
60
61
  * config are written beside the build, which the next `vite build`
@@ -152,11 +153,29 @@ function createClient(options) {
152
153
  /** With their environments. */
153
154
  list: () => call("GET /projects", {}),
154
155
  create: (project, input) => call("PUT /projects/:project", { project }, input),
155
- update: (project, patch) => call("PATCH /projects/:project", { project }, patch)
156
+ update: (project, patch) => call("PATCH /projects/:project", { project }, patch),
157
+ /** What deleting an archived project would erase and revoke; changes nothing. */
158
+ previewDelete: (project) => {
159
+ const [method, route] = address("DELETE /projects/:project", { project });
160
+ return send(method, `${route}?dryRun=1`, void 0);
161
+ },
162
+ /** Delete an archived project for good: its values erased, its grants revoked, its slug free. Owners only. */
163
+ delete: (project) => call("DELETE /projects/:project", { project })
156
164
  },
157
165
  environments: {
158
166
  create: (path, input) => call("PUT /projects/:project/:environment", place(path), input),
159
- update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch)
167
+ update: (path, patch) => call("PATCH /projects/:project/:environment", place(path), patch),
168
+ /** What deleting an archived environment would erase and revoke; changes nothing. */
169
+ previewDelete: (path) => {
170
+ const [method, route] = address("DELETE /projects/:project/:environment", place(path));
171
+ return send(method, `${route}?dryRun=1`, void 0);
172
+ },
173
+ /** Delete an archived environment for good, as a project is. Owners only. */
174
+ delete: (path) => call("DELETE /projects/:project/:environment", place(path)),
175
+ /** The keys its sibling environments have and it lacks, those you can see, and those its team dismissed. */
176
+ missing: (path) => call("GET /projects/:project/:environment/missing", place(path)),
177
+ /** Dismiss missing keys (`true`) or restore them (`null`). */
178
+ dismiss: (path, patch) => call("PATCH /projects/:project/:environment/dismissals", place(path), patch)
160
179
  },
161
180
  secrets: {
162
181
  /** Keys, versions and who changed what; never values. */
@@ -180,6 +199,16 @@ function createClient(options) {
180
199
  rename: (path, key) => call("PATCH /secrets/:project/:environment/:key", place(path), { key }),
181
200
  update: (path, patch) => call("PATCH /secrets/:project/:environment/:key", place(path), patch)
182
201
  },
202
+ /**
203
+ * References: secrets read through others (docs/design/environments.md).
204
+ * A key becomes one with `secrets.set(path, { KEY: { ref: 'market/prod/KEY' } })`.
205
+ */
206
+ references: {
207
+ /** The live references into and out of a place, `market`, `market/prod` or `market/prod/KEY`, and who reads through them. */
208
+ list: (path) => call("GET /references", {}, { path }),
209
+ /** Break the reference a secret is: its readers stop reading the source through it. */
210
+ break: (path) => call("DELETE /secrets/:project/:environment/:key/reference", place(path))
211
+ },
183
212
  members: {
184
213
  /** People and tokens, their role and their access; at a place, those who reach it. */
185
214
  list: (path) => call("GET /members", {}, { path }),
@@ -232,6 +261,55 @@ set: (member, access) => call("PATCH /access/:member", { member }, access) },
232
261
  get: (code) => call("GET /device-logins/:code", { code }),
233
262
  decide: (code, approve) => call("POST /device-logins/:code", { code }, { approve })
234
263
  },
264
+ /**
265
+ * Folders, which arrange lists and do nothing else: a folder exists while
266
+ * something is filed in it. Renaming one re-files all of it, onto a folder
267
+ * that exists merges the two; removing one takes all of it out, each item
268
+ * staying where it is, in no folder. Moving one item is `projects.update`
269
+ * or `secrets.update` with a `folder`.
270
+ */
271
+ folders: {
272
+ /** A folder of projects, renamed. Takes managing every project in it. */
273
+ rename: (folder, name) => call("PATCH /folders/:folder", { folder }, { name }),
274
+ /** Every project out of a folder. */
275
+ remove: (folder) => call("DELETE /folders/:folder", { folder }),
276
+ /** One of an environment's key folders, `market/prod`, renamed. Takes writing there. */
277
+ renameKeys: (environment, folder, name) => {
278
+ const { project, environment: slug } = place(environment);
279
+ return call("PATCH /folders/:project/:environment/:folder", {
280
+ project,
281
+ environment: slug,
282
+ folder
283
+ }, { name });
284
+ },
285
+ /** Every key out of one of an environment's folders. */
286
+ removeKeys: (environment, folder) => {
287
+ const { project, environment: slug } = place(environment);
288
+ return call("DELETE /folders/:project/:environment/:folder", {
289
+ project,
290
+ environment: slug,
291
+ folder
292
+ });
293
+ }
294
+ },
295
+ /**
296
+ * An MCP client asking to connect, by its authorization request, and the
297
+ * person's answer: where to send the browser next.
298
+ */
299
+ oauth: {
300
+ describe: (request) => call("GET /oauth/authorizations", {}, request),
301
+ decide: (input) => call("POST /oauth/authorizations", {}, input)
302
+ },
303
+ /** The MCP clients I connected. */
304
+ /** A change an MCP client asked for: what it would do, and the person's decision, which makes it. */
305
+ approvals: {
306
+ get: (id) => call("GET /approvals/:id", { id }),
307
+ decide: (id, input) => call("POST /approvals/:id", { id }, input)
308
+ },
309
+ apps: {
310
+ list: () => call("GET /apps", {}),
311
+ disconnect: (id) => call("DELETE /apps/:id", { id })
312
+ },
235
313
  audit: {
236
314
  list: (query = {}) => call("GET /audit", {}, query),
237
315
  verify: () => call("GET /audit/verification", {}),
@@ -259,7 +337,7 @@ function expect(condition, message, detail) {
259
337
  * The status coffre turned a call away with. A call that went through
260
338
  * fails the check: `what` says what it should not have done.
261
339
  */
262
- async function refused(what, call) {
340
+ async function refused$1(what, call) {
263
341
  const outcome = await call.then((value) => ({ value }), (error) => ({ error }));
264
342
  if ("value" in outcome) throw new Failure(`${what}, and was let`, outcome.value);
265
343
  if (!(outcome.error instanceof CoffreError)) throw outcome.error;
@@ -642,13 +720,13 @@ function bearer(origin, token) {
642
720
  }
643
721
  //#endregion
644
722
  //#region src/checks/people.ts
645
- const PROJECT = "conformance";
646
- const DEV = `${PROJECT}/dev`;
647
- const PROD = `${PROJECT}/prod`;
648
- const BULK = `${PROJECT}/bulk`;
649
- const SERVICE = "token:conformance-ci";
723
+ const PROJECT$1 = "conformance";
724
+ const DEV = `${PROJECT$1}/dev`;
725
+ const PROD = `${PROJECT$1}/prod`;
726
+ const BULK = `${PROJECT$1}/bulk`;
727
+ const SERVICE$2 = "token:conformance-ci";
650
728
  /** Where the live checks' token reads, as an operator would set it up. */
651
- const LIVE = `${PROJECT}/live`;
729
+ const LIVE = `${PROJECT$1}/live`;
652
730
  const LIVE_SERVICE = "token:conformance-live";
653
731
  function canary() {
654
732
  return `coffre-canary-${randomBytes(12).toString("hex")}`;
@@ -673,10 +751,12 @@ async function signIn(deployment, browser, email) {
673
751
  expect(approve.status === 302 && callback.startsWith(`${deployment.origin}/auth/callback/github?`), "GitHub did not send the browser back", callback);
674
752
  const back = await browser.fetch(callback);
675
753
  expect(back.status === 302 || back.status === 303, `the callback answered ${back.status}`, await back.text());
676
- const error = new URL(back.headers.get("location") ?? "/", deployment.origin).searchParams.get("error");
754
+ const location = new URL(back.headers.get("location") ?? "/", deployment.origin);
755
+ const error = location.searchParams.get("error");
677
756
  return error === null ? { ok: true } : {
678
757
  ok: false,
679
- error
758
+ error,
759
+ location: `${location.pathname}${location.search}`
680
760
  };
681
761
  }
682
762
  async function signInAdmin(deployment) {
@@ -698,7 +778,7 @@ async function signInAdmin(deployment) {
698
778
  };
699
779
  }
700
780
  async function setUp(admin) {
701
- await admin.api.projects.create(PROJECT, { name: "Conformance" });
781
+ await admin.api.projects.create(PROJECT$1, { name: "Conformance" });
702
782
  for (const [path, name] of [
703
783
  [DEV, "Development"],
704
784
  [PROD, "Production"],
@@ -711,7 +791,7 @@ async function setUp(admin) {
711
791
  };
712
792
  for (const path of [DEV, PROD]) await admin.api.secrets.set(path, valuesIn(canaries, path));
713
793
  return {
714
- detail: `${PROJECT}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
794
+ detail: `${PROJECT$1}: dev and prod, ${Object.keys(canaries).length} values, and bulk`,
715
795
  value: canaries
716
796
  };
717
797
  }
@@ -728,18 +808,18 @@ async function setUpLive(admin, canaries) {
728
808
  await admin.api.members.add(LIVE_SERVICE);
729
809
  await admin.api.access.set(LIVE_SERVICE, {
730
810
  [LIVE]: "viewer",
731
- [PROJECT]: "auditor"
811
+ [PROJECT$1]: "auditor"
732
812
  });
733
813
  const { token } = await admin.api.tokens.issue(LIVE_SERVICE, {
734
814
  label: "conformance live",
735
815
  expiresInDays: 1
736
816
  });
737
817
  return {
738
- detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT}`,
818
+ detail: `${LIVE}/CANARY, and ${LIVE_SERVICE}: viewer there, auditor on ${PROJECT$1}`,
739
819
  value: {
740
820
  token,
741
821
  canary: {
742
- project: PROJECT,
822
+ project: PROJECT$1,
743
823
  environment: "live",
744
824
  key: "CANARY",
745
825
  value
@@ -751,28 +831,30 @@ async function setUpLive(admin, canaries) {
751
831
  function valuesIn(canaries, environment) {
752
832
  return Object.fromEntries(Object.entries(canaries).filter(([path]) => path.startsWith(`${environment}/`)).map(([path, value]) => [path.slice(environment.length + 1), value]));
753
833
  }
834
+ /** A person the admin admits with this access, signed in in a browser of their own. */
835
+ async function personaOn(deployment, admin, name, access) {
836
+ const email = `${name}@conformance.example`;
837
+ const member = `user:${email}`;
838
+ await admin.api.members.add(member);
839
+ await admin.api.access.set(member, access);
840
+ const browser = new Browser(deployment.origin);
841
+ const signed = await signIn(deployment, browser, email);
842
+ expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
843
+ return {
844
+ email,
845
+ member,
846
+ browser,
847
+ api: browser.client()
848
+ };
849
+ }
754
850
  async function personas(deployment, admin) {
755
- async function person(name, access) {
756
- const email = `${name}@conformance.example`;
757
- const member = `user:${email}`;
758
- await admin.api.members.add(member);
759
- await admin.api.access.set(member, access);
760
- const browser = new Browser(deployment.origin);
761
- const signed = await signIn(deployment, browser, email);
762
- expect(signed.ok, `${email} was refused: ${"error" in signed ? signed.error : ""}`);
763
- return {
764
- email,
765
- member,
766
- browser,
767
- api: browser.client()
768
- };
769
- }
851
+ const person = (name, access) => personaOn(deployment, admin, name, access);
770
852
  const reader = await person("reader", { [DEV]: "viewer" });
771
853
  const leaver = await person("leaver", { [DEV]: "developer" });
772
854
  const bulk = await person("bulk", { [BULK]: "viewer" });
773
- await admin.api.members.add(SERVICE);
774
- await admin.api.access.set(SERVICE, { [DEV]: "viewer" });
775
- const issued = await admin.api.tokens.issue(SERVICE, {
855
+ await admin.api.members.add(SERVICE$2);
856
+ await admin.api.access.set(SERVICE$2, { [DEV]: "viewer" });
857
+ const issued = await admin.api.tokens.issue(SERVICE$2, {
776
858
  label: "conformance",
777
859
  expiresInDays: 1
778
860
  });
@@ -788,7 +870,7 @@ async function personas(deployment, admin) {
788
870
  cliToken
789
871
  },
790
872
  service: {
791
- member: SERVICE,
873
+ member: SERVICE$2,
792
874
  token: issued.token,
793
875
  api: bearer(deployment.origin, issued.token)
794
876
  },
@@ -1284,7 +1366,7 @@ async function membersOnly(deployment, { stranger }) {
1284
1366
  expect(!attempt.ok, "someone never admitted signed in");
1285
1367
  expect(!stranger.browser.hasCookies, "the refused sign-in left the browser a cookie");
1286
1368
  expect((await stranger.browser.fetch("/api/me")).status === 401, "the refused sign-in left a session");
1287
- await refused("a made-up token read secrets", bearer(deployment.origin, "coffre_cli_conformanceforgedtokenconformanceforged").secrets.list(DEV));
1369
+ await refused$1("a made-up token read secrets", bearer(deployment.origin, "coffre_cli_conformanceforgedtokenconformanceforged").secrets.list(DEV));
1288
1370
  for (const [method, path, body] of [
1289
1371
  [
1290
1372
  "GET",
@@ -1322,18 +1404,18 @@ async function membersOnly(deployment, { stranger }) {
1322
1404
  async function grantScoping({ reader, service, bulk }, canaries) {
1323
1405
  const read = await reader.api.secrets.reveal(DEV);
1324
1406
  expect(same(read.values, valuesIn(canaries, DEV)), "a viewer on dev did not get dev's values", read.values);
1325
- await refused("a viewer on dev revealed prod", reader.api.secrets.reveal(PROD));
1326
- await refused("a viewer on dev listed prod", reader.api.secrets.list(PROD));
1327
- await refused("a viewer wrote a value", reader.api.secrets.set(DEV, { API_KEY: "from the reader" }));
1328
- await refused("a viewer granted themselves more", reader.api.access.set(reader.member, { [PROD]: "owner" }));
1329
- await refused("a viewer added a member", reader.api.members.add("user:friend@conformance.example"));
1330
- await refused("a viewer issued a service token", reader.api.tokens.issue(service.member, { expiresInDays: 1 }));
1407
+ await refused$1("a viewer on dev revealed prod", reader.api.secrets.reveal(PROD));
1408
+ await refused$1("a viewer on dev listed prod", reader.api.secrets.list(PROD));
1409
+ await refused$1("a viewer wrote a value", reader.api.secrets.set(DEV, { API_KEY: "from the reader" }));
1410
+ await refused$1("a viewer granted themselves more", reader.api.access.set(reader.member, { [PROD]: "owner" }));
1411
+ await refused$1("a viewer added a member", reader.api.members.add("user:friend@conformance.example"));
1412
+ await refused$1("a viewer issued a service token", reader.api.tokens.issue(service.member, { expiresInDays: 1 }));
1331
1413
  const places = (await reader.api.me()).environments.map((place) => `${place.project}/${place.environment}`);
1332
1414
  expect(places.length === 1 && places[0] === DEV, "a viewer on dev is told of other places", places);
1333
1415
  const served = await service.api.secrets.reveal(DEV);
1334
1416
  expect(same(served.values, valuesIn(canaries, DEV)), "a service viewer on dev did not get dev's values", served.values);
1335
- await refused("a service viewer on dev revealed prod", service.api.secrets.reveal(PROD));
1336
- await refused("a viewer on bulk revealed dev", bulk.api.secrets.reveal(DEV));
1417
+ await refused$1("a service viewer on dev revealed prod", service.api.secrets.reveal(PROD));
1418
+ await refused$1("a viewer on bulk revealed dev", bulk.api.secrets.reveal(DEV));
1337
1419
  return "a viewer on dev reads dev and nothing else, in a browser or with a token, and changes nothing";
1338
1420
  }
1339
1421
  /**
@@ -1396,29 +1478,81 @@ async function offboarding(deployment, { admin, leaver, service }, canaries) {
1396
1478
  const exposed = report.exposed.map((entry) => `${entry.project}/${entry.environment}/${entry.key}`).sort();
1397
1479
  expect(same(exposed, Object.keys(valuesIn(canaries, DEV)).map((key) => `${DEV}/${key}`).sort()), "the offboarding report does not name what they read", report.exposed);
1398
1480
  expect((await leaver.browser.fetch("/api/me")).status === 401, "a removed member's browser session still works");
1399
- await refused("a removed member's CLI session read secrets", leaver.cli.secrets.list(DEV));
1481
+ await refused$1("a removed member's CLI session read secrets", leaver.cli.secrets.list(DEV));
1400
1482
  expect(!(await signIn(deployment, leaver.browser, leaver.email)).ok, "a removed member signed in again");
1401
1483
  await admin.api.members.remove(service.member);
1402
- await refused("a removed service's token read secrets", service.api.secrets.reveal(DEV));
1484
+ await refused$1("a removed service's token read secrets", service.api.secrets.reveal(DEV));
1403
1485
  await admin.api.members.add(leaver.member);
1404
1486
  await admin.api.access.set(leaver.member, { [DEV]: "developer" });
1405
1487
  await admin.api.members.add(service.member);
1406
1488
  await admin.api.access.set(service.member, { [DEV]: "viewer" });
1407
1489
  expect((await leaver.browser.fetch("/api/me")).status === 401, "re-admission revived the browser session");
1408
- await refused("re-admission revived the CLI session", leaver.cli.secrets.reveal(DEV));
1409
- await refused("re-admission revived the service token", service.api.secrets.reveal(DEV));
1490
+ await refused$1("re-admission revived the CLI session", leaver.cli.secrets.reveal(DEV));
1491
+ await refused$1("re-admission revived the service token", service.api.secrets.reveal(DEV));
1410
1492
  expect(!(await pollDevice(deployment, device.device_code)).ok, "re-admission revived the old device approval");
1411
1493
  expect((await signIn(deployment, leaver.browser, leaver.email)).ok, "a fresh provider callback could not sign the re-admitted member in");
1412
1494
  await admin.api.members.remove(leaver.member);
1413
1495
  await admin.api.members.remove(service.member);
1414
1496
  return `the report names ${exposed.length} values; re-admission revives no old session, token or approval; a fresh provider callback works`;
1415
1497
  }
1498
+ /**
1499
+ * Grants on every project: one on `*` reaches a project made after it; one
1500
+ * on `*` and a slug reaches that environment in every project and never
1501
+ * another; nobody but an owner gives one; and removing a member takes
1502
+ * them. Its services are removed, and its project archived, as it ends.
1503
+ */
1504
+ async function everyProject(deployment, { admin, reader }, canaries) {
1505
+ const services = {
1506
+ everything: "token:conformance-everywhere",
1507
+ dev: "token:conformance-every-dev",
1508
+ manager: "token:conformance-manager"
1509
+ };
1510
+ const client = async (member) => bearer(deployment.origin, (await admin.api.tokens.issue(member, { expiresInDays: 1 })).token);
1511
+ for (const member of Object.values(services)) await admin.api.members.add(member);
1512
+ await admin.api.access.set(services.manager, { [PROJECT$1]: "access-manager" });
1513
+ await refused$1("a project's access manager granted on every project", (await client(services.manager)).access.set(services.everything, { "*": "viewer" }));
1514
+ await refused$1("a viewer granted themselves every project", reader.api.access.set(reader.member, { "*/prod": "viewer" }));
1515
+ await admin.api.access.set(services.everything, { "*": "viewer" });
1516
+ await admin.api.access.set(services.dev, { "*/dev": "viewer" });
1517
+ const [everything, dev] = [await client(services.everything), await client(services.dev)];
1518
+ const later = `${PROJECT$1}-later`;
1519
+ const made = await admin.api.projects.create(later, { name: "Made later" });
1520
+ expect(made.inherited.some((grant) => grant.member === services.everything && grant.place === "*"), "making a project did not say who reaches it", made.inherited);
1521
+ for (const environment of ["dev", "prod"]) {
1522
+ const path = `${later}/${environment}`;
1523
+ const { inherited } = await admin.api.environments.create(path, { name: environment });
1524
+ const reaches = inherited.filter((grant) => grant.member === services.dev).length;
1525
+ expect(reaches === (environment === "dev" ? 1 : 0), `making ${path} misnamed who reaches it through dev in every project`, inherited);
1526
+ canaries[`${path}/API_KEY`] = canary();
1527
+ await admin.api.secrets.set(path, valuesIn(canaries, path));
1528
+ }
1529
+ for (const path of [
1530
+ `${later}/prod`,
1531
+ `${later}/dev`,
1532
+ PROD
1533
+ ]) {
1534
+ const read = await everything.secrets.reveal(path);
1535
+ expect(read.values.API_KEY === canaries[`${path}/API_KEY`], `viewer on every project could not read ${path}`, read.values);
1536
+ }
1537
+ await refused$1("viewer on every project wrote a value", everything.secrets.set(`${later}/prod`, { API_KEY: "from everywhere" }));
1538
+ const devRead = await dev.secrets.reveal(`${later}/dev`);
1539
+ expect(devRead.values.API_KEY === canaries[`${later}/dev/API_KEY`], "viewer on dev in every project could not read a dev made later", devRead.values);
1540
+ await refused$1("viewer on dev in every project read a prod made later", dev.secrets.reveal(`${later}/prod`));
1541
+ await refused$1("viewer on dev in every project read prod", dev.secrets.reveal(PROD));
1542
+ for (const member of Object.values(services)) await admin.api.members.remove(member);
1543
+ await refused$1("a removed member read through a grant on every project", everything.secrets.reveal(`${later}/prod`));
1544
+ await refused$1("a removed member read through a grant on dev in every project", dev.secrets.reveal(`${later}/dev`));
1545
+ const left = (await admin.api.members.list("*")).members.filter((member) => Object.values(services).includes(member.member));
1546
+ expect(left.length === 0, "grants on every project outlived their members", left);
1547
+ await admin.api.projects.update(later, { archived: true });
1548
+ return "a grant on every project reaches a project made after it; one on dev, every dev and nothing else; refused to non-owners; gone with its member";
1549
+ }
1416
1550
  /** Reading more values at once than the vault allows in its window is refused. */
1417
1551
  async function bulkLimit$1({ admin, bulk }, limit) {
1418
1552
  const values = {};
1419
1553
  for (let i = 0; i <= limit; i++) values[`BULK_${i}`] = `bulk-${i}`;
1420
1554
  await admin.api.secrets.set(BULK, values);
1421
- const refusal = await refused(`${limit + 1} values were revealed at once`, bulk.api.secrets.reveal(BULK));
1555
+ const refusal = await refused$1(`${limit + 1} values were revealed at once`, bulk.api.secrets.reveal(BULK));
1422
1556
  expect(refusal.status === 403 && refusal.code === "bulk_limit" && refusal.reason === "bulk_limit", "the bulk read was not refused as bulk_limit", refusal);
1423
1557
  const one = await bulk.api.secrets.reveal(`${BULK}/BULK_0`);
1424
1558
  expect(one.values.BULK_0 === "bulk-0", "a viewer on bulk could not read one of its values", one.values);
@@ -1547,7 +1681,7 @@ async function writesAgree(deployment) {
1547
1681
  });
1548
1682
  }
1549
1683
  const versions = await query(sql, `SELECT v.secret_id, v.version FROM secret_versions v JOIN secrets s ON s.id = v.secret_id
1550
- JOIN projects p ON p.id = s.project_id WHERE p.slug = $1`, [PROJECT]);
1684
+ JOIN projects p ON p.id = s.project_id WHERE p.slug = $1`, [PROJECT$1]);
1551
1685
  expect(versions.length > 0, "no stored versions were inspected");
1552
1686
  for (const version of versions) {
1553
1687
  const matching = writes.filter((entry) => entry.secret_id === version.secret_id && JSON.parse(entry.metadata).version === version.version);
@@ -1763,6 +1897,285 @@ async function earlierCheckpoint(deployment, { admin }) {
1763
1897
  return "an invalid earlier checkpoint was caught despite valid MACs and a valid later checkpoint";
1764
1898
  }
1765
1899
  //#endregion
1900
+ //#region src/checks/deletion.ts
1901
+ const PROJECT = "conformance-gone";
1902
+ const SERVICE$1 = "token:conformance-gone-ci";
1903
+ /** Each version under a project, by whether it still holds a ciphertext or a wrapped key. */
1904
+ async function sealed(deployment, projectId) {
1905
+ const rows = await using(deployment.database(), (sql) => query(sql, `SELECT length(v.ciphertext) AS ciphertext, length(v.wrapped_dek) AS wrapped
1906
+ FROM secret_versions v JOIN secrets s ON s.id = v.secret_id WHERE s.project_id = $1`, [projectId]));
1907
+ return {
1908
+ versions: rows.length,
1909
+ sealed: rows.filter((row) => Number(row.ciphertext) > 0 || Number(row.wrapped) > 0).length
1910
+ };
1911
+ }
1912
+ async function projectId(deployment, slug) {
1913
+ const [row] = await using(deployment.database(), (sql) => query(sql, "SELECT id FROM projects WHERE slug = $1", [slug]));
1914
+ return row?.id;
1915
+ }
1916
+ async function deletion(deployment, cli, admin) {
1917
+ const run = async (args, code = 0) => {
1918
+ const result = await cli.run(args);
1919
+ expect(result.code === code, `coffre ${args.join(" ")} exited ${result.code}, not ${code}`, result.output);
1920
+ return result.output;
1921
+ };
1922
+ const value = () => `deleted-value-${randomBytes(8).toString("hex")}`;
1923
+ await admin.api.projects.create(PROJECT, { name: "Gone" });
1924
+ for (const environment of ["prod", "dev"]) {
1925
+ await admin.api.environments.create(`${PROJECT}/${environment}`, { name: environment });
1926
+ await admin.api.secrets.set(`${PROJECT}/${environment}`, {
1927
+ API_KEY: value(),
1928
+ DATABASE_URL: value()
1929
+ });
1930
+ }
1931
+ await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: value() });
1932
+ await admin.api.members.add(SERVICE$1);
1933
+ await admin.api.access.set(SERVICE$1, { [`${PROJECT}/prod`]: "viewer" });
1934
+ const id = await projectId(deployment, PROJECT);
1935
+ const live = await run([
1936
+ "projects",
1937
+ "delete",
1938
+ PROJECT,
1939
+ "--apply"
1940
+ ], 1);
1941
+ expect(/not archived/.test(live), "deleting a live project was not refused as not archived", live);
1942
+ await run([
1943
+ "projects",
1944
+ "archive",
1945
+ PROJECT
1946
+ ]);
1947
+ const preview = await run([
1948
+ "projects",
1949
+ "delete",
1950
+ PROJECT
1951
+ ]);
1952
+ expect(/erased: 5 versions/.test(preview) && /revoked: 1 grant/.test(preview) && preview.includes("service:conformance-gone-ci would hold nothing anywhere"), "the preview does not say what the deletion takes", preview);
1953
+ expect(/Backups taken before the deletion still hold the encrypted values/.test(preview) && /Nothing changed/.test(preview), "the preview does not warn of backups, or changed something", preview);
1954
+ expect((await sealed(deployment, id)).sealed === 5, "the preview erased something");
1955
+ const done = await run([
1956
+ "projects",
1957
+ "delete",
1958
+ PROJECT,
1959
+ "--apply"
1960
+ ]);
1961
+ expect(/^deleted conformance-gone, for good/.test(done), "the deletion did not say it was done", done);
1962
+ const after = await sealed(deployment, id);
1963
+ expect(after.versions === 5 && after.sealed === 0, "a deleted project still holds a ciphertext or a wrapped key", after);
1964
+ const [tombstone] = await using(deployment.database(), (sql) => query(sql, "SELECT slug FROM projects WHERE id = $1", [id]));
1965
+ expect(/^conformance-gone~deleted-\d{4}-\d{2}-\d{2}$/.test(tombstone?.slug ?? ""), "the tombstone is not named for the day", tombstone);
1966
+ expect((await admin.api.projects.list()).projects.every((project) => !project.slug.startsWith(PROJECT)), "a deleted project is still listed");
1967
+ expect((await admin.api.members.get(SERVICE$1)).live.grants === 0, "a grant on the deleted project is still live");
1968
+ const revealed = await admin.api.secrets.reveal(`${tombstone.slug}/prod`).then(() => null, (error) => error);
1969
+ expect(revealed instanceof CoffreError && revealed.status === 404, "a deleted project is still revealed by its tombstone", revealed);
1970
+ const fresh = value();
1971
+ await admin.api.projects.create(PROJECT, { name: "Gone, again" });
1972
+ await admin.api.environments.create(`${PROJECT}/prod`, { name: "prod" });
1973
+ await admin.api.secrets.set(`${PROJECT}/prod`, { API_KEY: fresh });
1974
+ expect(await projectId(deployment, PROJECT) !== id, "the new project took the deleted one's row");
1975
+ expect((await admin.api.secrets.reveal(`${PROJECT}/prod/API_KEY`)).values.API_KEY === fresh, "the new project does not read its own value");
1976
+ const { entries } = await admin.api.audit.list({
1977
+ path: tombstone.slug,
1978
+ limit: 500
1979
+ });
1980
+ expect(entries.some((entry) => entry.action === "project.delete" && entry.decision === "allow"), "the deletion is not in the log under its tombstone", entries.slice(0, 5));
1981
+ await admin.api.environments.update(`${PROJECT}/prod`, { archived: true });
1982
+ await run([
1983
+ "environments",
1984
+ "delete",
1985
+ `${PROJECT}/prod`,
1986
+ "--apply"
1987
+ ]);
1988
+ await admin.api.environments.create(`${PROJECT}/prod`, { name: "prod, again" });
1989
+ const environments = (await admin.api.projects.list()).projects.find((project) => project.slug === PROJECT)?.environments ?? [];
1990
+ expect(environments.length === 1 && environments[0].name === "prod, again", "a deleted environment is still listed, or its slug is not free", environments);
1991
+ expect((await sealed(deployment, await projectId(deployment, PROJECT))).sealed === 0, "a deleted environment still holds a value");
1992
+ const verified = await admin.api.audit.verify();
1993
+ expect(verified.ok, "the log does not verify after the deletions", verified);
1994
+ return `${PROJECT} and ${PROJECT}/prod deleted by the CLI: 5 versions erased, a grant revoked, both unlisted and their slugs reused; ${verified.entries} entries verify`;
1995
+ }
1996
+ //#endregion
1997
+ //#region src/checks/environments.ts
1998
+ /** Where the fork check copies dev to; archived once checked. */
1999
+ const FORKED = `${PROJECT$1}/forked`;
2000
+ /**
2001
+ * A folder grants, hides and renames nothing: a secret filed in one is
2002
+ * still read, run and exported by its own name, by the same people, and
2003
+ * only those who may write may file it.
2004
+ */
2005
+ async function folders({ admin, reader }, canaries) {
2006
+ const keys = Object.keys(valuesIn(canaries, DEV));
2007
+ const key = keys[0];
2008
+ expect(key !== void 0, "dev holds no secret to file");
2009
+ await admin.api.projects.update(PROJECT$1, { folder: "Conformance" });
2010
+ await admin.api.secrets.update(`${DEV}/${key}`, { folder: "filed" });
2011
+ try {
2012
+ const project = (await reader.api.projects.list()).projects.find((each) => each.slug === PROJECT$1);
2013
+ expect(project?.folder === "Conformance", "a project filed in a folder is not listed in it", project);
2014
+ const listed = (await reader.api.secrets.list(DEV)).keys.find((each) => each.key === key);
2015
+ expect(listed?.folder === "filed", "a secret filed in a folder is not listed in it", listed);
2016
+ const read = await reader.api.secrets.reveal(DEV);
2017
+ expect(JSON.stringify(Object.keys(read.values).sort()) === JSON.stringify([...keys].sort()), "filing a secret changed the names a run injects", Object.keys(read.values));
2018
+ expect(read.values[key] === canaries[`${DEV}/${key}`], "filing a secret changed its value");
2019
+ await refused$1("a viewer filed a secret", reader.api.secrets.update(`${DEV}/${key}`, { folder: "elsewhere" }));
2020
+ await refused$1("a viewer filed a project", reader.api.projects.update(PROJECT$1, { folder: "Elsewhere" }));
2021
+ await refused$1("a folder name with a slash was taken", admin.api.secrets.update(`${DEV}/${key}`, { folder: "a/b" }));
2022
+ } finally {
2023
+ await admin.api.secrets.update(`${DEV}/${key}`, { folder: null });
2024
+ await admin.api.projects.update(PROJECT$1, { folder: null });
2025
+ }
2026
+ return "a filed secret is read and run by its own name, by the same people; only writers file it";
2027
+ }
2028
+ /**
2029
+ * A fork copies dev's values into a new environment, and nothing of who
2030
+ * may read dev: a viewer on dev reads neither the fork nor makes one.
2031
+ */
2032
+ async function forks({ admin, reader }, canaries) {
2033
+ const dev = valuesIn(canaries, DEV);
2034
+ await refused$1("a viewer forked an environment", reader.api.environments.create(FORKED, {
2035
+ name: "Forked",
2036
+ from: DEV.split("/")[1]
2037
+ }));
2038
+ const made = await admin.api.environments.create(FORKED, {
2039
+ name: "Forked",
2040
+ from: DEV.split("/")[1]
2041
+ });
2042
+ try {
2043
+ expect(made.forked?.keys === Object.keys(dev).length, "the fork did not copy each of dev's keys", made);
2044
+ const read = await admin.api.secrets.reveal(FORKED);
2045
+ expect(JSON.stringify(Object.entries(read.values).sort()) === JSON.stringify(Object.entries(dev).sort()), "the fork's values are not dev's");
2046
+ const history = await admin.api.secrets.history(`${FORKED}/${Object.keys(dev)[0]}`);
2047
+ expect(history.versions.length === 1, "the fork carried history", history.versions);
2048
+ await refused$1("a viewer on dev read dev's fork", reader.api.secrets.reveal(FORKED));
2049
+ } finally {
2050
+ await admin.api.environments.update(FORKED, { archived: true });
2051
+ }
2052
+ return "a fork holds dev's values and no history, and a viewer on dev neither makes one nor reads it";
2053
+ }
2054
+ /** The key in dev the reference check makes, archived once checked. */
2055
+ const HELD = "CONFORMANCE_REFERENCE";
2056
+ const FORGED = "CONFORMANCE_FORGED";
2057
+ /** The status a call failed with and its reason, the vault's or the app's, or that it went through. */
2058
+ async function outcome(call) {
2059
+ try {
2060
+ await call;
2061
+ return "let through";
2062
+ } catch (error) {
2063
+ if (!(error instanceof CoffreError)) throw error;
2064
+ return `${error.status} ${error.reason ?? error.code}`;
2065
+ }
2066
+ }
2067
+ /**
2068
+ * A reference lets whoever reads its holder read its source, so only the
2069
+ * vault makes one, and a read through one is checked against the vault's
2070
+ * own entry: the reader, a viewer on dev with no grant on prod, reads
2071
+ * prod's value through dev's reference, and the read is in prod's log and
2072
+ * dev's; a reference row the vault never made, written straight into the
2073
+ * database, reads nothing; a developer on dev who cannot read prod makes
2074
+ * none; and once broken, it reads no more.
2075
+ */
2076
+ async function references(deployment, { admin, reader, leaver }, canaries) {
2077
+ const [sourceKey] = Object.keys(valuesIn(canaries, PROD));
2078
+ expect(sourceKey !== void 0, "prod holds no secret to refer to");
2079
+ const source = `${PROD}/${sourceKey}`;
2080
+ await refused$1("a viewer on dev read prod directly", reader.api.secrets.reveal(source));
2081
+ expect(await outcome(leaver.api.secrets.set(DEV, { [HELD]: { ref: source } })) === "403 missing_secret_read", "a developer on dev who cannot read prod made a reference to prod's secret");
2082
+ await admin.api.secrets.set(DEV, { [HELD]: { ref: source } });
2083
+ try {
2084
+ expect((await reader.api.secrets.reveal(`${DEV}/${HELD}`)).values[HELD] === canaries[source], "a viewer on dev did not read prod's value through dev's reference");
2085
+ const logged = async (path) => (await admin.api.audit.list({
2086
+ path,
2087
+ limit: 200
2088
+ })).entries.filter((entry) => entry.action === "secret.read" && entry.actorId === reader.email && entry.metadata.via !== void 0).length;
2089
+ expect(await logged(PROD) >= 1 && await logged(DEV) >= 1, "the read through the reference is not in both the source's log and the holder's");
2090
+ const archives = [[source, (archived) => admin.api.secrets.update(source, { archived })], [PROD, (archived) => admin.api.environments.update(PROD, { archived })]];
2091
+ for (const [what, archive] of archives) {
2092
+ const refusal = await archive(true).then(() => null, (error) => error);
2093
+ if (refusal === null) await archive(false);
2094
+ expect(refusal instanceof CoffreError && refusal.status === 409 && refusal.message.includes(`${DEV}/${HELD} reads ${source}`), `${what} was archived, or refused without naming the reference, while a reference read it`, refusal instanceof Error ? refusal.message : refusal);
2095
+ }
2096
+ await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
2097
+ const underArchived = await outcome(admin.api.secrets.update(source, { archived: true })).finally(() => admin.api.secrets.update(`${DEV}/${HELD}`, { archived: false }));
2098
+ try {
2099
+ expect(underArchived === "let through", `${source} could not be archived while only an archived key referred to it: ${underArchived}`);
2100
+ const restored = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
2101
+ expect(restored.startsWith("409 "), `a reference read a source archived while its holder was: ${restored}`);
2102
+ } finally {
2103
+ if (underArchived === "let through") await admin.api.secrets.update(source, { archived: false });
2104
+ }
2105
+ expect((await reader.api.secrets.reveal(`${DEV}/${HELD}`)).values[HELD] === canaries[source], "a reference did not read its source again once both were restored");
2106
+ const forged = await using(deployment.database(), async (sql) => {
2107
+ const [holder] = await query(sql, "SELECT id, project_id, environment_id FROM secrets WHERE key = $1", [HELD]);
2108
+ const [target] = await query(sql, "SELECT s.id, s.project_id, s.environment_id FROM secrets s JOIN environments e ON e.id = s.environment_id WHERE s.key = $1 AND e.slug = $2", [sourceKey, PROD.split("/")[1]]);
2109
+ const [entry] = await query(sql, "SELECT seq FROM audit_log WHERE author = 'vault' AND action = 'access.grant' AND decision = 'allow' ORDER BY seq DESC LIMIT 1");
2110
+ const id = randomUUID();
2111
+ await query(sql, "INSERT INTO secrets (id, project_id, environment_id, key, current_version) VALUES ($1, $2, $3, $4, 0)", [
2112
+ id,
2113
+ holder.project_id,
2114
+ holder.environment_id,
2115
+ FORGED
2116
+ ]);
2117
+ await query(sql, `INSERT INTO secret_references (id, project_id, environment_id, secret_id, source_project_id, source_environment_id, source_secret_id, created_seq, created_by)
2118
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [
2119
+ randomUUID(),
2120
+ holder.project_id,
2121
+ holder.environment_id,
2122
+ id,
2123
+ target.project_id,
2124
+ target.environment_id,
2125
+ target.id,
2126
+ String(entry.seq),
2127
+ admin.member
2128
+ ]);
2129
+ return id;
2130
+ });
2131
+ try {
2132
+ const forgedRead = await outcome(reader.api.secrets.reveal(`${DEV}/${FORGED}`));
2133
+ expect([
2134
+ "404 no_value",
2135
+ "404 not_found",
2136
+ "403 bad_claim"
2137
+ ].includes(forgedRead), `a reference row the vault never made was read: ${forgedRead}`);
2138
+ } finally {
2139
+ await using(deployment.database(), async (sql) => {
2140
+ await query(sql, "DELETE FROM secret_references WHERE secret_id = $1", [forged]);
2141
+ await query(sql, "DELETE FROM secrets WHERE id = $1", [forged]);
2142
+ });
2143
+ }
2144
+ await admin.api.references.break(`${DEV}/${HELD}`);
2145
+ const after = await outcome(reader.api.secrets.reveal(`${DEV}/${HELD}`));
2146
+ expect(after.startsWith("409 "), `a broken reference still read: ${after}`);
2147
+ } finally {
2148
+ await admin.api.secrets.update(`${DEV}/${HELD}`, { archived: true });
2149
+ }
2150
+ return "a viewer on dev reads prod's value through a reference, logged in both; prod and its key cannot be archived while it reads them, but can once its holder is archived, which then reads nothing until they are back; a forged row is refused, a broken one reads no more, and none is made without read on the source";
2151
+ }
2152
+ /** A key prod has and dev does not, for the missing-keys check; archived once checked. */
2153
+ const PROD_ONLY = "CONFORMANCE_PROD_ONLY";
2154
+ /**
2155
+ * Key names are metadata: what dev is missing is compared only with the
2156
+ * environments the viewer reads. The admin sees prod's key missing from dev;
2157
+ * the reader, a viewer on dev alone, sees nothing of prod, and dismisses
2158
+ * nothing. A dismissal is the team's, and restoring undoes it.
2159
+ */
2160
+ async function missingKeys({ admin, reader }) {
2161
+ await admin.api.secrets.set(PROD, { [PROD_ONLY]: canary() });
2162
+ try {
2163
+ const seen = await admin.api.environments.missing(DEV);
2164
+ expect(seen.missing.some((key) => key.key === PROD_ONLY), "the admin was not told dev lacks prod's key", seen);
2165
+ const hidden = await reader.api.environments.missing(DEV);
2166
+ expect(![...hidden.missing, ...hidden.dismissed].some((key) => key.key === PROD_ONLY), "a viewer on dev learned a key name from prod, which they cannot read", hidden);
2167
+ await refused$1("a viewer dismissed a missing key", reader.api.environments.dismiss(DEV, { [PROD_ONLY]: true }));
2168
+ await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: true });
2169
+ const dismissed = await admin.api.environments.missing(DEV);
2170
+ expect(dismissed.dismissed.some((key) => key.key === PROD_ONLY) && !dismissed.missing.some((key) => key.key === PROD_ONLY), "a dismissed key was still listed as missing", dismissed);
2171
+ await admin.api.environments.dismiss(DEV, { [PROD_ONLY]: null });
2172
+ expect((await admin.api.environments.missing(DEV)).missing.some((key) => key.key === PROD_ONLY), "a restored key was not missing again");
2173
+ } finally {
2174
+ await admin.api.secrets.update(`${PROD}/${PROD_ONLY}`, { archived: true });
2175
+ }
2176
+ return "only who reads prod learns what dev lacks of it; a viewer dismisses nothing; a dismissal is listed, and restored";
2177
+ }
2178
+ //#endregion
1766
2179
  //#region src/checks/logins.ts
1767
2180
  const ZEROS = "decode(repeat('00', 32), 'hex')";
1768
2181
  const appendAs = (author) => `INSERT INTO audit_log
@@ -1876,6 +2289,582 @@ async function vaultLogin(deployment) {
1876
2289
  });
1877
2290
  }
1878
2291
  //#endregion
2292
+ //#region src/checks/mcp.ts
2293
+ const NAME = "Conformance MCP client";
2294
+ /** A native client's redirect, on loopback. A custom scheme is left out of a registration (D37). */
2295
+ const REDIRECT = "http://127.0.0.1:33418/callback";
2296
+ /** A `state` the router would read as a number: it must come back as sent. */
2297
+ const STATE = "1e5";
2298
+ /** What every 2026-07-28 request carries: its revision and the client's capabilities. */
2299
+ const ENVELOPE = {
2300
+ "io.modelcontextprotocol/protocolVersion": "2026-07-28",
2301
+ "io.modelcontextprotocol/clientCapabilities": {}
2302
+ };
2303
+ const base64url = (bytes) => bytes.toString("base64url");
2304
+ async function json(response) {
2305
+ const text = await response.text();
2306
+ try {
2307
+ return JSON.parse(text);
2308
+ } catch {
2309
+ return { text };
2310
+ }
2311
+ }
2312
+ /** A JSON-RPC message to /mcp, with the headers a client sends. */
2313
+ function mcp(deployment, headers, method = "server/discover", params = {}) {
2314
+ return fetch(`${deployment.origin}/mcp`, {
2315
+ method: "POST",
2316
+ headers: {
2317
+ "content-type": "application/json",
2318
+ accept: "application/json, text/event-stream",
2319
+ ...headers
2320
+ },
2321
+ body: JSON.stringify({
2322
+ jsonrpc: "2.0",
2323
+ id: 1,
2324
+ method,
2325
+ params
2326
+ })
2327
+ });
2328
+ }
2329
+ function token(deployment, fields) {
2330
+ return fetch(`${deployment.origin}/api/oauth/token`, {
2331
+ method: "POST",
2332
+ headers: { "content-type": "application/x-www-form-urlencoded" },
2333
+ body: new URLSearchParams(fields)
2334
+ });
2335
+ }
2336
+ /** The person approves on the consent page, as its Approve does; the code comes back on the redirect. */
2337
+ async function connect(deployment, person, clientId, scope = "browse") {
2338
+ const verifier = base64url(randomBytes(32));
2339
+ const request = {
2340
+ client_id: clientId,
2341
+ redirect_uri: REDIRECT,
2342
+ response_type: "code",
2343
+ code_challenge: base64url(createHash("sha256").update(verifier).digest()),
2344
+ code_challenge_method: "S256",
2345
+ state: STATE,
2346
+ scope,
2347
+ resource: `${deployment.origin}/mcp`
2348
+ };
2349
+ const view = await person.api.oauth.describe(request);
2350
+ expect(view.status === "ready", "the consent page refused a good request", view);
2351
+ expect(view.client.registration === "dcr" && view.client.name === NAME && view.scopes.join(" ") === scope && view.loopbackOnly, "the consent page does not show the registered client as it is", view);
2352
+ const { redirect } = await person.api.oauth.decide({
2353
+ request,
2354
+ approve: true,
2355
+ scopes: scope.split(" ")
2356
+ });
2357
+ const back = new URL(redirect);
2358
+ expect(`${back.origin}${back.pathname}` === REDIRECT, `the answer went to ${back.origin}${back.pathname}, not the redirect`, redirect);
2359
+ expect(back.searchParams.get("state") === STATE && back.searchParams.get("iss") === deployment.origin, "the answer does not carry the state as sent and the issuer", redirect);
2360
+ const code = back.searchParams.get("code");
2361
+ expect(code !== null, "an approval carried no code", redirect);
2362
+ return {
2363
+ code,
2364
+ verifier
2365
+ };
2366
+ }
2367
+ async function redeem(deployment, clientId, { code, verifier }) {
2368
+ const answer = await token(deployment, {
2369
+ grant_type: "authorization_code",
2370
+ code,
2371
+ code_verifier: verifier,
2372
+ redirect_uri: REDIRECT,
2373
+ client_id: clientId,
2374
+ resource: `${deployment.origin}/mcp`
2375
+ });
2376
+ const body = await json(answer);
2377
+ expect(answer.status === 200 && typeof body.access_token === "string" && typeof body.refresh_token === "string", `redeeming the code answered ${answer.status}`, body);
2378
+ expect(answer.headers.get("cache-control") === "no-store", "tokens were answered without cache-control: no-store");
2379
+ return body;
2380
+ }
2381
+ async function refused(deployment, what, fields) {
2382
+ const answer = await token(deployment, fields);
2383
+ const body = await json(answer);
2384
+ expect(answer.status === 400 && body.error === "invalid_grant", `${what} answered ${answer.status}, not invalid_grant`, body);
2385
+ }
2386
+ async function discovers(deployment, access) {
2387
+ const answer = await mcp(deployment, {
2388
+ authorization: `Bearer ${access}`,
2389
+ "mcp-protocol-version": "2026-07-28",
2390
+ "mcp-method": "server/discover"
2391
+ }, "server/discover", { _meta: ENVELOPE });
2392
+ if (answer.status === 401) return false;
2393
+ const body = await json(answer);
2394
+ expect(answer.status === 200 && Array.isArray(body.result?.supportedVersions), `server/discover answered ${answer.status}`, body);
2395
+ return true;
2396
+ }
2397
+ async function mcpConnect(deployment, people) {
2398
+ const { origin } = deployment;
2399
+ const anonymous = await mcp(deployment, {});
2400
+ const challenge = anonymous.headers.get("www-authenticate") ?? "";
2401
+ expect(anonymous.status === 401, `/mcp answered ${anonymous.status} without a token, not 401`);
2402
+ expect(challenge.includes(`resource_metadata="${origin}/.well-known/oauth-protected-resource/mcp"`) && challenge.includes("scope=\"browse\""), "the 401's challenge does not name the resource metadata and Browse", challenge);
2403
+ const resource = await json(await fetch(`${origin}/.well-known/oauth-protected-resource/mcp`));
2404
+ expect(resource.resource === `${origin}/mcp` && resource.authorization_servers?.[0] === origin, "the protected resource metadata does not name /mcp and coffre as its issuer", resource);
2405
+ const server = await json(await fetch(`${origin}/.well-known/oauth-authorization-server`));
2406
+ expect(server.issuer === origin && server.authorization_endpoint === `${origin}/oauth/authorize`, "the authorization server metadata is wrong", server);
2407
+ for (const [field, value] of [
2408
+ ["code_challenge_methods_supported", "S256"],
2409
+ ["token_endpoint_auth_methods_supported", "none"],
2410
+ ["grant_types_supported", "refresh_token"]
2411
+ ]) expect(server[field]?.includes(value), `the authorization server metadata leaves ${value} out of ${field}`, server);
2412
+ expect(server.client_id_metadata_document_supported === true, "the authorization server metadata does not offer metadata documents", server);
2413
+ const registered = await fetch(`${origin}/api/oauth/register`, {
2414
+ method: "POST",
2415
+ headers: { "content-type": "application/json" },
2416
+ body: JSON.stringify({
2417
+ client_name: NAME,
2418
+ redirect_uris: [REDIRECT, "conformance-app://callback"],
2419
+ token_endpoint_auth_method: "none"
2420
+ })
2421
+ });
2422
+ const client = await json(registered);
2423
+ expect(registered.status === 201 && typeof client.client_id === "string", `registering answered ${registered.status}`, client);
2424
+ expect(JSON.stringify(client.redirect_uris) === JSON.stringify([REDIRECT]), "the registration kept a redirect it should have left out", client);
2425
+ const clientId = client.client_id;
2426
+ const page = await people.reader.browser.fetch(`/oauth/authorize?${new URLSearchParams({
2427
+ client_id: clientId,
2428
+ redirect_uri: REDIRECT
2429
+ })}`);
2430
+ expect(page.status === 200, `the consent page answered ${page.status}`);
2431
+ const forged = await people.reader.browser.fetch("/api/oauth/authorizations", {
2432
+ method: "POST",
2433
+ headers: {
2434
+ origin: "https://attacker.example",
2435
+ "sec-fetch-site": "cross-site",
2436
+ "content-type": "application/json"
2437
+ },
2438
+ body: JSON.stringify({
2439
+ request: {
2440
+ client_id: clientId,
2441
+ redirect_uri: REDIRECT
2442
+ },
2443
+ approve: true
2444
+ })
2445
+ });
2446
+ expect(forged.status === 403, `another site's approval answered ${forged.status}, not 403`);
2447
+ const first = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
2448
+ expect(first.access_token.startsWith("coffre_mcp_") && first.refresh_token.startsWith("coffre_mcr_") && first.scope === "browse", "the tokens are not the shapes and scope coffre issues", { scope: first.scope });
2449
+ expect(await discovers(deployment, first.access_token), "a fresh access token was refused at /mcp");
2450
+ const atApi = await fetch(`${origin}/api/me`, { headers: { authorization: `Bearer ${first.access_token}` } });
2451
+ expect(atApi.status === 401, `an MCP token at /api answered ${atApi.status}, not 401`);
2452
+ const cli = await mcp(deployment, { authorization: `Bearer ${people.leaver.cliToken}` });
2453
+ expect(cli.status === 401, `a CLI session at /mcp answered ${cli.status}, not 401`);
2454
+ const browser = await people.reader.browser.fetch("/mcp", {
2455
+ method: "POST",
2456
+ headers: {
2457
+ "content-type": "application/json",
2458
+ origin
2459
+ },
2460
+ body: JSON.stringify({
2461
+ jsonrpc: "2.0",
2462
+ id: 1,
2463
+ method: "server/discover"
2464
+ })
2465
+ });
2466
+ expect(browser.status === 401, `a browser's cookie at /mcp answered ${browser.status}, not 401`);
2467
+ const foreign = await mcp(deployment, {
2468
+ authorization: `Bearer ${first.access_token}`,
2469
+ origin: "https://attacker.example"
2470
+ });
2471
+ expect(foreign.status === 403, `/mcp answered ${foreign.status} to another site's page, not 403`);
2472
+ const rotate = (refresh) => token(deployment, {
2473
+ grant_type: "refresh_token",
2474
+ refresh_token: refresh,
2475
+ client_id: clientId
2476
+ });
2477
+ const rotated = await rotate(first.refresh_token);
2478
+ const next = await json(rotated);
2479
+ expect(rotated.status === 200 && next.refresh_token !== first.refresh_token, `refreshing answered ${rotated.status}, or the same refresh token`);
2480
+ expect(await discovers(deployment, next.access_token), "a refreshed access token was refused");
2481
+ await refused(deployment, "a replaced refresh token", {
2482
+ grant_type: "refresh_token",
2483
+ refresh_token: first.refresh_token,
2484
+ client_id: clientId
2485
+ });
2486
+ await refused(deployment, "the current refresh token, after a reuse", {
2487
+ grant_type: "refresh_token",
2488
+ refresh_token: next.refresh_token,
2489
+ client_id: clientId
2490
+ });
2491
+ expect(!await discovers(deployment, next.access_token), "an access token outlived its connection, ended by a reused refresh token");
2492
+ const asked = await connect(deployment, people.reader, clientId);
2493
+ const second = await redeem(deployment, clientId, asked);
2494
+ await refused(deployment, "a code redeemed already", {
2495
+ grant_type: "authorization_code",
2496
+ code: asked.code,
2497
+ code_verifier: asked.verifier,
2498
+ redirect_uri: REDIRECT,
2499
+ client_id: clientId
2500
+ });
2501
+ expect(!await discovers(deployment, second.access_token), "an access token outlived its connection, ended by a reused code");
2502
+ const third = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
2503
+ const listed = (await people.reader.api.apps.list()).apps;
2504
+ expect(listed.length === 1 && listed[0].name === NAME && listed[0].registration === "dcr", "Connected apps does not list the one live connection", listed);
2505
+ await people.reader.api.apps.disconnect(listed[0].id);
2506
+ expect(!await discovers(deployment, third.access_token), "an access token outlived its disconnection");
2507
+ expect((await people.reader.api.apps.list()).apps.length === 0, "a disconnected app is still listed");
2508
+ const { entries } = await people.admin.api.audit.list({
2509
+ actor: people.reader.member,
2510
+ detail: "1",
2511
+ limit: 500
2512
+ });
2513
+ const mine = entries.filter((entry) => entry.metadata.clientId === clientId);
2514
+ const count = (action) => mine.filter((entry) => entry.action === action && entry.decision === "allow").length;
2515
+ const counts = {
2516
+ connect: count("mcp.connect"),
2517
+ token: count("mcp.token"),
2518
+ disconnect: count("mcp.disconnect")
2519
+ };
2520
+ expect(counts.connect === 3 && counts.token === 4 && counts.disconnect === 3, "the log does not hold each connection, token and disconnection", counts);
2521
+ const reasons = mine.filter((entry) => entry.action === "mcp.disconnect").map((entry) => entry.metadata.reason).sort();
2522
+ expect(JSON.stringify(reasons) === JSON.stringify([
2523
+ "code_reused",
2524
+ "person",
2525
+ "refresh_reused"
2526
+ ]), "the disconnections do not say why", reasons);
2527
+ return "401 and both metadata documents; registered, approved, redeemed and discovered; only at /mcp, and only its token there; a reused refresh token, a reused code and a disconnection each end the connection, and the log says so";
2528
+ }
2529
+ /** A 2026-07-28 request as a client sends it: its headers say what its body does; `capabilities` are the client's. */
2530
+ async function modern(deployment, access, method, params = {}, name, capabilities = {}) {
2531
+ const response = await mcp(deployment, {
2532
+ authorization: `Bearer ${access}`,
2533
+ "mcp-protocol-version": "2026-07-28",
2534
+ "mcp-method": method,
2535
+ ...name === void 0 ? {} : { "mcp-name": name }
2536
+ }, method, {
2537
+ ...params,
2538
+ _meta: {
2539
+ ...ENVELOPE,
2540
+ "io.modelcontextprotocol/clientCapabilities": capabilities
2541
+ }
2542
+ });
2543
+ return {
2544
+ response,
2545
+ body: await json(response)
2546
+ };
2547
+ }
2548
+ /** A client registered for one check, by the name every check's client has. */
2549
+ async function register(deployment) {
2550
+ return (await json(await fetch(`${deployment.origin}/api/oauth/register`, {
2551
+ method: "POST",
2552
+ headers: { "content-type": "application/json" },
2553
+ body: JSON.stringify({
2554
+ client_name: NAME,
2555
+ redirect_uris: [REDIRECT]
2556
+ })
2557
+ }))).client_id;
2558
+ }
2559
+ /**
2560
+ * The Browse tools, as a client calls them (design section 14, checks 1, 4
2561
+ * and 5): on 2026-07-28 and through a 2025-11-25 `initialize`, as the
2562
+ * reader, who sees dev and not prod. No value appears in any answer, the
2563
+ * headers must agree with the body, and every call is in the log under the
2564
+ * client, the API's own entries naming the connection.
2565
+ */
2566
+ async function mcpBrowse(deployment, people, canaries) {
2567
+ const clientId = await register(deployment);
2568
+ const { access_token: access } = await redeem(deployment, clientId, await connect(deployment, people.reader, clientId));
2569
+ const answers = [];
2570
+ const discovered = await modern(deployment, access, "server/discover");
2571
+ answers.push(JSON.stringify(discovered.body));
2572
+ expect(discovered.response.status === 200, `server/discover answered ${discovered.response.status}`, discovered.body);
2573
+ const listed = await modern(deployment, access, "tools/list");
2574
+ const result = listed.body.result;
2575
+ const names = result?.tools?.map((tool) => tool.name) ?? [];
2576
+ expect(names.includes("list_secrets") && names.includes("run_with_secrets") && result?.cacheScope === "public" && typeof result.ttlMs === "number", "tools/list does not list the Browse tools, cacheable", listed.body);
2577
+ const callTool = async (tool, args) => {
2578
+ const { response, body } = await modern(deployment, access, "tools/call", {
2579
+ name: tool,
2580
+ arguments: args
2581
+ }, tool);
2582
+ answers.push(JSON.stringify(body));
2583
+ expect(response.status === 200, `tools/call ${tool} answered ${response.status}`, body);
2584
+ return body.result;
2585
+ };
2586
+ const keys = ((await callTool("list_secrets", { environment: DEV })).structuredContent?.keys ?? []).map((key) => key.key);
2587
+ expect(["API_KEY", "DATABASE_URL"].every((key) => keys.includes(key)), `list_secrets on ${DEV} does not list its keys`, keys);
2588
+ const prod = await callTool("list_secrets", { environment: PROD });
2589
+ expect(prod.isError === true, `the reader listed ${PROD}'s keys through MCP, which they cannot`, prod);
2590
+ const run = await callTool("run_with_secrets", {
2591
+ environment: DEV,
2592
+ command: "npm test"
2593
+ });
2594
+ expect(run.content?.[0]?.text?.includes(`coffre run ${DEV} -- npm test`) === true, "run_with_secrets does not say how to run the command", run);
2595
+ for (const tool of ["whoami", "list_projects"]) await callTool(tool, {});
2596
+ await callTool("secret_history", { secret: `${DEV}/API_KEY` });
2597
+ const mismatched = await mcp(deployment, {
2598
+ authorization: `Bearer ${access}`,
2599
+ "mcp-protocol-version": "2026-07-28",
2600
+ "mcp-method": "tools/call",
2601
+ "mcp-name": "list_projects"
2602
+ }, "tools/call", {
2603
+ name: "whoami",
2604
+ arguments: {},
2605
+ _meta: ENVELOPE
2606
+ });
2607
+ const mismatch = await json(mismatched);
2608
+ expect(mismatched.status === 400 && mismatch.error?.code === -32020, `a Mcp-Name naming another tool answered ${mismatched.status}`, mismatch);
2609
+ const initialized = await mcp(deployment, { authorization: `Bearer ${access}` }, "initialize", {
2610
+ protocolVersion: "2025-11-25",
2611
+ capabilities: {},
2612
+ clientInfo: {
2613
+ name: "coffre-conformance",
2614
+ version: "1"
2615
+ }
2616
+ });
2617
+ const init = await json(initialized);
2618
+ expect(initialized.status === 200 && init.result?.protocolVersion === "2025-11-25", `initialize for 2025-11-25 answered ${initialized.status}`, init);
2619
+ expect(initialized.headers.get("mcp-session-id") === null, "initialize minted a session: coffre keeps none");
2620
+ const legacy = await mcp(deployment, {
2621
+ authorization: `Bearer ${access}`,
2622
+ "mcp-protocol-version": "2025-11-25"
2623
+ }, "tools/call", {
2624
+ name: "list_secrets",
2625
+ arguments: { environment: DEV }
2626
+ });
2627
+ const legacyBody = await json(legacy);
2628
+ answers.push(JSON.stringify(legacyBody));
2629
+ expect(legacy.status === 200 && legacyBody.result?.isError !== true, `a 2025-11-25 tools/call answered ${legacy.status}`, legacyBody);
2630
+ const leaked = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
2631
+ expect(leaked.length === 0, "a Browse tool answered with a secret value", leaked);
2632
+ const { entries } = await people.admin.api.audit.list({
2633
+ actor: people.reader.member,
2634
+ detail: "1",
2635
+ limit: 500
2636
+ });
2637
+ const mine = entries.filter((entry) => entry.metadata.via?.clientId === clientId);
2638
+ const reads = mine.filter((entry) => entry.action === "mcp.read").length;
2639
+ const refused = mine.filter((entry) => entry.action === "mcp.call" && entry.decision === "deny").length;
2640
+ expect(reads === 6 && refused === 1, "the log does not hold each call under the client", {
2641
+ reads,
2642
+ refused
2643
+ });
2644
+ expect(mine.filter((entry) => !entry.action.startsWith("mcp.")).length > 0, "the API's own entries for the calls do not name the connection", mine.map((entry) => entry.action));
2645
+ const shown = (await people.admin.api.audit.list({
2646
+ actor: people.reader.member,
2647
+ limit: 500
2648
+ })).entries;
2649
+ expect(!shown.some((entry) => entry.action === "mcp.read"), "read-only calls are not detail");
2650
+ return `on 2026-07-28 and 2025-11-25, the Browse tools as the reader: ${DEV} listed, ${PROD} refused, no value in any answer; headers held to the body; ${reads} reads as detail and the refusal shown, each under the client`;
2651
+ }
2652
+ /**
2653
+ * Changes, as a client asks for them (design section 14, checks 2 and 3):
2654
+ * Browse cannot ask at all, and with Write nothing changes until the person
2655
+ * approves on coffre's page. A client without URL elicitation gets the link
2656
+ * and calls again; one with it is asked to open the page, and retries with
2657
+ * its requestState, which no other call may use. Only the person decides,
2658
+ * with the digest the page showed; the page makes the change, once, and its
2659
+ * entries name the client and the approval. A value comes from the page.
2660
+ */
2661
+ async function mcpChanges(deployment, people, canaries) {
2662
+ const { admin } = people;
2663
+ const place = `${PROJECT$1}-mcp/dev`;
2664
+ await admin.api.projects.create(`${PROJECT$1}-mcp`, { name: "MCP changes" });
2665
+ await admin.api.environments.create(place, { name: "Development" });
2666
+ const values = {
2667
+ KEEP: canary(),
2668
+ OLD: canary()
2669
+ };
2670
+ for (const [key, value] of Object.entries(values)) canaries[`${place}/${key}`] = value;
2671
+ await admin.api.secrets.set(place, values);
2672
+ const changer = await personaOn(deployment, admin, "changer", { [`${PROJECT$1}-mcp`]: "maintainer" });
2673
+ const clientId = await register(deployment);
2674
+ const answers = [];
2675
+ const call = async (access, tool, args, more = {}, capabilities = {}) => {
2676
+ const { response, body } = await modern(deployment, access, "tools/call", {
2677
+ name: tool,
2678
+ arguments: args,
2679
+ ...more
2680
+ }, tool, capabilities);
2681
+ answers.push(JSON.stringify(body));
2682
+ return {
2683
+ status: response.status,
2684
+ challenge: response.headers.get("www-authenticate") ?? "",
2685
+ result: body.result,
2686
+ error: body.error
2687
+ };
2688
+ };
2689
+ const archived = async (key) => (await admin.api.secrets.history(`${place}/${key}`)).archived;
2690
+ const browse = (await redeem(deployment, clientId, await connect(deployment, changer, clientId))).access_token;
2691
+ const stepUp = await call(browse, "archive_secret", { secret: `${place}/OLD` });
2692
+ expect(stepUp.status === 403 && stepUp.challenge.includes("error=\"insufficient_scope\"") && stepUp.challenge.includes("scope=\"browse write\""), `archive_secret with Browse answered ${stepUp.status}, not a step-up to Write`, stepUp.challenge);
2693
+ expect(!await archived("OLD"), "archive_secret with Browse archived the secret");
2694
+ const write = (await redeem(deployment, clientId, await connect(deployment, changer, clientId, "browse write"))).access_token;
2695
+ const linked = await call(write, "archive_secret", { secret: `${place}/OLD` });
2696
+ const approval = linked.result?.structuredContent?.approval;
2697
+ expect(linked.status === 200 && linked.result?.structuredContent?.status === "pending" && approval?.url === `${deployment.origin}/approvals/${approval?.id}`, "a change without URL elicitation was not answered with its approval link", linked.result);
2698
+ expect(linked.result?.content?.[0]?.text?.includes(approval.url) === true, "the link is not in the text the model reads", linked.result);
2699
+ expect(!await archived("OLD"), "a change was made before its approval");
2700
+ const theirs = await people.reader.api.approvals.get(approval.id).then(() => null, (error) => error);
2701
+ expect(theirs instanceof CoffreError && theirs.status === 403, "another person opened someone else's approval", theirs);
2702
+ const page = await changer.browser.fetch(`/approvals/${approval.id}`);
2703
+ expect(page.status === 200, `the approval page answered ${page.status}`);
2704
+ const shown = (await changer.api.approvals.get(approval.id)).approval;
2705
+ expect(shown.status === "pending" && shown.summary === `archive ${place}/OLD` && shown.client.name === NAME, "the approval page does not show the change asked for", shown);
2706
+ const forgedDigest = await changer.api.approvals.decide(approval.id, {
2707
+ approve: true,
2708
+ digest: "0".repeat(64)
2709
+ }).then(() => null, (error) => error);
2710
+ expect(forgedDigest instanceof CoffreError && forgedDigest.status === 409, "a decision on a change the page did not show was taken", forgedDigest);
2711
+ const forgedSite = await changer.browser.fetch(`/api/approvals/${approval.id}`, {
2712
+ method: "POST",
2713
+ headers: {
2714
+ origin: "https://attacker.example",
2715
+ "sec-fetch-site": "cross-site",
2716
+ "content-type": "application/json"
2717
+ },
2718
+ body: JSON.stringify({
2719
+ approve: true,
2720
+ digest: shown.digest
2721
+ })
2722
+ });
2723
+ expect(forgedSite.status === 403, `another site's approval answered ${forgedSite.status}, not 403`);
2724
+ expect(!await archived("OLD"), "a refused decision changed something");
2725
+ const decided = await changer.api.approvals.decide(approval.id, {
2726
+ approve: true,
2727
+ digest: shown.digest
2728
+ });
2729
+ expect(decided.status === "approved" && await archived("OLD"), "Approve did not make the change", decided);
2730
+ const again = await changer.api.approvals.decide(approval.id, {
2731
+ approve: true,
2732
+ digest: shown.digest
2733
+ }).then(() => null, (error) => error);
2734
+ expect(again instanceof CoffreError && again.status === 409, "an approval was decided twice", again);
2735
+ const reported = await call(write, "archive_secret", { secret: `${place}/OLD` });
2736
+ expect(reported.result?.structuredContent?.status === "approved" && reported.result.isError !== true, "calling again does not report the approved change", reported.result);
2737
+ const elicits = { elicitation: { url: {} } };
2738
+ const asked = await call(write, "rename_secret", {
2739
+ secret: `${place}/KEEP`,
2740
+ newKey: "KEPT"
2741
+ }, {}, elicits);
2742
+ const request = asked.result?.inputRequests?.approve;
2743
+ expect(asked.result?.resultType === "input_required" && request?.method === "elicitation/create" && request.params.mode === "url" && typeof asked.result.requestState === "string", "a change with URL elicitation was not answered with an input_required URL elicitation", asked.result);
2744
+ const id = request.params.url.split("/").at(-1);
2745
+ const replayed = await call(write, "rename_secret", {
2746
+ secret: `${place}/KEEP`,
2747
+ newKey: "OTHER"
2748
+ }, {
2749
+ requestState: asked.result.requestState,
2750
+ inputResponses: { approve: { action: "accept" } }
2751
+ }, elicits);
2752
+ expect(replayed.error?.code === -32602, "a requestState was accepted for another call", replayed);
2753
+ const renamedEarly = await admin.api.secrets.list(place);
2754
+ expect(renamedEarly.keys.some((key) => key.key === "KEEP"), "a change was made before its approval", renamedEarly.keys);
2755
+ const second = (await changer.api.approvals.get(id)).approval;
2756
+ expect((await changer.api.approvals.decide(id, {
2757
+ approve: true,
2758
+ digest: second.digest
2759
+ })).status === "approved", "the second approval was not made");
2760
+ const retried = await call(write, "rename_secret", {
2761
+ secret: `${place}/KEEP`,
2762
+ newKey: "KEPT"
2763
+ }, {
2764
+ requestState: asked.result.requestState,
2765
+ inputResponses: { approve: { action: "accept" } }
2766
+ }, elicits);
2767
+ expect(retried.result?.structuredContent?.status === "approved", "the retry does not report the approved change", retried.result);
2768
+ const typed = canary();
2769
+ canaries[`${place}/TYPED`] = typed;
2770
+ const valueId = (await call(write, "request_secret_value", { secret: `${place}/TYPED` })).result.structuredContent.approval.id;
2771
+ const valuePage = (await changer.api.approvals.get(valueId)).approval;
2772
+ expect(valuePage.asks?.value !== void 0, "the approval page does not ask for the value");
2773
+ await changer.api.approvals.decide(valueId, {
2774
+ approve: true,
2775
+ digest: valuePage.digest,
2776
+ value: typed
2777
+ });
2778
+ expect((await admin.api.secrets.reveal(`${place}/TYPED`)).values.TYPED === typed, "the value typed on the page was not written");
2779
+ await call(write, "request_secret_value", { secret: `${place}/TYPED` });
2780
+ const generatedId = (await call(write, "generate_secret_value", {
2781
+ secret: `${place}/GENERATED`,
2782
+ alphabet: "hex"
2783
+ })).result.structuredContent.approval.id;
2784
+ const generatedPage = (await changer.api.approvals.get(generatedId)).approval;
2785
+ const generated = await changer.api.approvals.decide(generatedId, {
2786
+ approve: true,
2787
+ digest: generatedPage.digest
2788
+ });
2789
+ const made = (await admin.api.secrets.reveal(`${place}/GENERATED`)).values.GENERATED ?? "";
2790
+ canaries[`${place}/GENERATED`] = made;
2791
+ expect(/^[0-9a-f]{64}$/.test(made) && generated.shown.length === 0 && !JSON.stringify(generated).includes(made), "generate_secret_value did not make a 64-character hex value, shown to no one");
2792
+ await call(write, "generate_secret_value", {
2793
+ secret: `${place}/GENERATED`,
2794
+ alphabet: "hex"
2795
+ });
2796
+ const leaked = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
2797
+ expect(leaked.length === 0, "a change tool answered with a secret value", leaked);
2798
+ const { entries } = await admin.api.audit.list({
2799
+ actor: changer.member,
2800
+ limit: 500
2801
+ });
2802
+ const viaApproval = (action) => entries.filter((entry) => entry.action === action && entry.decision === "allow" && typeof entry.metadata.via?.approvalId === "string");
2803
+ const once = {
2804
+ archive: viaApproval("secret.archive").length,
2805
+ rename: viaApproval("secret.rename").length,
2806
+ write: viaApproval("secret.write").length
2807
+ };
2808
+ expect(once.archive === 1 && once.rename === 1 && once.write === 2, "the changes are not each made once, via the client and its approval", once);
2809
+ const decisions = entries.filter((entry) => entry.action === "mcp.approve").map((entry) => `${entry.decision} ${entry.reason ?? ""}`.trim()).sort();
2810
+ expect(JSON.stringify(decisions) === JSON.stringify([
2811
+ "allow",
2812
+ "allow",
2813
+ "allow",
2814
+ "allow",
2815
+ "deny approved",
2816
+ "deny changed"
2817
+ ]), "the decisions, and the two refused, are not in the log", decisions);
2818
+ return `Browse stepped up to Write; with Write, the link without URL elicitation and an elicitation with it; nothing changed until ${changer.email} approved on coffre's page, another person and another site refused, a replayed requestState refused; each change made once, via the client and its approval; a value typed on the page only, and one coffre made reaching no one`;
2819
+ }
2820
+ /**
2821
+ * Values (design section 14, checks 2 and 4): Browse cannot read one, Read
2822
+ * values reads what the person may, a value shown on coffre's page goes to
2823
+ * the person and not the client, and one a client asks coffre to make
2824
+ * reaches no one.
2825
+ */
2826
+ async function mcpValues(deployment, people, canaries) {
2827
+ const { reader } = people;
2828
+ const clientId = await register(deployment);
2829
+ const answers = [];
2830
+ const call = async (access, tool, args) => {
2831
+ const { response, body } = await modern(deployment, access, "tools/call", {
2832
+ name: tool,
2833
+ arguments: args
2834
+ }, tool);
2835
+ answers.push(JSON.stringify(body));
2836
+ return {
2837
+ status: response.status,
2838
+ challenge: response.headers.get("www-authenticate") ?? "",
2839
+ result: body.result
2840
+ };
2841
+ };
2842
+ const dev = valuesIn(canaries, DEV);
2843
+ const browse = (await redeem(deployment, clientId, await connect(deployment, reader, clientId))).access_token;
2844
+ const stepUp = await call(browse, "read_secret_values", { path: DEV });
2845
+ expect(stepUp.status === 403 && stepUp.challenge.includes("scope=\"browse read-values\""), `read_secret_values with Browse answered ${stepUp.status}, not a step-up`, stepUp.challenge);
2846
+ const show = await call(browse, "show_secret_value", { secret: `${DEV}/API_KEY` });
2847
+ const id = show.result?.structuredContent?.approval?.id;
2848
+ expect(show.result?.structuredContent?.status === "pending" && id !== void 0, "show_secret_value did not open an approval", show.result);
2849
+ const page = (await reader.api.approvals.get(id)).approval;
2850
+ expect(page.kind === "reveal", "the approval page does not say it shows a value", page);
2851
+ expect((await reader.api.approvals.decide(id, {
2852
+ approve: true,
2853
+ digest: page.digest
2854
+ })).shown.some((line) => line.value === dev.API_KEY), "Reveal did not show the person the value");
2855
+ const told = await call(browse, "show_secret_value", { secret: `${DEV}/API_KEY` });
2856
+ expect(told.result?.structuredContent?.status === "approved", "show_secret_value does not report the value as shown", told.result);
2857
+ const browseLeaks = Object.entries(canaries).filter(([, value]) => answers.some((answer) => answer.includes(value))).map(([path]) => path);
2858
+ expect(browseLeaks.length === 0, "a Browse answer held a value", browseLeaks);
2859
+ const reading = (await redeem(deployment, clientId, await connect(deployment, reader, clientId, "browse read-values"))).access_token;
2860
+ const read = await call(reading, "read_secret_values", { path: DEV });
2861
+ expect(JSON.stringify(read.result?.structuredContent?.values) === JSON.stringify(dev), `read_secret_values on ${DEV} did not answer its values`);
2862
+ expect(read.result?.content?.[0]?.text?.startsWith("These values are now part of this conversation") === true, "read_secret_values does not warn first", read.result?.content);
2863
+ const prod = await call(reading, "read_secret_values", { path: PROD });
2864
+ expect(prod.result?.isError === true && !JSON.stringify(prod.result).includes(canaries[`${PROD}/API_KEY`]), `the reader read ${PROD} through MCP`, prod.result);
2865
+ return `Browse stepped up for values and showed ${DEV}/API_KEY to ${reader.email} on coffre's page only; Read values answered ${DEV}'s values, warning first, and refused ${PROD}`;
2866
+ }
2867
+ //#endregion
1879
2868
  //#region src/checks/readiness.ts
1880
2869
  async function red(deployment) {
1881
2870
  await until("readiness red", async () => (await fetch(`${deployment.origin}/readyz`)).status === 503, 10);
@@ -1962,11 +2951,19 @@ function getCalls({ places, secrets, members, services }) {
1962
2951
  "GET /me": [{ params: {} }],
1963
2952
  "GET /projects": [{ params: {} }],
1964
2953
  "GET /secrets/:project/:environment": places.map((params) => ({ params })),
2954
+ "GET /projects/:project/:environment/missing": places.map((params) => ({ params })),
1965
2955
  "GET /secrets/:project/:environment/:key/versions": secrets.map((params) => ({ params })),
1966
2956
  "GET /members": [{ params: {} }, ...first === void 0 ? [] : [{
1967
2957
  params: {},
1968
2958
  input: { path: `${first.project}/${first.environment}` }
1969
2959
  }]],
2960
+ "GET /references": [...first === void 0 ? [] : [{
2961
+ params: {},
2962
+ input: { path: first.project }
2963
+ }, {
2964
+ params: {},
2965
+ input: { path: `${first.project}/${first.environment}` }
2966
+ }]],
1970
2967
  "GET /members/:member": members.map((member) => ({ params: { member } })),
1971
2968
  "GET /members/:member/tokens": services.map((member) => ({ params: { member } })),
1972
2969
  "GET /members/:member/bindings": services.map((member) => ({ params: { member } })),
@@ -1977,6 +2974,15 @@ function getCalls({ places, secrets, members, services }) {
1977
2974
  "GET /sessions": [{ params: {} }],
1978
2975
  "GET /identities": [{ params: {} }],
1979
2976
  "GET /device-logins/:code": [{ params: { code: "BCDF-GHJK" } }],
2977
+ "GET /oauth/authorizations": [{
2978
+ params: {},
2979
+ input: {
2980
+ client_id: "00000000-0000-4000-8000-000000000000",
2981
+ redirect_uri: "https://conformance.invalid/callback"
2982
+ }
2983
+ }],
2984
+ "GET /approvals/:id": [{ params: { id: "00000000-0000-4000-8000-000000000000" } }],
2985
+ "GET /apps": [{ params: {} }],
1980
2986
  "GET /audit": [{
1981
2987
  params: {},
1982
2988
  input: { limit: 500 }
@@ -2031,8 +3037,8 @@ function calls(people) {
2031
3037
  people.reader,
2032
3038
  people.leaver,
2033
3039
  people.bulk
2034
- ].map((person) => person.member), SERVICE],
2035
- services: [SERVICE]
3040
+ ].map((person) => person.member), SERVICE$2],
3041
+ services: [SERVICE$2]
2036
3042
  });
2037
3043
  }
2038
3044
  function pages(people) {
@@ -2051,17 +3057,27 @@ function pages(people) {
2051
3057
  "/audit",
2052
3058
  "/settings",
2053
3059
  "/auth/device",
3060
+ "/oauth/authorize",
2054
3061
  "/projects",
2055
- `/projects/${PROJECT}`,
3062
+ ...[
3063
+ "",
3064
+ "/users",
3065
+ "/service-accounts",
3066
+ "/settings"
3067
+ ].map((tab) => `/projects/${PROJECT$1}${tab}`),
2056
3068
  ...[
2057
3069
  DEV,
2058
3070
  PROD,
2059
3071
  BULK
2060
3072
  ].map((path) => `/projects/${path}`),
2061
3073
  "/users",
2062
- ...users.map((person) => `/users/${encodeURIComponent(person.email)}`),
2063
- "/tokens",
2064
- `/tokens/${SERVICE.slice(6)}`
3074
+ ...users.flatMap((person) => ["", "/activity"].map((tab) => `/users/${encodeURIComponent(person.email)}${tab}`)),
3075
+ "/service-accounts",
3076
+ ...[
3077
+ "",
3078
+ "/access",
3079
+ "/activity"
3080
+ ].map((tab) => `/service-accounts/${SERVICE$2.slice(6)}${tab}`)
2065
3081
  ];
2066
3082
  }
2067
3083
  async function canaryScan(deployment, people, canaries) {
@@ -2339,7 +3355,7 @@ async function verifyInterrupted(cli, admin) {
2339
3355
  * else changed; the runs' reads are in the audit log.
2340
3356
  */
2341
3357
  async function verifyLeftovers(cli, admin, setups, before, kept) {
2342
- expect(setups[0].includes(`the service ${PROBE.service}`), "the first run did not make its service", setups[0]);
3358
+ expect(setups[0].includes(`the service account ${PROBE.service.replace(/^token:/, "service:")}`), "the first run did not make its service account", setups[0]);
2343
3359
  expect(setups.slice(1).every((line) => line.startsWith("all found")), "a later run made something again", setups);
2344
3360
  const { tokens } = await admin.api.tokens.list(PROBE.service);
2345
3361
  expect(tokens.length === 0, `${PROBE.service} still holds ${tokens.length} credential(s)`, tokens);
@@ -2456,12 +3472,13 @@ async function manageByCli(cli) {
2456
3472
  "ci",
2457
3473
  "--service"
2458
3474
  ], void 0, 1);
2459
- expect(refused.includes("admit them first, `coffre admit conformance-deploy --service`"), "grant to a service not yet admitted did not say to admit it", refused);
3475
+ expect(refused.includes("admit them first, `coffre admit service:conformance-deploy`"), "grant to a service not yet admitted did not say to admit it", refused);
2460
3476
  const admitted = await coffre([
2461
3477
  "admit",
2462
3478
  "conformance-deploy",
2463
3479
  "--service"
2464
3480
  ]);
3481
+ expect(admitted.includes("admitted service:conformance-deploy") && !admitted.includes("token:"), "admit --service did not name the service account as service:<name>", admitted);
2465
3482
  expect(admitted.includes("next: coffre grant <project> conformance-deploy"), "admit --service did not say what comes next", admitted);
2466
3483
  await coffre([
2467
3484
  "grant",
@@ -2517,7 +3534,7 @@ async function manageByCli(cli) {
2517
3534
  "--apply"
2518
3535
  ]);
2519
3536
  const gone = await service(["get", "conformance-cli/ci/API_TOKEN"], void 0, 1);
2520
- expect(/does not know this service token/.test(gone), "a revoked token was not refused plainly", gone);
3537
+ expect(/does not know this bearer token/.test(gone), "a revoked token was not refused plainly", gone);
2521
3538
  await coffre([
2522
3539
  "revoke",
2523
3540
  "conformance-cli",
@@ -2549,6 +3566,8 @@ async function manageByCli(cli) {
2549
3566
  }
2550
3567
  //#endregion
2551
3568
  //#region src/chrome.ts
3569
+ /** How long one DevTools call may take: a Chrome stalled on a loaded host fails the call rather than hang whoever waits on it. */
3570
+ const ANSWER_MS = 6e4;
2552
3571
  const NAMES = [
2553
3572
  "google-chrome",
2554
3573
  "google-chrome-stable",
@@ -2636,9 +3655,17 @@ var Chrome = class Chrome {
2636
3655
  #send(method, params = {}, sessionId) {
2637
3656
  const id = ++this.#next;
2638
3657
  return new Promise((resolve, reject) => {
3658
+ const timer = setTimeout(() => {
3659
+ this.#pending.delete(id);
3660
+ reject(/* @__PURE__ */ new Error(`Chrome did not answer ${method} within ${ANSWER_MS / 1e3} s`));
3661
+ }, ANSWER_MS);
3662
+ const settled = (then) => (value) => {
3663
+ clearTimeout(timer);
3664
+ then(value);
3665
+ };
2639
3666
  this.#pending.set(id, {
2640
- resolve,
2641
- reject
3667
+ resolve: settled(resolve),
3668
+ reject: settled(reject)
2642
3669
  });
2643
3670
  this.#socket.send(JSON.stringify({
2644
3671
  id,
@@ -2651,9 +3678,11 @@ var Chrome = class Chrome {
2651
3678
  /**
2652
3679
  * `url` in a tab of its own, with `cookies` for its origin: the heading it
2653
3680
  * shows once its scripts have run and settled, and every uncaught error,
2654
- * console error and failed load along the way.
3681
+ * console error and failed load along the way. `then`, a script run once
3682
+ * the page settles, does what a person would next, such as open a dialog,
3683
+ * whose text is read with the rest.
2655
3684
  */
2656
- async load(url, cookies, settle = 2e3) {
3685
+ async load(url, cookies, settle = 2e3, then) {
2657
3686
  const { targetId } = await this.#send("Target.createTarget", { url: "about:blank" });
2658
3687
  const { sessionId } = await this.#send("Target.attachToTarget", {
2659
3688
  targetId,
@@ -2692,12 +3721,26 @@ var Chrome = class Chrome {
2692
3721
  await this.#send("Page.navigate", { url }, sessionId);
2693
3722
  await Promise.race([load, new Promise((resolve) => setTimeout(resolve, 3e4))]);
2694
3723
  await new Promise((resolve) => setTimeout(resolve, settle));
3724
+ if (then !== void 0) {
3725
+ await this.#send("Runtime.evaluate", {
3726
+ expression: then,
3727
+ awaitPromise: true
3728
+ }, sessionId);
3729
+ await new Promise((resolve) => setTimeout(resolve, settle));
3730
+ }
2695
3731
  const { result } = await this.#send("Runtime.evaluate", {
2696
- expression: "document.querySelector('h1')?.textContent?.trim() || null",
3732
+ expression: `({
3733
+ heading: document.querySelector('h1')?.textContent?.trim() || null,
3734
+ tab: document.querySelector('.tabs [aria-current=page]')?.textContent?.trim() || null,
3735
+ cards: [...document.querySelectorAll('h2.card-title')].map((title) => title.textContent.trim()),
3736
+ text: document.body.innerText,
3737
+ href: location.href,
3738
+ dialog: document.querySelector('[role=alertdialog], [role=dialog]')?.innerText ?? null,
3739
+ })`,
2697
3740
  returnByValue: true
2698
3741
  }, sessionId);
2699
3742
  return {
2700
- heading: result.value,
3743
+ ...result.value,
2701
3744
  errors
2702
3745
  };
2703
3746
  } finally {
@@ -2720,26 +3763,230 @@ var Chrome = class Chrome {
2720
3763
  };
2721
3764
  //#endregion
2722
3765
  //#region src/checks/pages.ts
2723
- /** Each page, and the heading it shows. */
3766
+ /** Each page, the heading it shows, and the tab it is, for a page with tabs. */
2724
3767
  const PAGES = [
2725
- ["/projects", "Projects"],
2726
- [`/projects/${PROJECT}`, "Conformance"],
2727
- ["/audit", "Audit"]
3768
+ [
3769
+ "/projects",
3770
+ "Projects",
3771
+ null
3772
+ ],
3773
+ [
3774
+ `/projects/${PROJECT$1}`,
3775
+ "Conformance",
3776
+ "Environments"
3777
+ ],
3778
+ [
3779
+ `/projects/${PROJECT$1}/users`,
3780
+ "Conformance",
3781
+ "Users"
3782
+ ],
3783
+ [
3784
+ `/projects/${PROJECT$1}/service-accounts`,
3785
+ "Conformance",
3786
+ "Service accounts"
3787
+ ],
3788
+ [
3789
+ `/projects/${PROJECT$1}/settings`,
3790
+ "Conformance",
3791
+ "Settings"
3792
+ ],
3793
+ [
3794
+ "/audit",
3795
+ "Audit",
3796
+ null
3797
+ ]
2728
3798
  ];
2729
- async function pagesInBrowser(deployment, admin, browser) {
3799
+ /**
3800
+ * A project's tabs walked as a person would: Users, then Settings, by their
3801
+ * links, then back twice and forward once, which ends on Users.
3802
+ */
3803
+ const WALK_TABS = `(async () => {
3804
+ const wait = () => new Promise((resolve) => setTimeout(resolve, 1000));
3805
+ const open = (label) => [...document.querySelectorAll('.tabs a')].find((link) => link.textContent.trim() === label)?.click();
3806
+ open('Users');
3807
+ await wait();
3808
+ open('Settings');
3809
+ await wait();
3810
+ history.back();
3811
+ await wait();
3812
+ history.back();
3813
+ await wait();
3814
+ history.forward();
3815
+ })()`;
3816
+ /**
3817
+ * A menu item's dialog opened as a person would: the menu by its button,
3818
+ * then the item, by its words. Base UI's menu opens on a pointer press, not
3819
+ * a bare click.
3820
+ */
3821
+ const openFromMenu = (menu, item) => `(async () => {
3822
+ const press = { bubbles: true, cancelable: true, pointerType: 'mouse', button: 0 };
3823
+ const trigger = document.querySelector(${JSON.stringify(menu)});
3824
+ for (const [Kind, type] of [[PointerEvent, 'pointerdown'], [MouseEvent, 'mousedown'], [PointerEvent, 'pointerup'], [MouseEvent, 'mouseup'], [MouseEvent, 'click']]) {
3825
+ trigger?.dispatchEvent(new Kind(type, press));
3826
+ }
3827
+ await new Promise((resolve) => setTimeout(resolve, 300));
3828
+ [...document.querySelectorAll('[role=menuitem]')].find((entry) => entry.textContent.includes(${JSON.stringify(item)}))?.click();
3829
+ })()`;
3830
+ /** A service account of the pages' own, whose page shows how it signs in. */
3831
+ const SERVICE = "token:conformance-pages";
3832
+ const CONSENT_CLIENT = "Conformance pages client";
3833
+ /** A registered client's authorization request, as the consent page receives it. */
3834
+ async function consentUrl(deployment) {
3835
+ const redirect = "http://127.0.0.1:33419/callback";
3836
+ const registered = await fetch(`${deployment.origin}/api/oauth/register`, {
3837
+ method: "POST",
3838
+ headers: { "content-type": "application/json" },
3839
+ body: JSON.stringify({
3840
+ client_name: CONSENT_CLIENT,
3841
+ redirect_uris: [redirect]
3842
+ })
3843
+ });
3844
+ const { client_id: clientId } = await registered.json();
3845
+ expect(registered.status === 201 && clientId !== void 0, `registering an MCP client answered ${registered.status}`);
3846
+ const request = new URLSearchParams({
3847
+ client_id: clientId,
3848
+ redirect_uri: redirect,
3849
+ response_type: "code",
3850
+ code_challenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
3851
+ code_challenge_method: "S256",
3852
+ state: "pages",
3853
+ scope: "browse write"
3854
+ });
3855
+ return `${deployment.origin}/oauth/authorize?${request}`;
3856
+ }
3857
+ /** The Chrome to run, the one given or the one found; skips the check when there is none. */
3858
+ function chromeOrSkip(browser) {
2730
3859
  const executable = browser ?? findChrome();
2731
3860
  if (executable === null) throw new Skip("no Chrome or Chromium here: --browser <path> names one");
3861
+ return executable;
3862
+ }
3863
+ async function pagesInBrowser(deployment, admin, browser) {
3864
+ const executable = chromeOrSkip(browser);
3865
+ await admin.api.members.add(SERVICE);
3866
+ const name = SERVICE.slice(6);
3867
+ const account = `/service-accounts/${name}`;
3868
+ const person = `/users/${encodeURIComponent(admin.email)}`;
3869
+ const pages = [
3870
+ ...PAGES,
3871
+ [
3872
+ "/settings",
3873
+ "Settings",
3874
+ null
3875
+ ],
3876
+ [
3877
+ person,
3878
+ admin.email,
3879
+ "Access"
3880
+ ],
3881
+ [
3882
+ `${person}/activity`,
3883
+ admin.email,
3884
+ "Activity"
3885
+ ],
3886
+ [
3887
+ "/service-accounts",
3888
+ "Service accounts",
3889
+ null
3890
+ ],
3891
+ [
3892
+ account,
3893
+ `service:${name}`,
3894
+ "Sign-in"
3895
+ ],
3896
+ [
3897
+ `${account}/activity`,
3898
+ `service:${name}`,
3899
+ "Activity"
3900
+ ]
3901
+ ];
2732
3902
  const chrome = await Chrome.open(executable);
2733
3903
  try {
2734
- for (const [path, heading] of PAGES) {
2735
- const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies());
3904
+ for (const [path, heading, tab] of pages) {
3905
+ const then = path === account ? openFromMenu("button[aria-label^=\"Actions for\"]", "Remove") : void 0;
3906
+ const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies(), void 0, then);
2736
3907
  expect(loaded.errors.length === 0, `${path}, signed in, reported errors in the browser`, loaded.errors.join("\n"));
2737
3908
  expect(loaded.heading?.startsWith(heading), `${path}, signed in, shows ${JSON.stringify(loaded.heading)}, not the heading ${JSON.stringify(heading)}`);
3909
+ expect(loaded.tab === tab, `${path}, signed in, shows the tab ${JSON.stringify(loaded.tab)}, not ${JSON.stringify(tab)}`);
3910
+ if (path.startsWith("/service-accounts")) expect(!/(?<![\w-])token:[A-Za-z0-9]/.test(loaded.text), `${path} shows a service account as token:<name>`, loaded.text);
3911
+ if (path === account) {
3912
+ expect(loaded.cards.filter((title) => title === "Sign in with OIDC" || title === "Bearer tokens").join(" then ") === "Sign in with OIDC then Bearer tokens", `${path} does not show OIDC, then bearer tokens`, loaded.cards);
3913
+ expect(loaded.dialog?.includes("Removing revokes 0 grants, 0 bearer tokens") === true, `${path}: Remove… does not preview what it would revoke`, loaded.dialog);
3914
+ }
3915
+ if (path === "/settings") expect(loaded.cards.includes("Keys"), "/settings does not show what the keys are checked against", loaded.cards);
3916
+ }
3917
+ const project = new URL(`/projects/${PROJECT$1}`, deployment.origin).href;
3918
+ const walked = await chrome.load(project, admin.browser.cookies(), void 0, WALK_TABS);
3919
+ expect(walked.errors.length === 0, `${project}'s tabs reported errors in the browser`, walked.errors.join("\n"));
3920
+ expect(walked.href === `${project}/users` && walked.tab === "Users", `Users, Settings, back, back and forward from ${project} ended on ${walked.href}, the tab ${JSON.stringify(walked.tab)}`);
3921
+ const access = `${account}/access`;
3922
+ await admin.api.access.set(SERVICE, { "*/dev": "viewer" });
3923
+ try {
3924
+ const loaded = await chrome.load(new URL(access, deployment.origin).href, admin.browser.cookies());
3925
+ expect(loaded.errors.length === 0, `${access} reported errors in the browser`, loaded.errors.join("\n"));
3926
+ expect(loaded.tab === "Access", `${access} shows the tab ${JSON.stringify(loaded.tab)}, not "Access"`);
3927
+ for (const shown of ["dev in every project", "Grant on every project"]) expect(loaded.text.includes(shown), `${access}, to an owner, does not show "${shown}"`, loaded.text);
3928
+ } finally {
3929
+ await admin.api.access.set(SERVICE, { "*/dev": null });
2738
3930
  }
3931
+ const consent = await consentUrl(deployment);
3932
+ const loaded = await chrome.load(consent, admin.browser.cookies());
3933
+ expect(loaded.errors.length === 0, "/oauth/authorize reported errors in the browser", loaded.errors.join("\n"));
3934
+ expect(loaded.heading === `Connect ${CONSENT_CLIENT} to coffre?`, `/oauth/authorize shows ${JSON.stringify(loaded.heading)}`);
3935
+ for (const shown of [
3936
+ "Unverified",
3937
+ "localhost",
3938
+ admin.email,
3939
+ "Browse",
3940
+ "Approve",
3941
+ "Deny"
3942
+ ]) expect(loaded.text.includes(shown), `/oauth/authorize does not show "${shown}"`, loaded.text);
2739
3943
  } finally {
2740
3944
  await chrome.close();
2741
3945
  }
2742
- return `${PAGES.map(([path]) => path).join(", ")}, signed in, in Chrome: each rendered, no error from their scripts`;
3946
+ return `${pages.map(([path]) => path).join(", ")}, signed in, in Chrome: each rendered, on its tab, no error from their scripts; a project's tabs by their links, back and forward; a service account shown as service:${name}, OIDC then bearer tokens, its removal previewed; the keys' checks in Settings; its grant on dev in every project with an owner's grant button; the MCP consent page, a registered client shown as unverified`;
3947
+ }
3948
+ /**
3949
+ * A refused sign-in, said once: the page coffre sends the browser back to
3950
+ * shows why, rendered by the server, then takes it out of the address, so a
3951
+ * reload is a clean retry. The refusal is a real one: a member's address
3952
+ * that GitHub now gives another account, which names the provider the
3953
+ * address already signs in with.
3954
+ */
3955
+ async function signinErrorOnce(deployment, admin, browser) {
3956
+ const executable = chromeOrSkip(browser);
3957
+ const email = "recycled@conformance.example";
3958
+ await admin.api.members.add(`user:${email}`);
3959
+ const first = await signIn(deployment, new Browser(deployment.origin), email);
3960
+ expect(first.ok, `${email} was refused before anything changed: ${"error" in first ? first.error : ""}`);
3961
+ deployment.idp.setGitHubUser(email, { id: deployment.idp.gitHubUserFor(email).id + 1e6 });
3962
+ const visitor = new Browser(deployment.origin);
3963
+ const refused = await signIn(deployment, visitor, email);
3964
+ expect(!refused.ok && refused.error === "account_mismatch", "another GitHub account with a member's address was not refused as account_mismatch", refused);
3965
+ const back = new URL(refused.location, deployment.origin);
3966
+ expect(back.searchParams.get("with") === "github", `the refusal does not name the provider the address signs in with: ${refused.location}`);
3967
+ const said = "already signs in with another GitHub account";
3968
+ const html = await visitor.fetch(refused.location);
3969
+ expect(html.status === 200 && (await html.text()).includes(said), `${refused.location}, without scripts, does not say the address ${said}`, html.status);
3970
+ const chrome = await Chrome.open(executable);
3971
+ let clean;
3972
+ try {
3973
+ const shown = await chrome.load(back.href, visitor.cookies());
3974
+ expect(shown.errors.length === 0, `${refused.location} reported errors in the browser`, shown.errors.join("\n"));
3975
+ expect(shown.text.includes(said), `${refused.location} does not say the address ${said}`, shown.text);
3976
+ const after = new URL(shown.href);
3977
+ clean = `${after.pathname}${after.search}`;
3978
+ expect([
3979
+ "error",
3980
+ "with",
3981
+ "via"
3982
+ ].every((name) => !after.searchParams.has(name)), `${refused.location} kept the refusal in its address`, shown.href);
3983
+ const reloaded = await chrome.load(shown.href, visitor.cookies());
3984
+ expect(!reloaded.text.includes(said), `${clean}, reloaded, still says the address ${said}`, reloaded.text);
3985
+ expect(reloaded.heading !== null, `${clean}, reloaded, rendered no heading`);
3986
+ } finally {
3987
+ await chrome.close();
3988
+ }
3989
+ return `${refused.location}: said by the server, once: Chrome then shows ${clean}, and a reload shows no error`;
2743
3990
  }
2744
3991
  /** What only server code carries. */
2745
3992
  const MARKERS = [
@@ -2752,6 +3999,11 @@ const MARKERS = [
2752
3999
  "audit_log",
2753
4000
  "consumed_tokens",
2754
4001
  "device_authorizations",
4002
+ "dismissed_keys",
4003
+ "mcp_approvals",
4004
+ "mcp_connections",
4005
+ "oauth_clients",
4006
+ "secret_references",
2755
4007
  "secret_versions",
2756
4008
  "service_bindings",
2757
4009
  "vault_grants",
@@ -2941,6 +4193,7 @@ function twin(jwt) {
2941
4193
  }
2942
4194
  /** A viewer on dev, and a binding that trusts deploy.yml pushed to main of acme/api. */
2943
4195
  async function trustRun(deployment, admin) {
4196
+ if (!(await admin.api.me()).features.workloads) throw new Skip("this deployment trusts no workloads: its signin({ workloads }) is off");
2944
4197
  await admin.api.members.add(RUNNER);
2945
4198
  await admin.api.access.set(RUNNER, { [DEV]: "viewer" });
2946
4199
  const made = await admin.api.bindings.create(RUNNER, {
@@ -2948,9 +4201,6 @@ async function trustRun(deployment, admin) {
2948
4201
  issuer: deployment.idp.workloads.issuer,
2949
4202
  claims: DEPLOY,
2950
4203
  label: "conformance"
2951
- }).catch((error) => {
2952
- if (error.status === 404) throw new Skip(`this deployment trusts no workloads: ${error.message}`);
2953
- throw error;
2954
4204
  });
2955
4205
  return {
2956
4206
  detail: `${RUNNER}, viewer on ${DEV}, trusts deploy.yml pushed to main of acme/api, from the dev IdP`,
@@ -3156,6 +4406,7 @@ async function conform(deployment, options) {
3156
4406
  admin,
3157
4407
  canaries
3158
4408
  }, ({ admin }) => pagesInBrowser(deployment, admin, options.browser));
4409
+ await report.check("sign-in error, once", { admin }, ({ admin }) => signinErrorOnce(deployment, admin, options.browser));
3159
4410
  const people = await report.check("personas", {
3160
4411
  admin,
3161
4412
  canaries
@@ -3166,6 +4417,14 @@ async function conform(deployment, options) {
3166
4417
  };
3167
4418
  await report.check("members only", { people }, ({ people }) => membersOnly(deployment, people));
3168
4419
  await report.check("grant scoping", all, ({ people, canaries }) => grantScoping(people, canaries));
4420
+ await report.check("folders", all, ({ people, canaries }) => folders(people, canaries));
4421
+ await report.check("forks", all, ({ people, canaries }) => forks(people, canaries));
4422
+ await report.check("references", all, ({ people, canaries }) => references(deployment, people, canaries));
4423
+ await report.check("missing keys", { people }, ({ people }) => missingKeys(people));
4424
+ await report.check("MCP connect", { people }, ({ people }) => mcpConnect(deployment, people));
4425
+ await report.check("MCP browse", all, ({ people, canaries }) => mcpBrowse(deployment, people, canaries));
4426
+ await report.check("MCP changes", all, ({ people, canaries }) => mcpChanges(deployment, people, canaries));
4427
+ await report.check("MCP values", all, ({ people, canaries }) => mcpValues(deployment, people, canaries));
3169
4428
  await report.check("reveals audited", all, ({ people, canaries }) => revealAudited(deployment, people, canaries, "reveal"));
3170
4429
  await report.check("runs audited", all, ({ people, canaries }) => revealAudited(deployment, people, canaries, "run"));
3171
4430
  await report.check("cross-site", all, ({ people, canaries }) => crossSite(people, canaries));
@@ -3210,10 +4469,15 @@ async function conform(deployment, options) {
3210
4469
  }, ({ admin, owner, before, first, second, live }) => verifyLeftovers(owner, admin, [first, second], before, live.canary));
3211
4470
  await report.check("verify keys", { owner }, ({ owner }) => verifyKeys(owner));
3212
4471
  await report.check("manage by CLI", { owner }, ({ owner }) => manageByCli(owner));
4472
+ await report.check("delete by CLI", {
4473
+ owner,
4474
+ admin
4475
+ }, ({ owner, admin }) => deletion(deployment, owner, admin));
3213
4476
  } finally {
3214
4477
  for (const cli of clis) cli.remove();
3215
4478
  }
3216
4479
  await report.check("offboarding", all, ({ people, canaries }) => offboarding(deployment, people, canaries));
4480
+ await report.check("grants on every project", all, ({ people, canaries }) => everyProject(deployment, people, canaries));
3217
4481
  await report.check("bulk limit", { people }, ({ people }) => bulkLimit$1(people, options.bulkLimit));
3218
4482
  const binding = await report.check("trust a run", { admin }, ({ admin }) => trustRun(deployment, admin));
3219
4483
  const credential = await report.check("run signs in", {