~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A site's page reaches the console without its visitor's session

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:e2e/site-session-2
docs/development.md+13−8
@@ -61,14 +61,19 @@ as it should and writes the coverage it counted.
`just e2e` uses the console as people use it, in Chromium, with
Playwright (`harness/e2e/flows.spec.mjs`): it signs in through the
reference PDS's own approval page, signs an app in as a group and has it
write as the group, declines one, and signs out. Its setup
(`harness/e2e/setup.mjs`) runs the reference PDS, the host over it, and
the built console behind an https front at `console.group-host.internal`
(`harness/tls-proxy.mjs`), as the PDS reaches an OAuth client only over
https at a hostname; `harness/pds.mjs` makes that name's certificate and
resolves it. Chromium comes with `cd harness && npx playwright install
chromium`. A failed flow leaves its trace and a picture under
`target/e2e/results`.
write as the group, publishes a site and checks that a page of it reaches
the console without the session of whoever opens it, declines an app,
and signs out. Its setup (`harness/e2e/setup.mjs`) runs the reference
PDS, the host over it, and the built console behind an https front at
`console.group-host.internal` (`harness/tls-proxy.mjs`), as the PDS
reaches an OAuth client only over https at a hostname; `harness/pds.mjs`
makes that name's certificate and resolves it. Hikers' site has a front
of its own at `hikers.group-host.internal`, a name beside the console's,
so the browser takes its pages for the same site as the console, as it
does a deployment's group addresses. Chromium comes with `cd harness &&
npx playwright install chromium`, and is told that every name under
`group-host.internal` is this machine. A failed flow leaves its trace and
a picture under `target/e2e/results`.
## Looking at the console
harness/e2e/flows.spec.mjs+62−0
@@ -600,6 +600,68 @@ test('publishing a site from a folder, and deleting it', async () => {
await expect(page.getByRole('link', { name: 'Website' })).toHaveCount(0);
});
test("a site's page reaches the console without the session of whoever opens it", async () => {
// A page anyone with group.configure could publish: it asks the host as
// whoever is looking, then posts a form signing them out. The site is
// at a name beside the console's, as a deployment's group addresses
// are beside its own name, so only its sandbox keeps the session back.
const consoleOrigin = new URL(world.base).origin;
const dir = mkdtempSync(join(tmpdir(), 'e2e-site-'));
writeFileSync(
join(dir, 'index.html'),
`<form id="out" method="post" action="${consoleOrigin}/console/logout"></form>
<script>
fetch('${consoleOrigin}/xrpc/fyi.opensocial.getViewer', { credentials: 'include' })
.catch(() => {})
.finally(() => document.getElementById('out').submit());
</script>`
);
await page.goto(url('/g/hikers.groups.test/settings/site'));
await page.getByRole('button', { name: 'Publish a site' }).click();
const publishing = page.getByRole('dialog', { name: 'Publish a site' });
await publishing.getByLabel('Folder').setInputFiles(dir);
await publishing.getByRole('button', { name: 'Publish' }).click();
await expect(publishing).toBeHidden();
// Each request the browser sends the console, with its cookies, until
// the one signing out.
const sent = [];
let out = false;
const watch = (req) => {
const at = new URL(req.url());
if (out || at.origin !== consoleOrigin) return;
out = at.pathname === '/console/logout';
sent.push(req.allHeaders().then((h) => ({ path: at.pathname, cookie: h.cookie ?? '' })));
};
const session = /group_host_session=/;
page.on('request', watch);
// From the console's own page, its session goes with it.
await page.evaluate(() => fetch('/xrpc/fyi.opensocial.getViewer'));
// From the site's, nothing of it does.
await page.goto(world.hikersSite);
await page.waitForURL((u) => u.origin === consoleOrigin);
page.off('request', watch);
const [own, ...fromSite] = await Promise.all(sent);
expect(own.path).toBe('/xrpc/fyi.opensocial.getViewer');
expect(own.cookie).toMatch(session);
expect(fromSite.map((r) => r.path)).toEqual([
'/xrpc/fyi.opensocial.getViewer',
'/console/logout'
]);
for (const r of fromSite) expect(r.cookie, r.path).not.toMatch(session);
// So she is signed in still.
await page.goto(url('/'));
await expect.poll(() => signedInAs(page)).toBe('@alice.test');
await page.goto(url('/g/hikers.groups.test/settings/site'));
await page.getByRole('button', { name: 'Delete the site' }).click();
await page
.getByRole('dialog', { name: 'Delete this site?' })
.getByRole('button', { name: 'Delete' })
.click();
await expect(page.getByText('Nothing published yet')).toBeVisible();
});
test("hiding a group's profile, and showing it again", async () => {
// Found on the network while its declaration is in its public repo,
// which anyone may read.
harness/e2e/setup.mjs+17−5
@@ -1,9 +1,11 @@
// Before the flows: a world (../world.mjs) whose console is behind the
// https front the PDS sends sign-ins back to (harness/tls-proxy.mjs), at
// the name harness/pds.mjs resolves for itself. Where everything is goes
// to the flows in E2E_WORLD. Returns the teardown.
// the name harness/pds.mjs resolves for itself; and Hikers' site, which a
// flow starts, behind a front of its own at a name beside the console's.
// Where everything is goes to the flows in E2E_WORLD. Returns the
// teardown.
import { start, tlsFront as front } from '../world.mjs';
import { siteFront, start, tlsFront as front } from '../world.mjs';
export default async function setup() {
// harbor is an account of its own, which alice moves here to become a group;
@@ -13,6 +15,12 @@ export default async function setup() {
front
});
const { net } = w;
const hikers = await siteFront(
net,
new URL(w.host).port,
'hikers.group-host.internal',
'hikers.groups.test'
);
process.env.E2E_WORLD = JSON.stringify({
base: w.base,
host: w.host,
@@ -20,7 +28,11 @@ export default async function setup() {
pds: net.pds,
mail: net.mail,
accounts: net.accounts,
riders: w.riders
riders: w.riders,
hikersSite: hikers.url
});
return w.stop;
return () => {
hikers.proxy.kill('SIGTERM');
w.stop();
};
}
harness/tls-proxy.mjs+7−4
@@ -1,7 +1,9 @@
// An https front for the console under test, at the harness's console
// hostname, passing every request on to it over plain http.
// hostname, passing every request on to it over plain http; or, given a
// name, for what the target serves at that name (a group's site, at its
// address), each request passed on as if to it.
//
// node harness/tls-proxy.mjs <cert> <key> <target port>
// node harness/tls-proxy.mjs <cert> <key> <target port> [<host>]
//
// Prints the port it listens on, and exits when stdin closes.
@@ -10,11 +12,12 @@ import { createServer } from 'node:https';
import { request } from 'node:http';
import { connect } from 'node:net';
const [cert, key, target] = process.argv.slice(2);
const [cert, key, target, host] = process.argv.slice(2);
const server = createServer({ cert: readFileSync(cert), key: readFileSync(key) }, (req, res) => {
const headers = host ? { ...req.headers, host } : req.headers;
const upstream = request(
{ host: '127.0.0.1', port: target, path: req.url, method: req.method, headers: req.headers },
{ host: '127.0.0.1', port: target, path: req.url, method: req.method, headers },
(answer) => {
res.writeHead(answer.statusCode, answer.headers);
answer.pipe(res);
harness/world.mjs+27−13
@@ -68,24 +68,38 @@ const up = async (url) => {
throw new Error(`${url} never answered`);
};
/// The console's front for a browser the harness drives:
/// harness/tls-proxy.mjs, with the certificate the PDS trusts, for the
/// name only it resolves (harness/pds.mjs), which the browser is told
/// An https front, harness/tls-proxy.mjs with the certificate the PDS
/// trusts, for what listens on `port`, asked as `host` if given: the
/// process, and the port it listens on.
const proxied = async (net, port, host) => {
const args = [join(root, 'harness/tls-proxy.mjs'), net.console.cert, net.console.key];
const proxy = spawn('node', [...args, String(port), ...(host ? [host] : [])], {
stdio: ['pipe', 'pipe', 'inherit']
});
return { proxy, port: (await line(proxy, (l) => /^\d+$/.test(l.trim()))).trim() };
};
/// The console's front for a browser the harness drives, for the name
/// only it resolves (harness/pds.mjs), which the browser is told
/// (`resolving`).
export const tlsFront = async (consolePort, net, children) => {
const proxy = spawn(
'node',
[join(root, 'harness/tls-proxy.mjs'), net.console.cert, net.console.key, String(consolePort)],
{
stdio: ['pipe', 'pipe', 'inherit']
}
);
const { proxy, port } = await proxied(net, consolePort);
children.push(proxy);
return `https://${net.console.host}:${(await line(proxy, (l) => /^\d+$/.test(l.trim()))).trim()}`;
return `https://${net.console.host}:${port}`;
};
/// A group's site, at its `address` on the host at `hostPort`, behind a
/// front at `name`, a name beside the console's: the browser takes its
/// pages for the same site as the console, as it does a deployment's
/// group addresses beside the host's own name. Its URL, and the front.
export const siteFront = async (net, hostPort, name, address) => {
const { proxy, port } = await proxied(net, hostPort, address);
return { url: `https://${name}:${port}`, proxy };
};
/// Chromium's argument that sends the console's name to this machine.
export const resolving = '--host-resolver-rules=MAP console.group-host.internal 127.0.0.1';
/// Chromium's argument that sends the console's name, and every name
/// beside it, to this machine.
export const resolving = '--host-resolver-rules=MAP *.group-host.internal 127.0.0.1';
/// `account`'s service auth for `aud` and `lxm`, from their own PDS.
export const serviceAuth = async (pds, account, aud, lxm) => {