Mail relay: the access-key field is off by default (mail.relay.accessKeyField)
A token issued by hand is set by a developer: setRelayToken() from a script, or mail.relay.token. The panel field and its route take a token only when the project switches the field on. Docs and AGENT.md say when such a token is needed and how to set it; a token of another host is refused on every way in. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
1a11cefffa
commit
edee3a321f
@@ -1013,6 +1013,9 @@ describe('what the panel is told', () => {
|
||||
const smtp = relayPayload({ integrations: { smtpHost: 'smtp.example.com', smtpPassword: 'x', smtpUser: 'u' } })
|
||||
expect((await mailPanelState(smtp, {})).transport).toBe('smtp')
|
||||
expect(await mailPanelState(fresh, false)).toMatchObject({ relay: null, transport: 'none' })
|
||||
// the access-key field is the project's switch, off by default
|
||||
expect(state.accessKeyField).toBeUndefined()
|
||||
expect((await mailPanelState(fresh, { accessKeyField: true })).accessKeyField).toBe(true)
|
||||
expect(JSON.stringify([state])).not.toContain('ims_')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -47,6 +47,9 @@ const fake = createFakeRelay({
|
||||
},
|
||||
})
|
||||
|
||||
// the access-key field is off by default; one test switches it on (the plugin reads the options on every request)
|
||||
const relayOptions: { accessKeyField?: boolean; fetchImpl: typeof fetch; url: string } = { fetchImpl: fake.fetch, url: fake.url }
|
||||
|
||||
const makeConfig = (mail?: Parameters<typeof iapl>[0]['mail'], name = 'relayhttp') =>
|
||||
buildTestConfig({
|
||||
admin: { user: 'users' },
|
||||
@@ -82,7 +85,7 @@ const api = (pathname: string, headers: Record<string, string> = {}, init: Reque
|
||||
const post = (pathname: string, headers: Record<string, string>, body?: unknown) => api(pathname, headers, { body: body === undefined ? undefined : JSON.stringify(body), method: 'POST' })
|
||||
|
||||
beforeAll(async () => {
|
||||
const config = makeConfig({ relay: { fetchImpl: fake.fetch, url: fake.url } })
|
||||
const config = makeConfig({ relay: relayOptions })
|
||||
payload = await getPayload({ config })
|
||||
server = await startPayloadServer(config)
|
||||
await payload.updateGlobal({ slug: 'site-integrations' as never, data: { smtpFromAddress: '[email protected]', smtpFromName: 'Kancelaria Example' } as never })
|
||||
@@ -205,8 +208,16 @@ 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
|
||||
// by default there is no access-key field: the state does not offer it and the route takes no token at all
|
||||
const mine = (await readRelayStore(payload)).token
|
||||
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)
|
||||
expect((await readRelayStore(payload)).token).toBe(mine)
|
||||
// a project switches the field on: mail.relay.accessKeyField
|
||||
relayOptions.accessKeyField = true
|
||||
expect(((await (await api('/iapl/mail-relay/status', admin)).json()) as { accessKeyField?: boolean }).accessKeyField).toBe(true)
|
||||
// a token of another site pasted while the site is connected: refused, and the site's own token stays
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user