/** Sign-in rules of the staff collections with twoFactor: false (signInRulesSuite.ts). */ import { describe, expect, test, vi } from 'vitest' import { FOREIGN, PASSWORD, signInSite } from './signInRulesSuite.js' vi.mock('server-only', () => ({})) const { call, gqlLogin, idOf, login, session } = signInSite({ twoFactor: false }) describe('sign-in rules without 2FA', () => { test('a stranger\'s five failures do not keep the owner out; foreign origin refused; own e-mail needs the current password', async () => { for (let i = 0; i < 5; i++) {await login('owner@example.com', 'a-wrong-password', '198.51.100.90')} expect((await login('owner@example.com', PASSWORD, '198.51.100.90')).status).toBe(429) expect((await login('owner@example.com', PASSWORD, '203.0.113.90')).status).toBe(200) expect((await gqlLogin('owner@example.com', PASSWORD, '203.0.113.91', FOREIGN)).status).toBe(403) const cookie = await session('editor@example.com', PASSWORD, '203.0.113.92') const id = await idOf('editor@example.com') expect((await call(`/users/${id}`, { email: 'x@example.com' }, { cookie }, 'PATCH')).status).toBe(400) expect((await call(`/users/${id}`, { currentPassword: PASSWORD, email: 'x@example.com' }, { cookie }, 'PATCH')).status).toBe(200) }) })