Mail relay: tests count the account rules' own hooks, reference index, doctor fixture
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
2cceceffd0
commit
ebfedb03d9
@@ -29,6 +29,12 @@ import { testDatabase } from './http/db.js'
|
||||
import { cookiesOf, startPayloadServer, type TestServer } from './http/server.js'
|
||||
import { totp } from './http/totp.js'
|
||||
|
||||
/**
|
||||
* A `beforeOperation` hook of the account rules. Every auth collection also carries the mark that tells the mail
|
||||
* service what Payload's own account mail is (modules/email/relay/accountMail.ts): that one is not counted here.
|
||||
*/
|
||||
const ruleHook = (hook: unknown) => !(hook as Record<symbol, unknown>)[Symbol.for('iapl.accountMailMark')]
|
||||
|
||||
const TOTP_SECRET = 'JBSWY3DPEHPK3PXP'
|
||||
|
||||
/** A plugin the project lists AFTER iapl: its auth collections did not exist when iapl ran (review round 2, R2-3). */
|
||||
@@ -484,7 +490,7 @@ export function accountRulesSuite(twoFactor: boolean): void {
|
||||
expect(checkPassword('abcd', { minLength: 4 })).toBeNull()
|
||||
expect(checkPassword('[email protected] ', { email: '[email protected]', minLength: 4 })).toBe('email')
|
||||
const hooks = async (options: Record<string, unknown>) =>
|
||||
(await iapl({ access: { authCollection: 'users' }, i18n, twoFactor: false, ...options } as never)({ admin: { user: 'users' }, collections: [{ slug: 'customers', auth: true, fields: [] }], secret: 'x' } as unknown as Config)).collections!.map((c) => [c.slug, c.hooks?.beforeOperation?.length ?? 0])
|
||||
(await iapl({ access: { authCollection: 'users' }, i18n, twoFactor: false, ...options } as never)({ admin: { user: 'users' }, collections: [{ slug: 'customers', auth: true, fields: [] }], secret: 'x' } as unknown as Config)).collections!.map((c) => [c.slug, (c.hooks?.beforeOperation ?? []).filter(ruleHook).length])
|
||||
expect(await hooks({})).toEqual([['customers', 0], ['users', 1]])
|
||||
expect(await hooks({ accounts: { password: false } })).toEqual([['customers', 0], ['users', 0]])
|
||||
expect(await hooks({ accounts: false })).toEqual([['customers', 0], ['users', 0]])
|
||||
@@ -621,7 +627,7 @@ export function accountRulesSuite(twoFactor: boolean): void {
|
||||
})
|
||||
|
||||
test('the switches', async () => {
|
||||
const guards = (config: Config, slug: string) => of(config, slug).hooks?.beforeOperation?.length ?? 0
|
||||
const guards = (config: Config, slug: string) => (of(config, slug).hooks?.beforeOperation ?? []).filter(ruleHook).length
|
||||
const firstUser = (config: Config, slug: string) => (of(config, slug).endpoints || []).filter((e) => e.path === '/first-register').length
|
||||
const on = await build({})
|
||||
// staff collections: the password rule; every auth collection: the first-user endpoint
|
||||
|
||||
+1
-1
@@ -701,7 +701,7 @@ describe('e-mail: transport, the mail service, Graph, the confirm route', () =>
|
||||
|
||||
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, { 'src/payload.config.ts': "export default { plugins: [iapl({})], 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([])
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user