@@ -0,0 +1,35 @@
|
||||
import {test, expect} from 'bun:test'
|
||||
|
||||
import {pwd} from '../index'
|
||||
|
||||
test('base case', async () => {
|
||||
const password = "AwesomePassword123!"
|
||||
const hash = await pwd.hash(password)
|
||||
const verification = await pwd.verify(password, hash)
|
||||
expect(verification).toBe(true)
|
||||
})
|
||||
|
||||
test('wrong password', async () => {
|
||||
const password1 = "AwesomePassword123!"
|
||||
const password2 = "AwesomePassword321!"
|
||||
expect(password1).not.toEqual(password2)
|
||||
|
||||
const hash = await pwd.hash(password1)
|
||||
const verification = await pwd.verify(password2, hash)
|
||||
expect(verification).toBe(false)
|
||||
})
|
||||
|
||||
test('salt changes', async () => {
|
||||
const password = "AwesomePassword123!"
|
||||
const hash1 = await pwd.hash(password)
|
||||
const hash2 = await pwd.hash(password)
|
||||
expect(hash1).not.toEqual(hash2)
|
||||
})
|
||||
|
||||
test('tampered hash', async () => {
|
||||
const password = "AwesomePassword123"
|
||||
const hash = await pwd.hash(password)
|
||||
const tamperedHash = hash.replace('a', 'b')
|
||||
const verification = await pwd.verify(password, tamperedHash)
|
||||
expect(verification).toBe(false)
|
||||
})
|
||||
Reference in New Issue
Block a user