@coffre/conformance 0.2.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.
@@ -3,31 +3,192 @@
3
3
  // page receives shows only there: wrangler's keep_names once wrapped the
4
4
  // functions seroval writes into a page in an `__name` that only the Worker
5
5
  // had, and a signed-in page rendered, then went blank.
6
+ import { Browser } from '../browser.ts';
6
7
  import { Chrome, findChrome } from '../chrome.ts';
7
8
  import type { Deployment } from '../harness.ts';
8
9
  import { expect, Skip } from '../report.ts';
9
- import { type Person, PROJECT } from './people.ts';
10
+ import { type Person, PROJECT, signIn } from './people.ts';
10
11
 
11
- /** Each page, and the heading it shows. */
12
- const PAGES = [
13
- ['/projects', 'Projects'],
14
- [`/projects/${PROJECT}`, 'Conformance'],
15
- ['/audit', 'Audit'],
16
- ] as const;
12
+ /** Each page, the heading it shows, and the tab it is, for a page with tabs. */
13
+ const PAGES: [path: string, heading: string, tab: string | null][] = [
14
+ ['/projects', 'Projects', null],
15
+ [`/projects/${PROJECT}`, 'Conformance', 'Environments'],
16
+ [`/projects/${PROJECT}/users`, 'Conformance', 'Users'],
17
+ [`/projects/${PROJECT}/service-accounts`, 'Conformance', 'Service accounts'],
18
+ [`/projects/${PROJECT}/settings`, 'Conformance', 'Settings'],
19
+ ['/audit', 'Audit', null],
20
+ ];
17
21
 
