autobaan/tests/common/password.test.ts
Collin Duncan 3247ca5315
Lots of changes to project structure
First integration of requester and scheduler workers
Added password hashing functions
Adding initial database integration
2023-05-23 15:09:11 -05:00

27 lines
921 B
TypeScript

import * as password from '../../src/common/password'
describe('password', () => {
describe('generateSalt', () => {
test('should generate salt of 32 bytes', async () => {
const saltBuffer = await password.generateSalt()
expect(saltBuffer.length).toEqual(32)
})
})
describe('generateHash', () => {
test('should generate a hash of 64 bytes', async () => {
const saltBuffer = Buffer.alloc(32, 1)
const hash = await password.generateHash('abc123', saltBuffer)
expect(hash).toEqual(
'$argon2id$v=19$m=16384,t=2,p=1$AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE$jF3SXC/JRI9d1jr48kQkvWaSVlf3XGNSRUCNnNp5IaI'
)
})
})
describe('hashPassword', () => {
test('it should create salt and hash password', async () => {
const hash = await password.hashPassword('abc123')
expect(hash).toMatch(/^\$argon2id\$v=19\$m=16384,t=2,p=1\$.+$/)
})
})
})