Files
klz-cables.com/.pnpm-store/v10/files/75/5ee41b3005cdff810e2de95117494459869f688ccfeaa60ea8818ac5d5bb2c21793e2f34f1b703a6b7eee3dceaf0f5c3946e61dac3c451e879d208647ce578
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

83 lines
2.5 KiB
Plaintext

import crypto from 'crypto';
import { describe, expect, it } from 'vitest';
import { authenticateLocalStrategy } from './authenticate.js';
// Helper to generate hash/salt like Payload does
const generateHashAndSalt = (password)=>{
const salt = crypto.randomBytes(32).toString('hex');
const hash = crypto.pbkdf2Sync(password, salt, 25000, 512, 'sha256').toString('hex');
return {
hash,
salt
};
};
describe('authenticateLocalStrategy', ()=>{
it('should return doc when password is valid', async ()=>{
const password = 'test-password';
const { hash, salt } = generateHashAndSalt(password);
const doc = {
id: 1,
hash,
salt
};
const result = await authenticateLocalStrategy({
doc,
password
});
expect(result).toEqual(doc);
});
it('should return null when password is invalid', async ()=>{
const { hash, salt } = generateHashAndSalt('correct-password');
const doc = {
id: 1,
hash,
salt
};
const result = await authenticateLocalStrategy({
doc,
password: 'wrong-password'
});
expect(result).toBeNull();
});
it('should return null when salt is missing', async ()=>{
const { hash } = generateHashAndSalt('test-password');
const doc = {
id: 1,
hash
};
const result = await authenticateLocalStrategy({
doc,
password: 'test-password'
});
expect(result).toBeNull();
});
it('should return null when hash is missing', async ()=>{
const { salt } = generateHashAndSalt('test-password');
const doc = {
id: 1,
salt
};
const result = await authenticateLocalStrategy({
doc,
password: 'test-password'
});
expect(result).toBeNull();
});
it('should return null when hash has different length (tampered)', async ()=>{
const password = 'test-password';
const { salt } = generateHashAndSalt(password);
// Truncated hash - different length than expected 512 bytes
const shortHash = 'abcd1234';
const doc = {
id: 1,
hash: shortHash,
salt
};
const result = await authenticateLocalStrategy({
doc,
password
});
expect(result).toBeNull();
});
});
//# sourceMappingURL=authenticate.spec.js.map