WIP 2.0.0: v1 removed; Argon2id passwords; node-fetch gone

- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks
  (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages
  (308s, one-click POST). 43 v1 route files and deprecation.ts removed;
  /docs redirects to /docs/v2; API_DOCUMENTATION.md points there.
- Read-only and impersonation lists name v2 paths only. The campus
  scope route test now runs over v2 routes (v2CampusScope.test.ts).
- Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still
  sign in and are re-hashed at the next sign-in.
- e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2.
- MIGRATING-TO-2.md with the full v1 -> v2 table.
- Two documented response shapes corrected.

Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 16:35:06 +02:00
co-authored by Claude Opus 5.5
parent 57b3c41067
commit 3f59164ab2
97 changed files with 1099 additions and 4398 deletions
@@ -9,7 +9,8 @@ const mockDb = {
};
jest.mock('../src/config/db', () => mockDb);
const mockCompare = jest.fn(async () => false);
jest.mock('../src/config/auth', () => ({ comparePassword: (...a: unknown[]) => (mockCompare as jest.Mock)(...a), hashPassword: async () => 'stand-in-hash', generateToken: () => 't' }));
const mockNeedsRehash = jest.fn(() => false);
jest.mock('../src/config/auth', () => ({ comparePassword: (...a: unknown[]) => (mockCompare as jest.Mock)(...a), hashPassword: async () => 'stand-in-hash', generateToken: () => 't', needsRehash: (...a: unknown[]) => (mockNeedsRehash as jest.Mock)(...a) }));
const mockSendMail = jest.fn(async () => undefined);
jest.mock('../src/utils/email', () => ({ sendMail: (...a: unknown[]) => (mockSendMail as jest.Mock)(...a), buildPasswordResetEmail: () => ({ html: '', text: 'reset' }) }));
jest.mock('../src/utils/notify', () => ({ waText: async () => undefined }));
@@ -81,3 +82,27 @@ describe('sign-in', () => {
expect(mockCompare).toHaveBeenCalledWith('guess', 'stand-in-hash');
});
});
describe('password re-hashing (2.0)', () => {
// Stop logIn at its first save, to see what it saves.
const firstSave = () => new Promise<Record<string, unknown>>(resolve => {
mockDb.user.update.mockImplementationOnce(async (args: { data: Record<string, unknown> }) => { resolve(args.data); throw new Error('stop'); });
});
test('a right password on an old hash saves a new hash', async () => {
mockDb.user.findFirst.mockResolvedValueOnce({ ...realUser, password: '$2a$10$old' });
mockCompare.mockResolvedValueOnce(true as never);
mockNeedsRehash.mockReturnValueOnce(true);
const saved = firstSave();
await logIn({ identifier: realUser.email, password: 'right' }, { ip: '127.0.0.1', userAgent: 'test' } as never).catch(() => undefined);
expect(await saved).toMatchObject({ failedAttempts: 0, password: 'stand-in-hash' });
});
test('a current hash is left as it is', async () => {
mockDb.user.findFirst.mockResolvedValueOnce(realUser);
mockCompare.mockResolvedValueOnce(true as never);
const saved = firstSave();
await logIn({ identifier: realUser.email, password: 'right' }, { ip: '127.0.0.1', userAgent: 'test' } as never).catch(() => undefined);
expect(await saved).not.toHaveProperty('password');
});
});