// zds, in Docker, from the image `node bench.mjs --setup` builds from its // pinned commit (bench/impls.json), configured as lib/impls.mjs configures // it, plus what a compatibility run needs. import { spawnSync } from 'node:child_process' import { join } from 'node:path' import { ADMIN_PASSWORD, HANDLE_DOMAINS } from '../env.mjs' import { Browser } from '../oauth.mjs' import { dockerPort, fromDocker, imageId, pins, shOk, zdsCreateArgs, zdsEnv, zdsOwnEnv } from '../impls.mjs' import { DOCKER_NEEDS, basic, container, hidden, signer, throughForms } from './common.mjs' export default { about: `zds ${pins.implementations.zds.release} (${pins.implementations.zds.repo} at ${pins.implementations.zds.commit.slice(0, 7)}), its image built by \`node bench.mjs --setup\`, in Docker`, pageApi: false, own: false, unsupported: { clientFetch: 'zds fetches a client document from the client_id\'s own https URL (src/internal/outbound.zig); it has no mapping of origins to the harness\'s web, as PDS_OAUTH_CLIENT_FETCH is', hostname: 'zds takes its hostname from ZDS_PUBLIC_URL, which must be the URL the harness calls (DPoP\'s htu, src/internal/dpop.zig:208-222), and sends requestCrawl the host without its port (src/atproto/sync.zig:676-688): it cannot be localhost, as the reference\'s is', narrowScope: 'zds\'s authorization page has no consent step (src/atproto/oauth.zig:438-489): a sign-in grants the scope asked, so a narrower one cannot be chosen', limits: 'zds has no general rate limits to turn on (only updateHandle, full getRepo exports and subscribeRepos)', restart: 'a container keeps the environment it was made with: no restart with another', lexiconAuthority: 'the harness knows no setting of zds naming one DID every NSID\'s lexicon is resolved from, as PDS_LEXICON_AUTHORITY_DID does: it would look the harness\'s permission sets up in DNS, which the harness does not serve', }, port: dockerPort, readyMs: 120_000, async info() { const pin = pins.implementations.zds return { version: pin.release, source: `${pin.repo} at ${pin.commit}, image ${pin.tag} (${await imageId(pin.tag)}) built with its own ${pin.dockerfile}`, config: '' } }, async start(o) { const pin = pins.implementations.zds const image = await imageId(pin.tag) if (!image) throw new Error(`zds: no Docker image ${pin.tag}; ${DOCKER_NEEDS}`) const name = `compat-zds-${process.pid}-${Date.now()}` const { rotation, hex } = await signer() // The harness's setup, as far as zds takes it (docs/operations.md): // the reference's server DID, handle domains, recovery key, admin // password and invites; mail kept in its outbox; the harness's AppView // as its proxy service; its crawlers; and no SSRF guard, as the // reference runs. const env = { ...zdsEnv, ...zdsOwnEnv({ port: o.port, plcUrl: o.plc, rotationHex: hex, admin: ADMIN_PASSWORD }), ZDS_SERVER_DID: 'did:web:localhost', ZDS_HANDLE_DOMAINS: HANDLE_DOMAINS.join(','), ZDS_RECOVERY_DID_KEY: o.recoveryKey, ZDS_INVITE_REQUIRED: String(o.invites), ZDS_MAIL_PROVIDER: 'outbox', ZDS_CRAWLERS: (o.crawlers ?? []).map(fromDocker).join(','), ZDS_ALLOW_PRIVATE_FETCH: 'true', ...(o.appView ? { ZDS_PROXY_SERVICE_URL: fromDocker(o.appView.url), ZDS_PROXY_SERVICE_DID: o.appView.did } : {}), } await shOk('docker', zdsCreateArgs({ name, port: o.port, env, image })) const url = `http://127.0.0.1:${o.port}` const admin = basic('admin', ADMIN_PASSWORD) // Its outbox (dev.zat.admin.listMail), newest first; each taken once. const seen = new Set() return { server: container(name, env, join(o.logDir, 'server.log'), join(o.logDir, 'server.err'), () => spawnSync('docker', ['rm', '-f', '-v', name])), url, publicUrl: url, recoveryKey: o.recoveryKey, rotationKey: rotation.did(), plcSigner: rotation, admin, async takeMail() { const r = await fetch(`${url}/xrpc/dev.zat.admin.listMail?limit=100`, { headers: { authorization: admin } }).then((x) => x.json()).catch(() => ({ messages: [] })) const fresh = (r.messages ?? []).filter((m) => !seen.has(m.id)).reverse() for (const m of fresh) seen.add(m.id) return fresh.map((m) => ({ to: m.to, kind: m.subject, token: m.code ?? null })) }, } }, /// The password form `GET /oauth/authorize` serves, posted as a browser /// posts it (src/atproto/oauth.zig:438-489): `request_uri`, `username`, /// `password`, and `deny` to refuse. It grants at once, with a 303 to /// the client. async signIn(account, authorizeUrl, consent) { const b = new Browser() return throughForms(b, authorizeUrl, [ (page) => ({ action: '/oauth/authorize', fields: { request_uri: hidden(page.text, 'request_uri') ?? new URL(authorizeUrl).searchParams.get('request_uri'), username: account.identifier, password: account.password, ...(consent.approve ? {} : { deny: '1' }) } }), ]) }, }