Accounts 1.7.1, Website 1.0.2, Events 3.7.1: link right after an install; Preview behind the proxy
Found installing the Website for cross-demo2. - All three: a connect involving an install that isn't in the cached copy of the Hub's list yet asks the Hub for a fresh list (one heartbeat, at most once a minute) instead of refusing. A new Website's admin couldn't sign in for up to 30 minutes. - Accounts: a heartbeat on every start. - Website: /admin links to Accounts on the spot (at most every 15 s), one connect to Accounts at a time, and the problem page says "not linked yet" (ACCOUNTS_NOT_LINKED). Preview redirected to the server's own http://localhost:<web port>: the preview routes now answer with a relative Location. - Events: a new Website can connect for the event feed straight away. - docs: VERSIONS, changelogs, WHATS-NEW. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import { buildExport } from '../src/export/churchExport.js';
|
||||
import { stats } from '../src/hub/client.js';
|
||||
import { connectAccountsIfListed } from '../src/links/connect.js';
|
||||
import { keyPair, saveLinkedProducts } from '../src/links/store.js';
|
||||
import { ACCOUNTS_INSTALL_ID, harness, INSTALL_ID } from './support/harness.js';
|
||||
import { ACCOUNTS_INSTALL_ID, harness, INSTALL_ID, SITE } from './support/harness.js';
|
||||
|
||||
const accountsKeys = generateEd25519();
|
||||
const accountsPublic = ed25519PublicToPem(accountsKeys.publicKey);
|
||||
@@ -88,6 +88,72 @@ describe('linking to the church\'s Accounts', () => {
|
||||
});
|
||||
});
|
||||
|
||||
/** A Hub answering heartbeats with `list` as the church's products (only what the Website reads). */
|
||||
async function fakeHub(list: () => unknown[]) {
|
||||
const calls: string[] = [];
|
||||
const server = http.createServer((req, res) => {
|
||||
calls.push(String(req.url));
|
||||
res.setHeader('content-type', 'application/json');
|
||||
res.end(JSON.stringify({ ok: true, licence: '', linkedProducts: list() }));
|
||||
});
|
||||
await new Promise<void>((r) => server.listen(0, '127.0.0.1', () => r()));
|
||||
const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
|
||||
closers.push(() => new Promise((r) => server.close(r)));
|
||||
return { url, calls };
|
||||
}
|
||||
|
||||
describe('1.0.2: linking right after an install', () => {
|
||||
it('links to Accounts when someone opens /admin, asking the Hub for a fresh list first', async () => {
|
||||
let accountsUrl = '';
|
||||
const hubServer = await fakeHub(() => [{ product: 'accounts', installId: ACCOUNTS_INSTALL_ID, url: accountsUrl, publicKey: accountsPublic }]);
|
||||
const h = await harness({ linked: false, env: { LINKS_ALLOW_PRIVATE: 'true', HUB_URL: hubServer.url } });
|
||||
await h.ctx.settings.set('hub_install_secret', 'secret');
|
||||
const accounts = await fakeAccounts(async () => (await keyPair(h.ctx)).publicKeyPem);
|
||||
closers.push(accounts.close);
|
||||
accountsUrl = accounts.url;
|
||||
|
||||
// The Website's cached list has no Accounts yet (it registered before the Hub knew of one).
|
||||
const res = await request(h.app).get('/api/auth/signin?returnTo=%2Fadmin');
|
||||
assert.equal(res.status, 303);
|
||||
assert.match(res.headers.location!, /^https:\/\/accounts\.hope\.test\//, 'off to Accounts, not the problem page');
|
||||
assert.deepEqual(hubServer.calls, ['/api/installs/heartbeat']);
|
||||
assert.equal(accounts.seen.length, 1, 'one connect, not one from the heartbeat and another from the sign-in');
|
||||
assert.equal(await h.db.productLink.count({ where: { product: 'accounts' } }), 1);
|
||||
});
|
||||
|
||||
it('tries again at most every 15 seconds while it can\'t link', async () => {
|
||||
let clock = new Date('2026-11-26T15:00:00Z');
|
||||
const hubServer = await fakeHub(() => []);
|
||||
const h = await harness({ linked: false, env: { HUB_URL: hubServer.url } });
|
||||
h.ctx.now = () => clock;
|
||||
await h.ctx.settings.set('hub_install_secret', 'secret');
|
||||
const problem = `${SITE}/auth/problem?code=ACCOUNTS_NOT_LINKED&returnTo=%2Fadmin`;
|
||||
assert.equal((await request(h.app).get('/api/auth/signin?returnTo=%2Fadmin')).headers.location, problem);
|
||||
assert.equal((await request(h.app).get('/api/auth/signin?returnTo=%2Fadmin')).headers.location, problem);
|
||||
assert.equal(hubServer.calls.length, 1);
|
||||
clock = new Date(clock.getTime() + 61_000);
|
||||
await request(h.app).get('/api/auth/signin?returnTo=%2Fadmin');
|
||||
assert.equal(hubServer.calls.length, 2);
|
||||
});
|
||||
|
||||
it('accepts a connect from a product installed after its last heartbeat (Events, for the event feed)', async () => {
|
||||
const EVENTS_INSTALL_ID = '4d2e8f3a-9b1c-4d0e-8f7a-6b5c4d3e2f1a';
|
||||
const eventsKeys = generateEd25519();
|
||||
const events = { product: 'events', installId: EVENTS_INSTALL_ID, url: 'https://events.hope.test', publicKey: ed25519PublicToPem(eventsKeys.publicKey) };
|
||||
const hubServer = await fakeHub(() => [events]);
|
||||
const h = await harness({ env: { HUB_URL: hubServer.url } });
|
||||
await h.ctx.settings.set('hub_install_secret', 'secret');
|
||||
const m = signLink({
|
||||
schema: LINK_SCHEMA, type: 'link.connect', from: { product: 'events', installId: EVENTS_INSTALL_ID, url: events.url },
|
||||
to: { installId: INSTALL_ID }, secret: newLinkSecret(), issuedAt: new Date().toISOString(), nonce: newLinkNonce(),
|
||||
}, eventsKeys.privateKeyPem);
|
||||
const res = await request(h.app).post('/api/links/v1/connect').send(m);
|
||||
assert.equal(res.status, 200, JSON.stringify(res.body));
|
||||
assert.equal(hubServer.calls.length, 1);
|
||||
assert.equal(await h.db.productLink.count({ where: { product: 'events' } }), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the heartbeat and the export', () => {
|
||||
it('reports aggregate counts the Hub accepts', async () => {
|
||||
const h = await harness();
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('signing in to the admin through Accounts', () => {
|
||||
const h = await harness({ linked: false });
|
||||
const res = await request(h.app).get('/api/auth/signin?returnTo=%2Fadmin');
|
||||
assert.equal(res.status, 303);
|
||||
assert.equal(res.headers.location, `${SITE}/auth/problem?code=ACCOUNTS_UNAVAILABLE&returnTo=%2Fadmin`);
|
||||
assert.equal(res.headers.location, `${SITE}/auth/problem?code=ACCOUNTS_NOT_LINKED&returnTo=%2Fadmin`);
|
||||
});
|
||||
|
||||
it('makes the Hub\'s admin email (verified) the first Owner and lands on the page they started from', async () => {
|
||||
|
||||
Reference in New Issue
Block a user