|
1 | 1 | import { assert, assertMatch, assertThrows } from "@std/assert"; |
2 | 2 | import { hash, verify } from "./hash.ts"; |
3 | 3 |
|
4 | | -Deno.test("hash", async (t) => { |
5 | | - await t.step("unsupported", () => { |
6 | | - // deno-lint-ignore ban-ts-comment |
7 | | - // @ts-ignore |
8 | | - assertThrows(() => hash("unsupported", "password")); |
9 | | - // deno-lint-ignore ban-ts-comment |
10 | | - // @ts-ignore |
11 | | - assertThrows(() => verify("unsupported", "password", "")); |
12 | | - }); |
| 4 | +Deno.test("hash() and verify() with unsupported", () => { |
| 5 | + // deno-lint-ignore ban-ts-comment |
| 6 | + // @ts-ignore |
| 7 | + assertThrows(() => hash("unsupported", "password")); |
| 8 | + // deno-lint-ignore ban-ts-comment |
| 9 | + // @ts-ignore |
| 10 | + assertThrows(() => verify("unsupported", "password", "")); |
| 11 | +}); |
13 | 12 |
|
14 | | - await t.step("argon2", () => { |
15 | | - const h1 = hash("argon2", "password"); |
16 | | - assertMatch(h1, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/); |
17 | | - assert(verify("argon2", "password", h1)); |
18 | | - const h2 = hash({ name: "argon2" }, "password"); |
19 | | - assertMatch(h2, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/); |
20 | | - assert(verify({ name: "argon2" }, "password", h2)); |
21 | | - }); |
| 13 | +Deno.test("hash() and verify() with argon2", () => { |
| 14 | + const h1 = hash("argon2", "password"); |
| 15 | + assertMatch(h1, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/); |
| 16 | + assert(verify("argon2", "password", h1)); |
| 17 | + const h2 = hash({ name: "argon2" }, "password"); |
| 18 | + assertMatch(h2, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/); |
| 19 | + assert(verify({ name: "argon2" }, "password", h2)); |
| 20 | +}); |
22 | 21 |
|
23 | | - await t.step("bcrypt", () => { |
24 | | - const h1 = hash("bcrypt", "password"); |
25 | | - assertMatch(h1, /^\$2b\$12\$/); |
26 | | - assert(verify("bcrypt", "password", h1)); |
27 | | - const h2 = hash({ name: "bcrypt" }, "password"); |
28 | | - assertMatch(h2, /^\$2b\$12\$/); |
29 | | - assert(verify({ name: "bcrypt" }, "password", h2)); |
30 | | - }); |
| 22 | +Deno.test("hash() and verify() with bcrypt", () => { |
| 23 | + const h1 = hash("bcrypt", "password"); |
| 24 | + assertMatch(h1, /^\$2b\$12\$/); |
| 25 | + assert(verify("bcrypt", "password", h1)); |
| 26 | + const h2 = hash({ name: "bcrypt" }, "password"); |
| 27 | + assertMatch(h2, /^\$2b\$12\$/); |
| 28 | + assert(verify({ name: "bcrypt" }, "password", h2)); |
| 29 | +}); |
31 | 30 |
|
32 | | - await t.step("scrypt", () => { |
33 | | - const h1 = hash("scrypt", "password"); |
34 | | - assertMatch(h1, /^\$scrypt\$ln=17,r=8,p=1\$/); |
35 | | - assert(verify("scrypt", "password", h1)); |
36 | | - const h2 = hash({ name: "scrypt" }, "password"); |
37 | | - assertMatch(h2, /^\$scrypt\$ln=17,r=8,p=1\$/); |
38 | | - assert(verify({ name: "scrypt" }, "password", h2)); |
39 | | - }); |
| 31 | +Deno.test("hash() and verify() with scrypt", () => { |
| 32 | + const h1 = hash("scrypt", "password"); |
| 33 | + assertMatch(h1, /^\$scrypt\$ln=17,r=8,p=1\$/); |
| 34 | + assert(verify("scrypt", "password", h1)); |
| 35 | + const h2 = hash({ name: "scrypt" }, "password"); |
| 36 | + assertMatch(h2, /^\$scrypt\$ln=17,r=8,p=1\$/); |
| 37 | + assert(verify({ name: "scrypt" }, "password", h2)); |
40 | 38 | }); |
0 commit comments