Hub 2.2.0: a public key on the v2 heartbeat, Clear public key

Installs that registered with protocol v1 move to v2 by sending their
public key on a signed v2 heartbeat: saved / matches / mismatch, never a
failed heartbeat. Clear public key (2FA again) for a rebuilt server.
Contracts 1.4.0 vendored; hub-protocol.md §6 updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 12:05:59 +02:00
co-authored by Claude Opus 5.5
parent 7428337aa5
commit 106d71e566
11 changed files with 158 additions and 14 deletions
+53
View File
@@ -239,6 +239,59 @@ describe('heartbeat', () => {
expect(Object.keys(json).sort()).toEqual(['latestVersion', 'licence', 'notices', 'releases', 'serverTime']);
});
describe('public key on the heartbeat (Hub 2.2.0)', () => {
const v1Events = async () => {
const r = eventsRegistration();
const { json } = await register({ protocolVersion: 1, licenceKey: r.licenceKey, install: { name: r.install.name, url: r.install.url, version: '2.3.1' } });
return json;
};
test('an install registered with v1 moves to v2 with its key, and its siblings then list it', async () => {
const reg = await v1Events();
const { json: website } = await register(websiteRegistration());
const key = pem();
const res = await signed('/installs/heartbeat', reg, { ...sample('hub-heartbeat-events.json'), publicKey: key });
const json = await res.json();
expect(res.status).toBe(200);
expect(hub.heartbeatResponseSchema.safeParse(json).error?.issues ?? []).toEqual([]);
expect(json.publicKeyStatus).toBe('saved');
expect(json.linkedProducts.map(l => l.product)).toEqual(['website']);
expect(mockDb.t.installs.find(i => i.id === reg.installId).publicKey.trim()).toBe(key.trim());
const fromWebsite = await (await signed('/installs/heartbeat', website, sample('hub-heartbeat-website.json'))).json();
expect(fromWebsite.linkedProducts.map(l => [l.product, l.installId])).toEqual([['events', reg.installId]]);
});
test('the same key again matches, also with Windows line endings', async () => {
const reg = await v1Events();
const key = pem();
await signed('/installs/heartbeat', reg, { ...sample('hub-heartbeat-events.json'), publicKey: key });
const crlfKey = key.split(String.fromCharCode(10)).join(String.fromCharCode(13, 10));
const json = await (await signed('/installs/heartbeat', reg, { ...sample('hub-heartbeat-events.json'), publicKey: crlfKey })).json();
expect(json.publicKeyStatus).toBe('matches');
});
test('a different key keeps the saved one, raises one alert and never fails the heartbeat', async () => {
const reg = await v1Events();
const first = pem();
await signed('/installs/heartbeat', reg, { ...sample('hub-heartbeat-events.json'), publicKey: first });
for (let i = 0; i < 2; i++) {
const res = await signed('/installs/heartbeat', reg, { ...sample('hub-heartbeat-events.json'), publicKey: pem() });
expect(res.status).toBe(200);
const json = await res.json();
expect(json.publicKeyStatus).toBe('mismatch');
expect(json.licence).toBeTruthy();
}
expect(mockDb.t.installs.find(i => i.id === reg.installId).publicKey.trim()).toBe(first.trim());
expect(mockDb.t.events.filter(e => e.type === 'public_key_mismatch').length).toBeGreaterThanOrEqual(1);
});
test('a heartbeat without a key has no publicKeyStatus', async () => {
const { json: reg } = await register(eventsRegistration());
const json = await (await signed('/installs/heartbeat', reg, sample('hub-heartbeat-events.json'))).json();
expect(json).not.toHaveProperty('publicKeyStatus');
});
});
test('an unsigned heartbeat is refused', async () => {
const { json: reg } = await register(eventsRegistration());
const res = await post('/installs/heartbeat', sample('hub-heartbeat-events.json'), { 'X-Hub-Install': reg.installId, 'X-Hub-Timestamp': new Date().toISOString(), 'X-Hub-Signature': 'nope' });