feat: add 2FA, secure cookies and publishing tools
All checks were successful
CI / Validate frontend and API (push) Successful in 3m5s
CI / Build and publish Docker images (push) Successful in 1m42s

This commit is contained in:
Cauê Faleiros
2026-11-06 10:29:37 -03:00
parent fff63f5efa
commit 50905eefd7
40 changed files with 3493 additions and 215 deletions

33
tests/auth.test.ts Normal file
View File

@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest';
import { createRawToken, hashToken } from '../server/src/auth/account-tokens';
import { hashPassword, verifyPassword } from '../server/src/auth/passwords';
describe('account tokens', () => {
it('produces unique URL-safe tokens', () => {
const first = createRawToken();
const second = createRawToken();
expect(first).not.toBe(second);
expect(first).toMatch(/^[A-Za-z0-9_-]+$/);
expect(first.length).toBeGreaterThan(30);
});
it('hashes deterministically without exposing the token', () => {
const token = 'example-token';
expect(hashToken(token)).toBe(hashToken(token));
expect(hashToken(token)).not.toBe(token);
expect(hashToken(token)).toMatch(/^[a-f0-9]{64}$/);
});
});
describe('password hashing', () => {
it('accepts the correct password and rejects others', async () => {
const hash = await hashPassword('Compor@123');
expect(hash).not.toContain('Compor@123');
await expect(verifyPassword('Compor@123', hash)).resolves.toBe(true);
await expect(verifyPassword('wrong-password', hash)).resolves.toBe(false);
});
it('rejects malformed hashes', async () => {
await expect(verifyPassword('Compor@123', 'not-a-hash')).resolves.toBe(false);
});
});