Skip to content

Commit 1b84811

Browse files
committed
feat: check for empty str in isHashMatch
1 parent 079564a commit 1b84811

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/node/cli.ts

+8
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export const parse = (
263263
if (opts?.configFile) {
264264
msg = `error reading ${opts.configFile}: ${msg}`
265265
}
266+
266267
return new Error(msg)
267268
}
268269

@@ -286,7 +287,14 @@ export const parse = (
286287
const split = splitOnFirstEquals(arg.replace(/^--/, ""))
287288
key = split[0] as keyof Args
288289
value = split[1]
290+
} else {
291+
const short = arg.replace(/^-/, "")
292+
const pair = Object.entries(options).find(([, v]) => v.short === short)
293+
if (pair) {
294+
key = pair[0] as keyof Args
295+
}
289296
}
297+
290298
if (!key || !options[key]) {
291299
throw error(`Unknown option ${arg}`)
292300
}

src/node/util.ts

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export const hash = async (password: string): Promise<string> => {
134134
* Used to verify if the password matches the hash
135135
*/
136136
export const isHashMatch = async (password: string, hash: string) => {
137+
if (password === "" || hash === "") {
138+
return false
139+
}
137140
try {
138141
return await argon2.verify(hash, password)
139142
} catch (error) {

test/unit/node/util.test.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ describe("isHashMatch", () => {
185185
const actual = await isHashMatch(password, _hash)
186186
expect(actual).toBe(true)
187187
})
188+
it("should return false if the password is empty", async () => {
189+
const password = ""
190+
const _hash = "$argon2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
191+
const actual = await isHashMatch(password, _hash)
192+
expect(actual).toBe(false)
193+
})
194+
it("should return false if the hash is empty", async () => {
195+
const password = "hellowpasssword"
196+
const _hash = ""
197+
const actual = await isHashMatch(password, _hash)
198+
expect(actual).toBe(false)
199+
})
188200
})
189201

190202
describe("hashLegacy", () => {
@@ -325,7 +337,7 @@ describe("handlePasswordValidation", () => {
325337
})
326338
})
327339

328-
describe.only("isCookieValid", () => {
340+
describe("isCookieValid", () => {
329341
it("should be valid if hashed-password for SHA256 matches cookie.key", async () => {
330342
const isValid = await isCookieValid({
331343
passwordMethod: "SHA256",
@@ -384,7 +396,7 @@ describe.only("isCookieValid", () => {
384396
})
385397
})
386398

387-
describe.only("sanitizeString", () => {
399+
describe("sanitizeString", () => {
388400
it("should return an empty string if passed a type other than a string", () => {
389401
expect(sanitizeString({} as string)).toBe("")
390402
})

0 commit comments

Comments
 (0)