18
- export async function pagesInBrowser(deployment: Deployment, admin: Person, browser: string | null): Promise<string> {
22
+ /**
23
+ * A project's tabs walked as a person would: Users, then Settings, by their
24
+ * links, then back twice and forward once, which ends on Users.
25
+ */
26
+ const WALK_TABS = `(async () => {
27
+ const wait = () => new Promise((resolve) => setTimeout(resolve, 1000));
28
+ const open = (label) => [...document.querySelectorAll('.tabs a')].find((link) => link.textContent.trim() === label)?.click();
29
+ open('Users');
30
+ await wait();
31
+ open('Settings');
32
+ await wait();
33
+ history.back();
34
+ await wait();
35
+ history.back();
36
+ await wait();
37
+ history.forward();
38
+ })()`;
39
+
40
+ /**
41
+ * A menu item's dialog opened as a person would: the menu by its button,
42
+ * then the item, by its words. Base UI's menu opens on a pointer press, not
43
+ * a bare click.
44
+ */
45
+ const openFromMenu = (menu: string, item: string) => `(async () => {
46
+ const press = { bubbles: true, cancelable: true, pointerType: 'mouse', button: 0 };
47
+ const trigger = document.querySelector(${JSON.stringify(menu)});
48
+ for (const [Kind, type] of [[PointerEvent, 'pointerdown'], [MouseEvent, 'mousedown'], [PointerEvent, 'pointerup'], [MouseEvent, 'mouseup'], [MouseEvent, 'click']]) {
49
+ trigger?.dispatchEvent(new Kind(type, press));
50
+ }
51
+ await new Promise((resolve) => setTimeout(resolve, 300));
52
+ [...document.querySelectorAll('[role=menuitem]')].find((entry) => entry.textContent.includes(${JSON.stringify(item)}))?.click();
53
+ })()`;
54
+
55
+ /** A service account of the pages' own, whose page shows how it signs in. */
56
+ const SERVICE = 'token:conformance-pages';
57
+
58
+ const CONSENT_CLIENT = 'Conformance pages client';
59
+
60
+ /** A registered client's authorization request, as the consent page receives it. */
61
+ async function consentUrl(deployment: Deployment): Promise<string> {
62
+ const redirect = 'http://127.0.0.1:33419/callback';
63
+ const registered = await fetch(`${deployment.origin}/api/oauth/register`, {
64
+ method: 'POST',
65
+ headers: { 'content-type': 'application/json' },
66
+ body: JSON.stringify({ client_name: CONSENT_CLIENT, redirect_uris: [redirect] }),
67
+ });
68
+ const { client_id: clientId } = (await registered.json()) as { client_id?: string };
69
+ expect(registered.status === 201 && clientId !== undefined, `registering an MCP client answered ${registered.status}`);
70
+ const request = new URLSearchParams({
71
+ client_id: clientId,
72
+ redirect_uri: redirect,
73
+ response_type: 'code',
74
+ code_challenge: 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM',
75
+ code_challenge_method: 'S256',
76
+ state: 'pages',
77
+ scope: 'browse write',
78
+ });
79
+ return `${deployment.origin}/oauth/authorize?${request}`;
80
+ }
81
+
82
+ /** The Chrome to run, the one given or the one found; skips the check when there is none. */
83
+ function chromeOrSkip(browser: string | null): string {
19
84
  const executable = browser ?? findChrome();
20
85
  if (executable === null) throw new Skip('no Chrome or Chromium here: --browser <path> names one');
86
+ return executable;
87
+ }
88
+
89
+ export async function pagesInBrowser(deployment: Deployment, admin: Person, browser: string | null): Promise<string> {
90
+ const executable = chromeOrSkip(browser);
91
+ await admin.api.members.add(SERVICE);
92
+ const name = SERVICE.slice('token:'.length);
93
+ // A service account is service:<name> to people; the API and the log keep token:<name>.
94
+ const account = `/service-accounts/${name}`;
95
+ const person = `/users/${encodeURIComponent(admin.email)}`;
96
+ const pages = [
97
+ ...PAGES,
98
+ ['/settings', 'Settings', null],
99
+ [person, admin.email, 'Access'],
100
+ [`${person}/activity`, admin.email, 'Activity'],
101
+ ['/service-accounts', 'Service accounts', null],
102
+ [account, `service:${name}`, 'Sign-in'],
103
+ [`${account}/activity`, `service:${name}`, 'Activity'],
104
+ ] as const;
21
105
  const chrome = await Chrome.open(executable);
22
106
  try {
23
- for (const [path, heading] of PAGES) {
24
- const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies());
107
+ for (const [path, heading, tab] of pages) {
108
+ // On the service account's page, its removal is opened, and not confirmed: the dialog says first what it would revoke.
109
+ const then = path === account ? openFromMenu('button[aria-label^="Actions for"]', 'Remove') : undefined;
110
+ const loaded = await chrome.load(new URL(path, deployment.origin).href, admin.browser.cookies(), undefined, then);
25
111
  expect(loaded.errors.length === 0, `${path}, signed in, reported errors in the browser`, loaded.errors.join('\n'));
26
112
  // The heading, then what may follow it in the h1, such as a project's slug.
27
113
  expect(loaded.heading?.startsWith(heading), `${path}, signed in, shows ${JSON.stringify(loaded.heading)}, not the heading ${JSON.stringify(heading)}`);
114
+ expect(loaded.tab === tab, `${path}, signed in, shows the tab ${JSON.stringify(loaded.tab)}, not ${JSON.stringify(tab)}`);
115
+ 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);
116
+ if (path === account) {
117
+ const ways = loaded.cards.filter((title) => title === 'Sign in with OIDC' || title === 'Bearer tokens');
118
+ expect(ways.join(' then ') === 'Sign in with OIDC then Bearer tokens', `${path} does not show OIDC, then bearer tokens`, loaded.cards);
119
+ expect(loaded.dialog?.includes('Removing revokes 0 grants, 0 bearer tokens') === true, `${path}: Remove… does not preview what it would revoke`, loaded.dialog);
120
+ }
121
+ if (path === '/settings') expect(loaded.cards.includes('Keys'), '/settings does not show what the keys are checked against', loaded.cards);
28
122
  }
123
+ // A project's tabs are routes: their links, back and forward move between them in the page.
124
+ const project = new URL(`/projects/${PROJECT}`, deployment.origin).href;
125
+ const walked = await chrome.load(project, admin.browser.cookies(), undefined, WALK_TABS);
126
+ expect(walked.errors.length === 0, `${project}'s tabs reported errors in the browser`, walked.errors.join('\n'));
127
+ 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)}`);
128
+ // Its access on every project, which an owner grants and revokes on its Access tab.
129
+ const access = `${account}/access`;
130
+ await admin.api.access.set(SERVICE, { '*/dev': 'viewer' });
131
+ try {
132
+ const loaded = await chrome.load(new URL(access, deployment.origin).href, admin.browser.cookies());
133
+ expect(loaded.errors.length === 0, `${access} reported errors in the browser`, loaded.errors.join('\n'));
134
+ expect(loaded.tab === 'Access', `${access} shows the tab ${JSON.stringify(loaded.tab)}, not "Access"`);
135
+ for (const shown of ['dev in every project', 'Grant on every project']) {
136
+ expect(loaded.text.includes(shown), `${access}, to an owner, does not show "${shown}"`, loaded.text);
137
+ }
138
+ } finally {
139
+ await admin.api.access.set(SERVICE, { '*/dev': null });
140
+ }
141
+ // The page an MCP client sends a person to: who asks, where the answer goes, and what it may do.
142
+ const consent = await consentUrl(deployment);
143
+ const loaded = await chrome.load(consent, admin.browser.cookies());
144
+ expect(loaded.errors.length === 0, '/oauth/authorize reported errors in the browser', loaded.errors.join('\n'));
145
+ expect(loaded.heading === `Connect ${CONSENT_CLIENT} to coffre?`, `/oauth/authorize shows ${JSON.stringify(loaded.heading)}`);
146
+ for (const shown of ['Unverified', 'localhost', admin.email, 'Browse', 'Approve', 'Deny']) {
147
+ expect(loaded.text.includes(shown), `/oauth/authorize does not show "${shown}"`, loaded.text);
148
+ }
149
+ } finally {
150
+ await chrome.close();
151
+ }
152
+ 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`;
153
+ }
154
+
155
+ /**
156
+ * A refused sign-in, said once: the page coffre sends the browser back to
157
+ * shows why, rendered by the server, then takes it out of the address, so a
158
+ * reload is a clean retry. The refusal is a real one: a member's address
159
+ * that GitHub now gives another account, which names the provider the
160
+ * address already signs in with.
161
+ */
162
+ export async function signinErrorOnce(deployment: Deployment, admin: Person, browser: string | null): Promise<string> {
163
+ const executable = chromeOrSkip(browser);
164
+ const email = 'recycled@conformance.example';
165
+ await admin.api.members.add(`user:${email}`);
166
+ const first = await signIn(deployment, new Browser(deployment.origin), email);
167
+ expect(first.ok, `${email} was refused before anything changed: ${'error' in first ? first.error : ''}`);
168
+ deployment.idp.setGitHubUser(email, { id: deployment.idp.gitHubUserFor(email).id + 1_000_000 });
169
+ const visitor = new Browser(deployment.origin);
170
+ const refused = await signIn(deployment, visitor, email);
171
+ expect(!refused.ok && refused.error === 'account_mismatch', 'another GitHub account with a member\'s address was not refused as account_mismatch', refused);
172
+ const back = new URL(refused.location, deployment.origin);
173
+ expect(back.searchParams.get('with') === 'github', `the refusal does not name the provider the address signs in with: ${refused.location}`);
174
+
175
+ const said = 'already signs in with another GitHub account';
176
+ const html = await visitor.fetch(refused.location);
177
+ expect(html.status === 200 && (await html.text()).includes(said), `${refused.location}, without scripts, does not say the address ${said}`, html.status);
178
+ const chrome = await Chrome.open(executable);
179
+ let clean: string;
180
+ try {
181
+ const shown = await chrome.load(back.href, visitor.cookies());
182
+ expect(shown.errors.length === 0, `${refused.location} reported errors in the browser`, shown.errors.join('\n'));
183
+ expect(shown.text.includes(said), `${refused.location} does not say the address ${said}`, shown.text);
184
+ const after = new URL(shown.href);
185
+ clean = `${after.pathname}${after.search}`;
186
+ expect(['error', 'with', 'via'].every((name) => !after.searchParams.has(name)), `${refused.location} kept the refusal in its address`, shown.href);
187
+ const reloaded = await chrome.load(shown.href, visitor.cookies());
188
+ expect(!reloaded.text.includes(said), `${clean}, reloaded, still says the address ${said}`, reloaded.text);
189
+ expect(reloaded.heading !== null, `${clean}, reloaded, rendered no heading`);
29
190
  } finally {
30
191
  await chrome.close();
31
192
  }
32
- return `${PAGES.map(([path]) => path).join(', ')}, signed in, in Chrome: each rendered, no error from their scripts`;
193
+ return `${refused.location}: said by the server, once: Chrome then shows ${clean}, and a reload shows no error`;
33
194
  }
