import { describe, it, expect } from 'vitest';
import { generateToken, validateToken } from '../../security/csrf.js';
describe('generateToken', () => {
    it('returns a 64-char hex string', async () => {
        const token = await generateToken();
        expect(token).toHaveLength(64);
        expect(token).toMatch(/^[0-9a-f]{64}$/);
    });
    it('generates unique tokens on each call', async () => {
        const token1 = await generateToken();
        const token2 = await generateToken();
        expect(token1).not.toBe(token2);
    });
});
describe('validateToken', () => {
    it('returns true for matching tokens', async () => {
        const token = await generateToken();
        expect(validateToken(token, token)).toBe(true);
    });
    it('returns true for identical manually-constructed tokens', () => {
        const token = 'a'.repeat(64);
        expect(validateToken(token, token)).toBe(true);
    });
    it('returns false for different tokens of the same length', async () => {
        const token1 = await generateToken();
        const token2 = await generateToken();
        expect(validateToken(token1, token2)).toBe(false);
    });
    it('returns false for tokens of different lengths', () => {
        const short = 'abcdef';
        const long = 'abcdefabcdef';
        expect(validateToken(short, long)).toBe(false);
    });
    it('returns false when one token is empty', async () => {
        const token = await generateToken();
        expect(validateToken(token, '')).toBe(false);
        expect(validateToken('', token)).toBe(false);
    });
});
//# sourceMappingURL=csrf.test.js.map