Mail relay: HTTP tests on a running Payload, account mail marked by recipient, panel wording, doctor rules tested
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
ea9703f8e3
commit
533f571d4d
+56
-1
@@ -515,8 +515,9 @@ describe('security and deep status', () => {
|
||||
}
|
||||
const status = await collectDoctorStatus(payload as never)
|
||||
expect(status).toMatchObject({ pendingCookies: 4, usersWithout2fa: 2 })
|
||||
expect(Object.keys(status).sort()).toEqual(['node', 'openSignUp', 'pendingCookies', 'plugin', 'staffOnOwnRoles', 'staffOpenToOthers', 'turnstile', 'turnstileSecretFromEnv', 'usersSetupClosed', 'usersWithout2fa'])
|
||||
expect(Object.keys(status).sort()).toEqual(['mail', 'node', 'openSignUp', 'pendingCookies', 'plugin', 'staffOnOwnRoles', 'staffOpenToOthers', 'turnstile', 'turnstileSecretFromEnv', 'usersSetupClosed', 'usersWithout2fa'])
|
||||
expect(status.usersSetupClosed).toBeNull() // no setup window in this config
|
||||
expect(status.mail).toBeNull() // no Site integrations global in this config
|
||||
})
|
||||
test('collectDoctorStatus counts the accounts whose 2FA setup window has passed', async () => {
|
||||
const payload = {
|
||||
@@ -658,3 +659,57 @@ describe('iapl-doctor: first-seen dates', () => {
|
||||
expect(shouldWriteSeen({ sites: 'clients/*' }, {})).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('e-mail: transport, the mail service, Graph, the confirm route', () => {
|
||||
const ids = ['mail-transport', 'mail-relay-state', 'mail-reply-address', 'mail-graph-deprecated', 'mail-relay-route']
|
||||
const relay = (extra: object = {}) => ({ connected: true, disconnected: false, nameReplaced: false, state: 'active', ...extra })
|
||||
const mail = (extra: object = {}) => ({ graphEnv: false, relay: relay(), replyAddress: true, status: null, transport: 'relay', ...extra })
|
||||
const run = async (deep: null | object, files: Record<string, string> = {}) =>
|
||||
rules(await doctor(project({ ...base(), 'src/payload.config.ts': 'iapl({ forms: {} })', ...files }), ids, deep ? { deepStatus: { mail: deep } } : {}))
|
||||
|
||||
test('a healthy site on the mail service, a site on SMTP, and a run without the deep status report nothing', async () => {
|
||||
expect(await run(mail())).toEqual([])
|
||||
expect(await run(mail({ relay: relay({ connected: false, state: undefined }), replyAddress: false, transport: 'smtp' }))).toEqual([])
|
||||
expect(await run(null)).toEqual([])
|
||||
})
|
||||
|
||||
test('mail-transport: nothing set up is an error; failing sends are a warning, an error after a day', async () => {
|
||||
expect(await run(mail({ relay: null, transport: 'none' }))).toEqual(['mail-transport:error'])
|
||||
const failing = (since: string) => mail({ status: { code: 'relay-quota', since, state: 'degraded' } })
|
||||
expect(await run(failing(`${TODAY}T09:00:00.000Z`))).toEqual(['mail-transport:warning'])
|
||||
expect(await run(failing('2026-10-27T09:00:00.000Z'))).toEqual(['mail-transport:error'])
|
||||
})
|
||||
|
||||
test('mail-relay-state: disconnected, suspended, pending, refused, not enrolled yet, a replaced sender name', async () => {
|
||||
expect(await run(mail({ relay: relay({ connected: false, disconnected: true }) }))).toEqual(['mail-relay-state:error'])
|
||||
expect(await run(mail({ relay: relay({ state: 'suspended' }) }))).toEqual(['mail-relay-state:error'])
|
||||
expect(await run(mail({ relay: relay({ state: 'pending' }) }))).toEqual(['mail-relay-state:warning'])
|
||||
expect(await run(mail({ relay: relay({ connected: false, reason: 'redirect', refusal: 'callback-failed', state: undefined }) }))).toEqual(['mail-relay-state:warning'])
|
||||
expect(await run(mail({ relay: relay({ connected: false, state: undefined }) }))).toEqual(['mail-relay-state:info'])
|
||||
expect(await run(mail({ relay: relay({ nameReplaced: true }) }))).toEqual(['mail-relay-state:warning'])
|
||||
})
|
||||
|
||||
test('mail-reply-address: on the mail service without a "Sender address"', async () => {
|
||||
expect(await run(mail({ replyAddress: false }))).toEqual(['mail-reply-address:warning'])
|
||||
})
|
||||
|
||||
test('mail-graph-deprecated: the variables, the transport in use, or graphAdapter in the config', async () => {
|
||||
expect(await run(mail({ graphEnv: true, relay: relay({ connected: false, state: undefined }), transport: 'graph' }))).toEqual(['mail-graph-deprecated:warning'])
|
||||
expect(await run(mail({ graphEnv: true, transport: 'smtp' }))).toEqual(['mail-graph-deprecated:warning'])
|
||||
expect(await run(null, { 'src/payload.config.ts': 'email: graphAdapter()' })).toEqual(['mail-graph-deprecated:warning'])
|
||||
})
|
||||
|
||||
test('mail-relay-route: trailing slashes or another API route keep the service from confirming the site — unless the relay is off', async () => {
|
||||
expect(await run(null, { 'next.config.ts': 'export default { trailingSlash: true }' })).toEqual(['mail-relay-route:warning'])
|
||||
expect(await run(null, { 'src/payload.config.ts': "buildConfig({ routes: { api: '/cms-api' } })" })).toEqual(['mail-relay-route:warning'])
|
||||
expect(await run(null, { 'next.config.ts': 'export default { trailingSlash: true }', 'src/payload.config.ts': 'iapl({ mail: { relay: false } })' })).toEqual([])
|
||||
})
|
||||
|
||||
test('every rule is listed and documented in doctor.md', () => {
|
||||
const doc = readFileSync(path.join(packageRoot, 'docs/doctor.md'), 'utf8')
|
||||
for (const id of ids) {
|
||||
expect(doctorRules.some((r) => r.id === id)).toBe(true)
|
||||
expect(doc).toContain(`\`${id}\``)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user