/** accounts: { signInLimit: false, signInSameOrigin: false, confirmOwnChanges: false } — Payload's behaviour as before 1.18.0. */ import { describe, expect, test, vi } from 'vitest' import { iapl } from '../src/plugin.js' import { FOREIGN, PASSWORD, signInSite } from './signInRulesSuite.js' vi.mock('server-only', () => ({})) vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock) const { call, idOf, login, session, state } = signInSite({ off: true }) describe('the sign-in rules switched off', () => { test("Payload's lock (5 from anywhere), foreign sign-in taken, own e-mail without a question", async () => { expect((await login('admin2@example.com', PASSWORD, '203.0.113.1', FOREIGN)).status).toBe(200) for (let i = 0; i < 5; i++) {await login('owner@example.com', 'a-wrong-password', '198.51.100.95')} const locked = await login('owner@example.com', PASSWORD, '203.0.113.95') expect(locked.status).toBe(401) expect((state.payload.collections['users' as never].config.auth as { maxLoginAttempts: number }).maxLoginAttempts).toBe(5) const cookie = await session('editor@example.com', PASSWORD, '203.0.113.96') expect((await call(`/users/${await idOf('editor@example.com')}`, { email: 'y@example.com' }, { cookie }, 'PATCH')).status).toBe(200) }) test('values nobody understands stop the start', async () => { const i18n = { defaultLocale: 'en', locales: [{ code: 'en', label: 'English' }] } const start = (accounts: unknown) => (async () => iapl({ accounts, i18n } as never)({ collections: [], secret: 'x' } as never))() await expect(start({ signInLimit: 0 })).rejects.toThrow(/accounts\.signInLimit must be/) await expect(start({ signInLimit: { perAddress: 0 } })).rejects.toThrow(/perAddress must be/) await expect(start({ signInSameOrigin: 'false' })).rejects.toThrow(/signInSameOrigin must be/) await expect(start({ confirmOwnChanges: 'no' })).rejects.toThrow(/confirmOwnChanges must be/) }) })