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
1 line
3.7 KiB
Plaintext
1 line
3.7 KiB
Plaintext
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.spec.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { authenticateLocalStrategy } from './authenticate.js'\n\n// Helper to generate hash/salt like Payload does\nconst generateHashAndSalt = (password: string): { hash: string; salt: string } => {\n const salt = crypto.randomBytes(32).toString('hex')\n const hash = crypto.pbkdf2Sync(password, salt, 25000, 512, 'sha256').toString('hex')\n return { hash, salt }\n}\n\ndescribe('authenticateLocalStrategy', () => {\n it('should return doc when password is valid', async () => {\n const password = 'test-password'\n const { hash, salt } = generateHashAndSalt(password)\n const doc = { id: 1, hash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password })\n\n expect(result).toEqual(doc)\n })\n\n it('should return null when password is invalid', async () => {\n const { hash, salt } = generateHashAndSalt('correct-password')\n const doc = { id: 1, hash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password: 'wrong-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when salt is missing', async () => {\n const { hash } = generateHashAndSalt('test-password')\n const doc = { id: 1, hash }\n\n const result = await authenticateLocalStrategy({ doc, password: 'test-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when hash is missing', async () => {\n const { salt } = generateHashAndSalt('test-password')\n const doc = { id: 1, salt }\n\n const result = await authenticateLocalStrategy({ doc, password: 'test-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when hash has different length (tampered)', async () => {\n const password = 'test-password'\n const { salt } = generateHashAndSalt(password)\n // Truncated hash - different length than expected 512 bytes\n const shortHash = 'abcd1234'\n const doc = { id: 1, hash: shortHash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password })\n\n expect(result).toBeNull()\n })\n})\n"],"names":["crypto","describe","expect","it","authenticateLocalStrategy","generateHashAndSalt","password","salt","randomBytes","toString","hash","pbkdf2Sync","doc","id","result","toEqual","toBeNull","shortHash"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAE3B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,yBAAyB,QAAQ,oBAAmB;AAE7D,iDAAiD;AACjD,MAAMC,sBAAsB,CAACC;IAC3B,MAAMC,OAAOP,OAAOQ,WAAW,CAAC,IAAIC,QAAQ,CAAC;IAC7C,MAAMC,OAAOV,OAAOW,UAAU,CAACL,UAAUC,MAAM,OAAO,KAAK,UAAUE,QAAQ,CAAC;IAC9E,OAAO;QAAEC;QAAMH;IAAK;AACtB;AAEAN,SAAS,6BAA6B;IACpCE,GAAG,4CAA4C;QAC7C,MAAMG,WAAW;QACjB,MAAM,EAAEI,IAAI,EAAEH,IAAI,EAAE,GAAGF,oBAAoBC;QAC3C,MAAMM,MAAM;YAAEC,IAAI;YAAGH;YAAMH;QAAK;QAEhC,MAAMO,SAAS,MAAMV,0BAA0B;YAAEQ;YAAKN;QAAS;QAE/DJ,OAAOY,QAAQC,OAAO,CAACH;IACzB;IAEAT,GAAG,+CAA+C;QAChD,MAAM,EAAEO,IAAI,EAAEH,IAAI,EAAE,GAAGF,oBAAoB;QAC3C,MAAMO,MAAM;YAAEC,IAAI;YAAGH;YAAMH;QAAK;QAEhC,MAAMO,SAAS,MAAMV,0BAA0B;YAAEQ;YAAKN,UAAU;QAAiB;QAEjFJ,OAAOY,QAAQE,QAAQ;IACzB;IAEAb,GAAG,2CAA2C;QAC5C,MAAM,EAAEO,IAAI,EAAE,GAAGL,oBAAoB;QACrC,MAAMO,MAAM;YAAEC,IAAI;YAAGH;QAAK;QAE1B,MAAMI,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