@@ -49,7 +49,7 @@ export async function signIn(
49
49
  deployment: Deployment,
50
50
  browser: Browser,
51
51
  email: string,
52
- ): Promise<{ ok: true } | { ok: false; error: string }> {
52
+ ): Promise<{ ok: true } | { ok: false; error: string; location: string }> {
53
53
  const leave = await browser.fetch('/auth/signin/github');
54
54
  const authorize = new URL(leave.headers.get('location') ?? '', deployment.origin);
55
55
  expect(
@@ -68,8 +68,9 @@ export async function signIn(
68
68
  );
69
69
  const back = await browser.fetch(callback);
70
70
  expect(back.status === 302 || back.status === 303, `the callback answered ${back.status}`, await back.text());
71
- const error = new URL(back.headers.get('location') ?? '/', deployment.origin).searchParams.get('error');
72
- return error === null ? { ok: true } : { ok: false, error };
71
+ const location = new URL(back.headers.get('location') ?? '/', deployment.origin);
72
+ const error = location.searchParams.get('error');
73
+ return error === null ? { ok: true } : { ok: false, error, location: `${location.pathname}${location.search}` };
73
74
  }
74
75
 
75
76
  export async function signInAdmin(deployment: Deployment) {
@@ -129,17 +130,20 @@ export function valuesIn(canaries: Canaries, environment: string): Record<string
129
130
  );
130
131
  }
