Skip to content

Commit 33f2c43

Browse files
committed
Improved parallelism of tests
1 parent 86eca36 commit 33f2c43

4 files changed

Lines changed: 94 additions & 102 deletions

File tree

crypto/hash.test.ts

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
import { assert, assertMatch, assertThrows } from "@std/assert";
22
import { hash, verify } from "./hash.ts";
33

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+
});
1312

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+
});
2221

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+
});
3130

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));
4038
});

crypto/hash/argon2.test.ts

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
import { assert, assertMatch } from "@std/assert";
22
import { type Argon2Options, hash, verify } from "./argon2.ts";
33

4-
Deno.test("Argon2", async (t) => {
5-
await t.step("defaults", () => {
6-
const h = hash("password", {});
7-
assertMatch(h, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/);
8-
assert(verify("password", h, {}));
9-
});
4+
Deno.test("hash() and verify() with default arguments", () => {
5+
const h = hash("password", {});
6+
assertMatch(h, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/);
7+
assert(verify("password", h, {}));
8+
});
109

11-
await t.step("Argon2i", () => {
12-
const o = { algorithm: "argon2i" } satisfies Argon2Options;
13-
const h = hash("password", o);
14-
assertMatch(h, /^\$argon2i\$v=19\$m=19456,t=2,p=1\$/);
15-
assert(verify("password", h, o));
16-
});
10+
Deno.test("hash() and verify() with argon2i", () => {
11+
const o = { algorithm: "argon2i" } satisfies Argon2Options;
12+
const h = hash("password", o);
13+
assertMatch(h, /^\$argon2i\$v=19\$m=19456,t=2,p=1\$/);
14+
assert(verify("password", h, o));
15+
});
1716

18-
await t.step("Argon2d", () => {
19-
const o = { algorithm: "argon2d" } satisfies Argon2Options;
20-
const h = hash("password", o);
21-
assertMatch(h, /^\$argon2d\$v=19\$m=19456,t=2,p=1\$/);
22-
assert(verify("password", h, o));
23-
});
17+
Deno.test("hash() and verify() with argon2d", () => {
18+
const o = { algorithm: "argon2d" } satisfies Argon2Options;
19+
const h = hash("password", o);
20+
assertMatch(h, /^\$argon2d\$v=19\$m=19456,t=2,p=1\$/);
21+
assert(verify("password", h, o));
22+
});
2423

25-
await t.step("wrong algoritm", () => {
26-
// deno-lint-ignore ban-ts-comment
27-
// @ts-ignore
28-
const o = { algorithm: "asdfasdf" } as Argon2Options;
29-
const h = hash("password", o);
30-
assertMatch(h, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/);
31-
assert(verify("password", h, o));
32-
});
24+
Deno.test("hash() and verify() with wrong algorithm", () => {
25+
// deno-lint-ignore ban-ts-comment
26+
// @ts-ignore
27+
const o = { algorithm: "asdfasdf" } as Argon2Options;
28+
const h = hash("password", o);
29+
assertMatch(h, /^\$argon2id\$v=19\$m=19456,t=2,p=1\$/);
30+
assert(verify("password", h, o));
31+
});
3332

34-
await t.step("all options", () => {
35-
const o = {
36-
algorithm: "argon2id",
37-
memoryCost: 10000,
38-
timeCost: 3,
39-
parallelism: 2,
40-
outputLength: 16,
41-
} satisfies Argon2Options;
42-
const h = hash("password", o);
43-
assertMatch(h, /^\$argon2id\$v=19\$m=10000,t=3,p=2\$/);
44-
assert(verify("password", h, o));
45-
});
33+
Deno.test("hash() and verify() with all options", () => {
34+
const o = {
35+
algorithm: "argon2id",
36+
memoryCost: 10000,
37+
timeCost: 3,
38+
parallelism: 2,
39+
outputLength: 16,
40+
} satisfies Argon2Options;
41+
const h = hash("password", o);
42+
assertMatch(h, /^\$argon2id\$v=19\$m=10000,t=3,p=2\$/);
43+
assert(verify("password", h, o));
4644
});

crypto/hash/bcrypt.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { assert, assertMatch } from "@std/assert";
22
import { type BcryptOptions, hash, verify } from "./bcrypt.ts";
33

4-
Deno.test("Bcrypt", async (t) => {
5-
await t.step("defaults", () => {
6-
const o = {} as BcryptOptions;
7-
const h = hash("password", o);
8-
assertMatch(h, /^\$2b\$12\$/);
9-
assert(verify("password", h, o));
10-
});
4+
Deno.test("hash() and verify() with defaults", () => {
5+
const o = {} as BcryptOptions;
6+
const h = hash("password", o);
7+
assertMatch(h, /^\$2b\$12\$/);
8+
assert(verify("password", h, o));
9+
});
1110

12-
await t.step("cost 4", () => {
13-
const o = { cost: 4 } as BcryptOptions;
14-
const h = hash("password", o);
15-
assertMatch(h, /^\$2b\$04\$/);
16-
assert(verify("password", h, o));
17-
});
11+
Deno.test("hash() and verify() with all options", () => {
12+
const o = { cost: 4 } as BcryptOptions;
13+
const h = hash("password", o);
14+
assertMatch(h, /^\$2b\$04\$/);
15+
assert(verify("password", h, o));
1816
});

crypto/hash/scrypt.test.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { assert, assertMatch } from "@std/assert";
22
import { hash, type ScryptOptions, verify } from "./scrypt.ts";
33

4-
Deno.test("Scrypt", async (t) => {
5-
await t.step("defaults", () => {
6-
const o = {} as ScryptOptions;
7-
const h = hash("password", o);
8-
assertMatch(h, /^\$scrypt\$ln=17,r=8,p=1\$/);
9-
assert(verify("password", h, o));
10-
});
4+
Deno.test("hash() and verify() with defaults", () => {
5+
const o = {} as ScryptOptions;
6+
const h = hash("password", o);
7+
assertMatch(h, /^\$scrypt\$ln=17,r=8,p=1\$/);
8+
assert(verify("password", h, o));
9+
});
1110

12-
await t.step("all config", () => {
13-
const o = {
14-
logN: 1,
15-
blockSize: 1,
16-
parallelism: 2,
17-
keyLenght: 16,
18-
} as ScryptOptions;
19-
const h = hash("password", o);
20-
assertMatch(h, /^\$scrypt\$ln=1,r=1,p=2\$/);
21-
assert(verify("password", h, o));
22-
});
11+
Deno.test("hash() and verify() with all options", () => {
12+
const o = {
13+
logN: 1,
14+
blockSize: 1,
15+
parallelism: 2,
16+
keyLenght: 16,
17+
} as ScryptOptions;
18+
const h = hash("password", o);
19+
assertMatch(h, /^\$scrypt\$ln=1,r=1,p=2\$/);
20+
assert(verify("password", h, o));
2321
});

0 commit comments

Comments
 (0)