|
6 | 6 | getPasswordMethod,
|
7 | 7 | hashLegacy,
|
8 | 8 | isHashLegacyMatch,
|
| 9 | + isCookieValid, |
9 | 10 | } from "../../../src/node/util"
|
10 | 11 |
|
11 | 12 | describe("getEnvPaths", () => {
|
@@ -234,7 +235,7 @@ describe("getPasswordMethod", () => {
|
234 | 235 | })
|
235 | 236 | })
|
236 | 237 |
|
237 |
| -describe.only("handlePasswordValidation", () => { |
| 238 | +describe("handlePasswordValidation", () => { |
238 | 239 | it("should return true with a hashedPassword for a PLAIN_TEXT password", async () => {
|
239 | 240 | const p = "password"
|
240 | 241 | const passwordValidation = await handlePasswordValidation({
|
@@ -322,3 +323,62 @@ describe.only("handlePasswordValidation", () => {
|
322 | 323 | expect(matchesHash).toBe(false)
|
323 | 324 | })
|
324 | 325 | })
|
| 326 | + |
| 327 | +describe.only("isCookieValid", () => { |
| 328 | + it("should be valid if hashed-password for SHA256 matches cookie.key", async () => { |
| 329 | + const isValid = await isCookieValid({ |
| 330 | + passwordMethod: "SHA256", |
| 331 | + cookieKey: "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af", |
| 332 | + hashedPasswordFromArgs: "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af", |
| 333 | + passwordFromArgs: undefined, |
| 334 | + }) |
| 335 | + expect(isValid).toBe(true) |
| 336 | + }) |
| 337 | + it("should be invalid if hashed-password for SHA256 does not match cookie.key", async () => { |
| 338 | + const isValid = await isCookieValid({ |
| 339 | + passwordMethod: "SHA256", |
| 340 | + cookieKey: "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb9442bb6f8f8f07af", |
| 341 | + hashedPasswordFromArgs: "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af", |
| 342 | + passwordFromArgs: undefined, |
| 343 | + }) |
| 344 | + expect(isValid).toBe(false) |
| 345 | + }) |
| 346 | + it("should be valid if hashed-password for ARGON2 matches cookie.key", async () => { |
| 347 | + const isValid = await isCookieValid({ |
| 348 | + passwordMethod: "ARGON2", |
| 349 | + cookieKey: "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY", |
| 350 | + hashedPasswordFromArgs: |
| 351 | + "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY", |
| 352 | + passwordFromArgs: undefined, |
| 353 | + }) |
| 354 | + expect(isValid).toBe(true) |
| 355 | + }) |
| 356 | + it("should be invalid if hashed-password for ARGON2 does not match cookie.key", async () => { |
| 357 | + const isValid = await isCookieValid({ |
| 358 | + passwordMethod: "ARGON2", |
| 359 | + cookieKey: "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9H", |
| 360 | + hashedPasswordFromArgs: |
| 361 | + "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY", |
| 362 | + passwordFromArgs: undefined, |
| 363 | + }) |
| 364 | + expect(isValid).toBe(false) |
| 365 | + }) |
| 366 | + it("should be valid if password for PLAIN_TEXT matches cookie.key", async () => { |
| 367 | + const isValid = await isCookieValid({ |
| 368 | + passwordMethod: "PLAIN_TEXT", |
| 369 | + cookieKey: "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY", |
| 370 | + passwordFromArgs: "password", |
| 371 | + hashedPasswordFromArgs: undefined, |
| 372 | + }) |
| 373 | + expect(isValid).toBe(true) |
| 374 | + }) |
| 375 | + it("should be invalid if hashed-password for PLAIN_TEXT does not match cookie.key", async () => { |
| 376 | + const isValid = await isCookieValid({ |
| 377 | + passwordMethod: "PLAIN_TEXT", |
| 378 | + cookieKey: "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9H", |
| 379 | + passwordFromArgs: "password1234", |
| 380 | + hashedPasswordFromArgs: undefined, |
| 381 | + }) |
| 382 | + expect(isValid).toBe(false) |
| 383 | + }) |
| 384 | +}) |
0 commit comments