From d75883bcc6b7c0f9417bdf5af6dfffcdd0b906c2 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 6 Jun 2022 14:20:22 -0400 Subject: [PATCH] feat: add additional test for handlePasswordValidation (#5243) --- test/unit/node/util.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit/node/util.test.ts b/test/unit/node/util.test.ts index 1455a7e07..e37aeac92 100644 --- a/test/unit/node/util.test.ts +++ b/test/unit/node/util.test.ts @@ -349,6 +349,22 @@ describe("isCookieValid", () => { }) expect(isValid).toBe(false) }) + it("should return false and empty string as hashedPassword when passwordMethod is invalid", async () => { + const p = "password1" + const passwordValidation = await util.handlePasswordValidation({ + // @ts-expect-error although this shouldn't ever happen, it ensures the default case in this function + // works as expected. + passwordMethod: "INVALID", + passwordFromRequestBody: p, + passwordFromArgs: undefined, + hashedPasswordFromArgs: undefined, + }) + + const matchesHash = await util.isHashMatch(p, passwordValidation.hashedPassword) + + expect(passwordValidation.isPasswordValid).toBe(false) + expect(matchesHash).toBe(false) + }) }) describe("sanitizeString", () => {