Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

test(e2e): preserve printed view cookie links [N26,I8]

Corey Olsonbf69c0a48e86
diff --git a/test/e2e.test.js b/test/e2e.test.js
index 094df3e2..484b6e33 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -53,6 +53,7 @@ function sandbox() {
PULLBOARD_HOME: join(dir, 'pullboard-home'),
PULLBOARD_MACHINE_HOME: join(dir, 'machine-home'),
};
+ delete env.PULLBOARD_RELAY_TOKEN;
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
const tryGit = (cwd, ...args) => spawnSync('git', args, { cwd, env, encoding: 'utf8' });
const run = (cwd, ...args) => {
@@ -1526,6 +1527,35 @@ async function startView(box, cwd) {
const key = link.searchParams.get('k');
const base = `http://127.0.0.1:${link.port}`;
const headers = { 'x-pullboard-key': key };
+ /**
+ * Fetch the page through either the accepted printed-key response or the cookie exchange.
+ * Keeping these paths in one fixture lets the API assertions stay independent of page auth.
+ */
+ const page = async () => {
+ const response = await fetch(link, { redirect: 'manual' });
+ if (response.status === 200) return response;
+ assert.equal(response.status, 303, 'the printed link either serves the legacy page or exchanges its key');
+
+ const rawLocation = response.headers.get('location');
+ assert.ok(rawLocation, 'the cookie exchange has a redirect target');
+ const location = new URL(rawLocation, base);
+ assert.equal(location.origin, new URL(base).origin, 'the cookie exchange stays on this view origin');
+ assert.equal(location.pathname, '/', 'the cookie exchange returns to the clean page path');
+ assert.equal(location.search, '', 'the redirect does not keep credentials in the address');
+ assert.equal(location.hash, '', 'the redirect has no credential-bearing fragment');
+
+ const cookies = response.headers.getSetCookie?.() ?? [response.headers.get('set-cookie')].filter(Boolean);
+ assert.equal(cookies.length, 1, 'the exchange sets one session cookie');
+ const [pair, ...attributes] = cookies[0].split(';').map((part) => part.trim());
+ assert.match(pair, /^[A-Za-z0-9_-]+=[A-Za-z0-9._~-]+$/u, 'the session cookie has a valid nonempty name and value');
+ assert.ok(attributes.some((attribute) => /^httponly$/iu.test(attribute)), 'the session cookie is HttpOnly');
+ assert.ok(attributes.some((attribute) => /^samesite=strict$/iu.test(attribute)), 'the session cookie is SameSite=Strict');
+ assert.ok(attributes.some((attribute) => /^path=\/$/iu.test(attribute)), 'the session cookie is scoped to the view');
+
+ const pageResponse = await fetch(location, { headers: { cookie: pair }, redirect: 'manual' });
+ assert.equal(pageResponse.status, 200, 'the cookie jar fetches the page after the exchange');
+ return pageResponse;
+ };
/** Read the public listing through the view's real authenticated API. */
const boards = async () => {
const response = await fetch(`${base}/api/v1/boards`, { headers });
@@ -1557,7 +1587,7 @@ async function startView(box, cwd) {
child.once('exit', done);
child.kill('SIGTERM');
});
- return { link, key, base, state, act, stop };
+ return { link, key, base, page, state, act, stop };
}
test('view serves every project on this machine, on loopback, behind its secret and its own Host [N26, I8]', async () => {
@@ -1572,8 +1602,7 @@ test('view serves every project on this machine, on loopback, behind its secret
const badSecret = await fetch(`${view.base}/api/v1/boards`, { headers: { 'x-pullboard-key': 'guess' } });
assert.equal(badSecret.status, 401, 'a wrong secret');
assert.equal((await badSecret.json()).error.code, 'AUTH_REQUIRED');
- const page = await fetch(view.link);
- assert.equal(page.status, 200);
+ const page = await view.page();
assert.match(await page.text(), /<title>Pullboard<\/title>/);
const { boards, warnings, project: shown } = await view.state(box.repo);
assert.deepEqual(boards.map((entry) => [entry.root, entry.name]), [[box.repo, 'repo']]);
@@ -1644,7 +1673,7 @@ test('the view answers a request line no URL parser accepts with 403, and keeps
socket.on('close', () => done(text));
});
assert.match(reply, /^HTTP\/1\.1 403/);
- assert.equal((await fetch(view.link)).status, 200, 'still serving');
+ assert.equal((await view.page()).status, 200, 'still serving');
} finally {
await view.stop();
}
@@ -1672,7 +1701,7 @@ test('the view keeps the board layout people know: switcher, tabs, a list and it
box.git(box.repo, 'switch', '-q', 'main');
const view = await startView(box, box.repo);
try {
- const page = await (await fetch(view.link)).text();
+ const page = await (await view.page()).text();
for (const region of ['id="proj-switch"', 'data-tab="items"', 'data-tab="shouts"', 'data-tab="spec"', 'data-tab="doctrine"', 'data-tab="activity"', 'id="chain"', 'id="detail"', 'id="add-form"', 'id="hold-form"']) {
assert.ok(page.includes(region), region);
}