feat: add 2FA, secure cookies and publishing tools
This commit is contained in:
33
tests/auth.test.ts
Normal file
33
tests/auth.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user