Mail relay: review round 2 — the store is keyed by host, a copied database does not enrol by itself

- Q-1 one entry per host (iapl:mail-relay:site:<host>); a read never deletes or writes; another host's
  entry is neither used nor touched (a developer's process on the live database, www and apex, a copy)
- a database that holds another host's connection and none of this site's does not enrol by itself:
  "Connect again" does, once; mail.relay.otherHosts ('wait' | 'enrol' | the site's own other hosts);
  panel text and doctor finding; a site with an empty store enrols by itself as before
- Q-2 the file limit answers from what is stored and never asks the service
- Q-3 a file whose mail was not confirmed is not reported as a wrong file, and no notice mail follows
- Q-4 its own text when the access-key field is off
- D-1 docs for open enrolment; staging, copies and several hosts

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 23:14:11 +01:00
co-authored by Claude Fable 5.2
parent edee3a321f
commit 85ed92bb89
31 changed files with 467 additions and 211 deletions
+6 -2
View File
@@ -30,6 +30,8 @@ vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHe
const PASSWORD = 'a-long-test-password-1'
const HOST = 'example.com'
const CONFIRM = `/api${RELAY_CONFIRM_PATH}`
/** The site's entry: one per host. */
const SITE_KEY = `${RELAY_KV_KEY}:site:${HOST}`
let server: TestServer
let payload: Payload
@@ -139,7 +141,7 @@ describe('the token cannot be reached from outside', () => {
test('it is in the key-value store', async () => {
token = (await readRelayStore(payload)).token ?? ''
expect(token).toMatch(/^ims_[\w-]{43}$/)
const rows = await payload.db.find({ collection: 'payload-kv', limit: 0, pagination: false, where: { key: { equals: RELAY_KV_KEY } } })
const rows = await payload.db.find({ collection: 'payload-kv', limit: 0, pagination: false, where: { key: { equals: SITE_KEY } } })
expect(rows.docs).toHaveLength(1)
id = (rows.docs[0] as { id: number | string }).id
expect(JSON.stringify(rows.docs[0])).toContain(token)
@@ -150,7 +152,7 @@ describe('the token cannot be reached from outside', () => {
const answers = [
await api('/payload-kv', headers),
await api(`/payload-kv/${id}`, headers),
await api(`/payload-kv?where[key][equals]=${encodeURIComponent(RELAY_KV_KEY)}&depth=0`, headers),
await api(`/payload-kv?where[key][equals]=${encodeURIComponent(SITE_KEY)}&depth=0`, headers),
await api('/payload-kv', headers, { body: JSON.stringify({ data: { token: 'x' }, key: `${RELAY_KV_KEY}:x` }), method: 'POST' }),
await api(`/payload-kv/${id}`, headers, { body: JSON.stringify({ data: {} }), method: 'PATCH' }),
await api(`/payload-kv/${id}`, headers, { method: 'DELETE' }),
@@ -213,6 +215,8 @@ describe('the state routes are for admins', () => {
expect(((await (await api('/iapl/mail-relay/status', admin)).json()) as { accessKeyField?: boolean }).accessKeyField).toBeUndefined()
const closed = await post('/iapl/mail-relay/connect', admin, { token: fake.issueToken(HOST) })
expect(closed.status).toBe(403)
// said as what it is — not "only an administrator can do this" to an administrator
expect(((await closed.json()) as { error: string }).error).toMatch(/set by the site's developer/)
expect((await readRelayStore(payload)).token).toBe(mine)
// a project switches the field on: mail.relay.accessKeyField
relayOptions.accessKeyField = true