131
132
 
133
+ /** A person the admin admits with this access, signed in in a browser of their own. */
134
+ export async function personaOn(deployment: Deployment, admin: Person, name: string, access: Record<string, 'viewer' | 'developer' | 'maintainer'>): Promise<Person> {
135
+ const email = `${name}@conformance.example`;
136
+ const member = `user:${email}`;
137
+ await admin.api.members.add(member);
138
+ await admin.api.access.set(member, access);
139
+ const browser = new Browser(deployment.origin);
140
+ const signed = await signIn(deployment, browser, email);
141
+ expect(signed.ok, `${email} was refused: ${'error' in signed ? signed.error : ''}`);
142
+ return { email, member, browser, api: browser.client() };
143
+ }
144
+
132
145
  export async function personas(deployment: Deployment, admin: Person) {
133
- async function person(name: string, access: Record<string, 'viewer' | 'developer'>): Promise<Person> {
134
- const email = `${name}@conformance.example`;
135
- const member = `user:${email}`;
136
- await admin.api.members.add(member);
137
- await admin.api.access.set(member, access);
138
- const browser = new Browser(deployment.origin);
139
- const signed = await signIn(deployment, browser, email);
140
- expect(signed.ok, `${email} was refused: ${'error' in signed ? signed.error : ''}`);
141
- return { email, member, browser, api: browser.client() };
142
- }
146
+ const person = (name: string, access: Record<string, 'viewer' | 'developer'>) => personaOn(deployment, admin, name, access);
143
147
 
144
148
  const reader = await person('reader', { [DEV]: 'viewer' });
145
149
  const leaver = await person('leaver', { [DEV]: 'developer' });
@@ -68,14 +68,10 @@ function twin(jwt: string): string {
68
68
 
69
69
  /** A viewer on dev, and a binding that trusts deploy.yml pushed to main of acme/api. */
70
70
  export async function trustRun(deployment: Deployment, admin: Person) {
71
+ if (!(await admin.api.me()).features.workloads) throw new Skip("this deployment trusts no workloads: its signin({ workloads }) is off");
71
72
  await admin.api.members.add(RUNNER);
72
73
  await admin.api.access.set(RUNNER, { [DEV]: 'viewer' });
73
- const made = await admin.api.bindings
74
- .create(RUNNER, { profile: 'github', issuer: deployment.idp.workloads.issuer, claims: DEPLOY, label: 'conformance' })
75
- .catch((error: { status?: number; message?: string }) => {
76
- if (error.status === 404) throw new Skip(`this deployment trusts no workloads: ${error.message}`);
77
- throw error;
78
- });
74
+ const made = await admin.api.bindings.create(RUNNER, { profile: 'github', issuer: deployment.idp.workloads.issuer, claims: DEPLOY, label: 'conformance' });
79
75
  return { detail: `${RUNNER}, viewer on ${DEV}, trusts deploy.yml pushed to main of acme/api, from the dev IdP`, value: made.binding.id };
80
76
  }
81
77
 
@@ -149,28 +145,30 @@ export async function runsRefused(deployment: Deployment, admin: Person): Promis
149
145
  }
150
146
 
151
147
  /**
152
- * The CLI, as a CI job runs it: on GitHub Actions, with the runner's
153
- * token endpoint and nothing else; elsewhere, with the token in
154
- * COFFRE_ID_TOKEN. It keeps the credential in memory, and prints neither.
148
+ * The CLI, as a CI job runs it, as a service by its ID token: on GitHub
149
+ * Actions, `--service` and the runner's token endpoint, nothing else and
150
+ * nothing kept; elsewhere, the token piped to `coffre login --service
151
+ * --id-token`, whose credential the next command uses. No token printed.
155
152
  */
156
153
  export async function cliSignsIn(deployment: Deployment, canaries: Canaries): Promise<string> {
157
154
  const issuer = deployment.idp.workloads;
158
155
  const cli = new Cli(deployment.origin);
159
156
  try {
160
- const base = { COFFRE_API_URL: deployment.origin, COFFRE_SERVICE: RUNNER };
161
- const given = await mint(deployment);
162
- const runs = {
163
- 'on GitHub Actions': { ...base, ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl, ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken },
164
- 'with COFFRE_ID_TOKEN': { ...base, COFFRE_ID_TOKEN: given },
165
- };
166
- for (const [where, env] of Object.entries(runs)) {
167
- const run = await cli.run(['get', `${DEV}/API_KEY`], env);
157
+ const read = async (where: string, args: string[], env: Record<string, string>, secrets: string[]) => {
158
+ const run = await cli.run([...args, 'get', `${DEV}/API_KEY`], env);
168
159
  expect(run.code === 0, `coffre get ${where} exited ${run.code}`, run.output);
169
160
  expect(run.output.trim() === canaries[`${DEV}/API_KEY`], `coffre get ${where} did not print the value`);
170
- expect(!run.output.includes(given) && !run.output.includes(issuer.requestToken) && !/coffre_svc_/.test(run.output), `coffre get ${where} printed a token`);
171
- }
172
- expect(!existsSync(join(cli.home, '.coffre', 'credentials.json')), 'the CLI kept a credential on disk');
173
- return `\`coffre get\` as ${RUNNER}, on GitHub Actions and with COFFRE_ID_TOKEN; no token printed, nothing written`;
161
+ expect(!secrets.some((secret) => run.output.includes(secret)) && !/coffre_svc_/.test(run.output), `coffre get ${where} printed a token`);
162
+ };
163
+ await read('on GitHub Actions', ['--url', deployment.origin, '--service', RUNNER], { ACTIONS_ID_TOKEN_REQUEST_URL: issuer.requestUrl, ACTIONS_ID_TOKEN_REQUEST_TOKEN: issuer.requestToken }, [issuer.requestToken]);
164
+ expect(!existsSync(join(cli.home, '.coffre', 'credentials.json')), 'the CLI kept a credential on disk, for one command');
165
+
166
+ const given = await mint(deployment);
167
+ const login = await cli.run(['login', deployment.origin, '--service', RUNNER, '--id-token'], {}, `${given}\n`);
168
+ expect(login.code === 0, `coffre login --service --id-token exited ${login.code}`, login.output);
169
+ expect(!login.output.includes(given) && !/coffre_svc_/.test(login.output), 'coffre login --service printed a token');
170
+ await read('after coffre login --service --id-token', [], {}, [given]);
171
+ return `\`coffre --service ${RUNNER} get\` on GitHub Actions, nothing kept; \`coffre login --service --id-token\` with the token piped in, then \`coffre get\`; no token printed`;
174
172
  } finally {
175
173
  cli.remove();
176
174
  }
package/src/chrome.ts CHANGED
@@ -8,7 +8,23 @@ import { homedir, tmpdir } from 'node:os';
8
8
  import { delimiter, join } from 'node:path';
9
9
 
10
10
  /** What a page did, loaded: the heading it shows, and every error its scripts and console reported. */
11
- export type Loaded = { heading: string | null; errors: string[] };
11
+ export type Loaded = {
12
+ heading: string | null;
13
+ /** The tab the page shows, for a page with tabs. */
14
+ tab: string | null;
15
+ /** The titles of the page's cards, in order. */
16
+ cards: string[];
17
+ /** What a person reads on it. */
18
+ text: string;
19
+ /** The address it ends at, once its scripts have run: a notice read once is taken out of it. */
20
+ href: string;
21
+ /** The text of the dialog open at the end, as after `then` opened one; null for none. */
22
+ dialog: string | null;
23
+ errors: string[];
24
+ };
25
+
26
+ /** How long one DevTools call may take: a Chrome stalled on a loaded host fails the call rather than hang whoever waits on it. */
27
+ const ANSWER_MS = 60_000;
12
28
 
13
29
  const NAMES = ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser', 'chrome'];
14
30
  const MAC = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium'];
@@ -107,7 +123,15 @@ export class Chrome {
107
123
  #send(method: string, params: Record<string, unknown> = {}, sessionId?: string): Promise<Record<string, unknown>> {
108
124
  const id = ++this.#next;
109
125
  return new Promise((resolve, reject) => {
110
- this.#pending.set(id, { resolve, reject });
126
+ const timer = setTimeout(() => {
127
+ this.#pending.delete(id);
128
+ reject(new Error(`Chrome did not answer ${method} within ${ANSWER_MS / 1000} s`));
129
+ }, ANSWER_MS);
130
+ const settled = <T>(then: (value: T) => void) => (value: T) => {
131
+ clearTimeout(timer);
132
+ then(value);
133
+ };
134
+ this.#pending.set(id, { resolve: settled(resolve), reject: settled(reject) });
111
135
  this.#socket.send(JSON.stringify({ id, method, params, sessionId }));
112
136
  });
113
137
  }
@@ -115,9 +139,11 @@ export class Chrome {
115
139
  /**
116
140
  * `url` in a tab of its own, with `cookies` for its origin: the heading it
117
141
  * shows once its scripts have run and settled, and every uncaught error,
118
- * console error and failed load along the way.
142
+ * console error and failed load along the way. `then`, a script run once
143
+ * the page settles, does what a person would next, such as open a dialog,
144
+ * whose text is read with the rest.
119
145
  */
120
- async load(url: string, cookies: [string, string][], settle = 2_000): Promise<Loaded> {
146
+ async load(url: string, cookies: [string, string][], settle = 2_000, then?: string): Promise<Loaded> {
121
147
  const { targetId } = (await this.#send('Target.createTarget', { url: 'about:blank' })) as { targetId: string };
122
148
  const { sessionId } = (await this.#send('Target.attachToTarget', { targetId, flatten: true })) as { sessionId: string };
123
149
  const errors: string[] = [];
@@ -147,12 +173,24 @@ export class Chrome {
147
173
  await Promise.race([load, new Promise((resolve) => setTimeout(resolve, 30_000))]);
148
174
  // What streams in after the load, and hydration, have their time: the page may render, then fail.
149
175
  await new Promise((resolve) => setTimeout(resolve, settle));
150
- const { result } = (await this.#send(
151
- 'Runtime.evaluate',
152
- { expression: "document.querySelector('h1')?.textContent?.trim() || null", returnByValue: true },
153
- sessionId,
154
- )) as { result: { value: string | null } };
155
- return { heading: result.value, errors };
176
+ if (then !== undefined) {
177
+ await this.#send('Runtime.evaluate', { expression: then, awaitPromise: true }, sessionId);
178
+ // What it asked of the server has its time to come back.
179
+ await new Promise((resolve) => setTimeout(resolve, settle));
180
+ }
181
+ // The heading, the tab shown, the cards' titles in order, all the text a person reads, and where the page ended.
182
+ const expression = `({
183
+ heading: document.querySelector('h1')?.textContent?.trim() || null,
184
+ tab: document.querySelector('.tabs [aria-current=page]')?.textContent?.trim() || null,
185
+ cards: [...document.querySelectorAll('h2.card-title')].map((title) => title.textContent.trim()),
186
+ text: document.body.innerText,
187
+ href: location.href,
188
+ dialog: document.querySelector('[role=alertdialog], [role=dialog]')?.innerText ?? null,
189
+ })`;
190
+ const { result } = (await this.#send('Runtime.evaluate', { expression, returnByValue: true }, sessionId)) as {
191
+ result: { value: { heading: string | null; tab: string | null; cards: string[]; text: string; href: string; dialog: string | null } };
192
+ };
193
+ return { ...result.value, errors };
156
194
  } finally {
157
195
  this.#listeners.delete(listener);
158
196
  await this.#send('Target.closeTarget', { targetId }).catch(() => {});
package/src/draining.ts CHANGED
@@ -11,9 +11,10 @@ import { join, resolve } from 'node:path';
11
11
  * The built app as `wrangler dev` can run it: its own build, behind an entry
12
12
  * that, once the app has answered, reads whatever the request still sends
13
13
  * before passing the answer on. Locally, and only there, a Worker built
14
- * unbundled with static assets fails every request after one whose body it
15
- * left unread, which every refusal does, and reading it later, after the
16
- * answer, is too late; deployed, Cloudflare discards such a body, as
14
+ * unbundled with static assets may fail the request after one whose body it
15
+ * left unread, which every refusal does: wrangler retries a GET, not a POST
16
+ * (cloudflare/workers-sdk#15203). Reading it later, after the answer, is too
17
+ * late; deployed, Cloudflare discards such a body, as
17
18
  * `vite dev` and `vite preview` do. The app itself must never wait so on what
18
19
  * a caller sends; this harness sends only bodies that end. The entry and its
19
20
  * config are written beside the build, which the next `vite build`
package/src/harness.ts CHANGED
@@ -110,14 +110,18 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
110
110
  const logs = () => output(4000);
111
111
  const alive = () => !children.some((entry) => entry.daemon && entry.exited);
112
112
 
113
- function start(name: string, command: string, args: string[], env: Record<string, string>, daemon = true): Child {
113
+ function start(name: string, command: string, args: string[], env: Record<string, string>, daemon = true, input?: string): Child {
114
114
  const child = spawn(command, args, {
115
115
  cwd: dir,
116
116
  env: { ...shell, ...env },
117
117
  // Its own process group, so stopping it stops what it started (workerd).
118
118
  detached: true,
119
- stdio: ['ignore', 'pipe', 'pipe'],
119
+ stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],
120
120
  });
121
+ if (input !== undefined) {
122
+ child.stdin!.on('error', () => {});
123
+ child.stdin!.end(input);
124
+ }
121
125
  const entry: Child = { name, child, daemon, exited: false, output: [] };
122
126
  child.stdout!.on('data', (chunk: Buffer) => entry.output.push(chunk));
123
127
  child.stderr!.on('data', (chunk: Buffer) => entry.output.push(chunk));
@@ -131,8 +135,8 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
131
135
  return entry;
132
136
  }
133
137
 
134
- async function run(command: string, args: string[], env: Record<string, string> = {}): Promise<void> {
135
- const entry = start(args[0] ?? command, command, args, env, false);
138
+ async function run(command: string, args: string[], env: Record<string, string> = {}, input?: string): Promise<void> {
139
+ const entry = start(args[0] ?? command, command, args, env, false, input);
136
140
  const code = await new Promise((done) => {
137
141
  entry.child.once('exit', done);
138
142
  entry.child.once('error', done);
@@ -198,9 +202,9 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
198
202
  sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`),
199
203
  );
200
204
  // As the deployment's pipeline does before it deploys: its own CLI's
201
- // `coffre migrate`, in its folder, the owner's URL in its environment.
205
+ // `coffre migrate`, in its folder, the owner's URL piped in.
202
206
  // A fresh log has no heartbeat: only the scheduled job can make /readyz pass.
203
- await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], { COFFRE_MIGRATE_DATABASE_URL: owner });
207
+ await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], {}, `${owner}\n`);
204
208
  // The app as it deploys: its Start app, built by its own Vite, which wrangler runs unbundled.
205
209
  await run(bin('vite'), ['build', 'app']);
206
210
  const state = join(scratch, 'state');
@@ -16,8 +16,8 @@ import { readParams, sendJson, type Route } from './http.ts';
16
16
  * `permissions: id-token: write`, to the bearer of `requestToken`. Locally,
17
17
  * `POST /workloads/token` mints one, for trying the CLI by hand:
18
18
  *
19
- * COFFRE_ID_TOKEN=$(curl -s -X POST http://127.0.0.1:8081/workloads/token \
20
- * -d aud=http://127.0.0.1:3000 | jq -r .token)
19
+ * curl -s -X POST http://127.0.0.1:8081/workloads/token -d aud=http://127.0.0.1:3000 | jq -r .token |
20
+ * coffre login http://127.0.0.1:3000 --service <name> --id-token
21
21
  */
22
22
  export class WorkloadIssuer {
23
23
  readonly #origin: () => string;
package/src/suite.ts CHANGED
@@ -3,17 +3,20 @@
3
3
  // which leaves the audit log broken for good.
4
4
  import type { Deployment } from './harness.ts';
5
5
  import { Report } from './report.ts';
6
- import { bulkLimit, crossSite, grantScoping, membersOnly, offboarding } from './checks/access.ts';
6
+ import { bulkLimit, crossSite, everyProject, grantScoping, membersOnly, offboarding } from './checks/access.ts';
7
7
  import { checkpoints, deletedTail, forgedVaultEntry, missingEntry, noAuditNoValue, revealAudited, rewrittenEntry, verification, writesAgree } from './checks/audit.ts';
8
8
  import { earlierCheckpoint } from './checks/checkpoints.ts';
9
+ import { deletion } from './checks/deletion.ts';
10
+ import { folders, forks, missingKeys, references } from './checks/environments.ts';
9
11
  import { appLogin, vaultLogin } from './checks/logins.ts';
12
+ import { mcpBrowse, mcpChanges, mcpConnect, mcpValues } from './checks/mcp.ts';
10
13
  import { accessAuthorship, memberTampering, noAuditNoAccess, sealingRace } from './checks/members.ts';
11
14
  import { refusedCheckpoint, missingCheckpoint, middleCut } from './checks/readiness.ts';
12
15
  import { editedGeneration, forgedCredential, forgedIdentity, forgedApproval } from './checks/signin.ts';
13
16
  import { canaryScan } from './checks/canaries.ts';
14
- import { Cli, cliLogin, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
17
+ import { Cli, cliLogin, manageByCli, verifyAsOwner, verifyAsUser, verifyInterrupted, verifyKeys, verifyLeftovers, verifyWithToken } from './checks/cli.ts';
15
18
  import { pageLoad, personas, setUp, setUpLive, signInAdmin } from './checks/people.ts';
16
- import { pagesInBrowser } from './checks/pages.ts';
19
+ import { pagesInBrowser, signinErrorOnce } from './checks/pages.ts';
17
20
  import { browserBundle, headers, health } from './checks/surface.ts';
18
21
  import { cliSignsIn, exchangesLimited, runSignsIn, runsRefused, runUnbound, spentOnce, tokensUnlogged, trustRun } from './checks/workloads.ts';
19
22
 
@@ -27,11 +30,21 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
27
30
  await report.check('security headers', { admin }, ({ admin }) => headers(deployment, admin));
28
31
  const canaries = await report.check('setup', { admin }, ({ admin }) => setUp(admin));
29
32
  await report.check('pages in a browser', { admin, canaries }, ({ admin }) => pagesInBrowser(deployment, admin, options.browser));
33
+ await report.check('sign-in error, once', { admin }, ({ admin }) => signinErrorOnce(deployment, admin, options.browser));
30
34
  const people = await report.check('personas', { admin, canaries }, ({ admin }) => personas(deployment, admin));
31
35
  const all = { people, canaries };
32
36
 
33
37
  await report.check('members only', { people }, ({ people }) => membersOnly(deployment, people));
34
38
  await report.check('grant scoping', all, ({ people, canaries }) => grantScoping(people, canaries));
39
+ await report.check('folders', all, ({ people, canaries }) => folders(people, canaries));
40
+ await report.check('forks', all, ({ people, canaries }) => forks(people, canaries));
41
+ await report.check('references', all, ({ people, canaries }) => references(deployment, people, canaries));
42
+ await report.check('missing keys', { people }, ({ people }) => missingKeys(people));
43
+ // Before offboarding: the leaver's CLI session is one of the credentials /mcp must refuse.
44
+ await report.check('MCP connect', { people }, ({ people }) => mcpConnect(deployment, people));
45
+ await report.check('MCP browse', all, ({ people, canaries }) => mcpBrowse(deployment, people, canaries));
46
+ await report.check('MCP changes', all, ({ people, canaries }) => mcpChanges(deployment, people, canaries));
47
+ await report.check('MCP values', all, ({ people, canaries }) => mcpValues(deployment, people, canaries));
35
48
  await report.check('reveals audited', all, ({ people, canaries }) => revealAudited(deployment, people, canaries, 'reveal'));
36
49
  await report.check('runs audited', all, ({ people, canaries }) => revealAudited(deployment, people, canaries, 'run'));
37
50
  await report.check('cross-site', all, ({ people, canaries }) => crossSite(people, canaries));
@@ -52,10 +65,13 @@ export async function conform(deployment: Deployment, options: { bulkLimit: numb
52
65
  verifyLeftovers(owner, admin, [first, second], before, live.canary),
53
66
  );
54
67
  await report.check('verify keys', { owner }, ({ owner }) => verifyKeys(owner));
68
+ await report.check('manage by CLI', { owner }, ({ owner }) => manageByCli(owner));
69
+ await report.check('delete by CLI', { owner, admin }, ({ owner, admin }) => deletion(deployment, owner, admin));
55
70
  } finally {
56
71
  for (const cli of clis) cli.remove();
57
72
  }
58
73
  await report.check('offboarding', all, ({ people, canaries }) => offboarding(deployment, people, canaries));
74
+ await report.check('grants on every project', all, ({ people, canaries }) => everyProject(deployment, people, canaries));
59
75
  await report.check('bulk limit', { people }, ({ people }) => bulkLimit(people, options.bulkLimit));
60
76
  // A CI run signing in with its ID token, through a binding. The limit
61
77
  // comes last of these: it spends this address's exchanges for the minute.