Mail relay: review of 7d766b6 — R-1 to R-12, four mutations, two sentences

- R-1 a delivered token becomes the one in use only on 200 or a refusal given after authentication
- R-2 a token of another site is refused by what /v1/status says (access-key field, scripts); docs for staging
- R-3 the confirm route looks the nonce up first and counts only refused calls
- R-4 one budget of time per message (10 s, 30 s with files), enrolment and retries included
- R-5 'Disconnect' without the service's answer is not confirmed and keeps the token to try again
- R-6 no enrolment without the confirm route in the config
- R-7 half an SMTP set-up: one log line and a hint in the panel
- R-8 to R-10, R-12 docs; R-11 the last failure stays in the state block
- tests for redirect: manual, the candidate's nonce, the expectation taken back, one recipient only

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 22:07:10 +01:00
co-authored by Claude Fable 5.2
parent 0ee74ab2a4
commit a2b07b1dc1
23 changed files with 584 additions and 69 deletions
+20
View File
@@ -205,6 +205,13 @@ describe('the state routes are for admins', () => {
})
test('"Disconnect" and "Connect again" work for an admin, and neither shows a token', async () => {
// a token of another site pasted while the site is connected: refused, and the site's own token stays
const mine = (await readRelayStore(payload)).token
const stranger = fake.issueToken('someone-else.example.org')
expect((await post('/iapl/mail-relay/connect', admin, { token: stranger })).status).toBe(400)
expect((await readRelayStore(payload)).token).toBe(mine)
expect(mine).toMatch(/^ims_/)
const off = await post('/iapl/mail-relay/disconnect', admin)
const offBody = (await off.json()) as Record<string, unknown>
expect(offBody).toMatchObject({ ok: true, relay: { connected: false, disconnected: true } })
@@ -213,6 +220,19 @@ describe('the state routes are for admins', () => {
const bad = await post('/iapl/mail-relay/connect', admin, { token: 'ims_not-a-token' })
expect(bad.status).toBe(400)
// the access-key field: a token the service does not know, and a token of ANOTHER site, are refused before
// anything is stored; the other site's token is not revoked
expect((await post('/iapl/mail-relay/connect', admin, { token: `ims_${'q'.repeat(43)}` })).status).toBe(400)
const foreign = fake.issueToken('other-client.example.org')
const refused = await post('/iapl/mail-relay/connect', admin, { token: foreign })
expect(refused.status).toBe(400)
expect(await refused.text()).not.toContain('ims_')
expect((await readRelayStore(payload)).token).toBeUndefined()
expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}` } }))).status).toBe(200)
// a token issued by hand for THIS host is taken, and the state says where it came from
const own = await post('/iapl/mail-relay/connect', admin, { token: fake.issueToken(HOST) })
expect(await own.json()).toMatchObject({ ok: true, relay: { connected: true, tokenSource: 'manual' } })
await post('/iapl/mail-relay/disconnect', admin)
const on = await post('/iapl/mail-relay/connect', admin)
const onBody = (await on.json()) as Record<string, unknown>
expect(onBody, JSON.stringify(onBody)).toMatchObject({ ok: true, relay: { connected: true, disconnected: false, state: 'active' } })