Archived
1
0

refactor: add functions to check hash password

This commit is contained in:
Joe Previte
2021-05-19 16:17:32 -07:00
parent f35120c0a3
commit aaf044728f
4 changed files with 74 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { hash } from "../../../src/node/util"
import { hash, isHashMatch, hashLegacy, isHashLegacyMatch } from "../../../src/node/util"
describe("getEnvPaths", () => {
describe("on darwin", () => {
@ -155,3 +155,37 @@ describe("hash", () => {
expect(hashed).not.toBe(plainTextPassword)
})
})
describe("isHashMatch", () => {
it("should return true if the password matches the hash", () => {
const password = "password123"
const _hash = hash(password)
expect(isHashMatch(password, _hash)).toBe(true)
})
it("should return false if the password does not match the hash", () => {
const password = "password123"
const _hash = hash(password)
expect(isHashMatch("otherPassword123", _hash)).toBe(false)
})
})
describe("hashLegacy", () => {
it("should return a hash of the string passed in", () => {
const plainTextPassword = "mySecretPassword123"
const hashed = hashLegacy(plainTextPassword)
expect(hashed).not.toBe(plainTextPassword)
})
})
describe("isHashLegacyMatchh", () => {
it("should return true if is match", () => {
const password = "password123"
const _hash = hashLegacy(password)
expect(isHashLegacyMatch(password, _hash)).toBe(true)
})
it("should return false if is match", () => {
const password = "password123"
const _hash = hashLegacy(password)
expect(isHashLegacyMatch("otherPassword123", _hash)).toBe(false)
})
})