generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mod_test.ts
61 lines (57 loc) · 1.96 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { assert, assertEquals } from "./deps.ts";
import { hash, verify } from "./mod.ts";
Deno.test("basic hashing - scrypt format", (): void => {
const hashedPassword = hash("test-password");
assert(verify("test-password", hashedPassword));
});
Deno.test("basic hashing - PHC format", (): void => {
const hashedPassword = hash("test-password", undefined, "phc");
assert(verify("test-password", hashedPassword));
});
Deno.test("basic hashing raw", (): void => {
const hashedPassword = hash(
"test-password",
{ salt: "test", logN: 14 }, // the expected hash was generated using the older default parameters, hence logN=14 instead of logN=17
"raw",
);
assertEquals(
hashedPassword,
"zu8gd0RTeX6r0dbNzBv5ZzXOAQo0UnFUw49uRXrPwAlDocpJSA43WEgAcKNlsBhLyA+zVDluz/0GFa1ShAcr6g==",
);
});
// source of this test string: https://github.com/barrysteyn/node-scrypt#what-are-the-essential-properties-for-storing-passwords
Deno.test("verify scrypt string", (): void => {
assert(
verify(
"password1",
"c2NyeXB0AAwAAAAIAAAAATpP+fdQAryDiRmCmcoOrZa2mZ049KdbA/ofTTrATQQ+m0L/gR811d0WQyip6p2skXVEMz2+8U+xGryFu2p0yzfCxYLUrAaIzaZELkN2M6k0",
),
);
});
// source of this test string: https://passlib.readthedocs.io/en/stable/lib/passlib.hash.scrypt.html
Deno.test("verify PHC string", (): void => {
assert(
verify(
"password",
"$scrypt$ln=16,r=8,p=1$aM15713r3Xsvxbi31lqr1Q$nFNh2CVHVjNldFVKDHDlm4CbdRSCdEBsjjJxD+iCs5E",
),
);
});
Deno.test("reject invalid password (PHC)", (): void => {
assertEquals(
verify(
"invalid-password",
"$scrypt$ln=16,r=8,p=1$aM15713r3Xsvxbi31lqr1Q$nFNh2CVHVjNldFVKDHDlm4CbdRSCdEBsjjJxD+iCs5E",
),
false,
);
});
Deno.test("reject invalid password (scrypt)", (): void => {
assertEquals(
verify(
"invalid-password",
"c2NyeXB0AAwAAAAIAAAAATpP+fdQAryDiRmCmcoOrZa2mZ049KdbA/ofTTrATQQ+m0L/gR811d0WQyip6p2skXVEMz2+8U+xGryFu2p0yzfCxYLUrAaIzaZELkN2M6k0",
),
false,
);
});