Skip to content

Commit a95f4d2

Browse files
committed
fix: crypto tests
1 parent 2e6b590 commit a95f4d2

4 files changed

Lines changed: 6 additions & 10 deletions

File tree

new-deepnotes/packages/e2ee/src/derive-group-password.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { describe, expect, it } from "vitest";
2-
import sodium from "libsodium-wrappers-sumo";
32
import { deriveGroupPasswordValues, nanoidToBytes } from "./derive-group-password.js";
43

54
describe("deriveGroupPasswordValues", () => {
6-
it("produces deterministic output for a known group id and password", async () => {
7-
await sodium.ready;
5+
it("produces deterministic output for a known group id and password", () => {
86
const groupId = "V1StGXR8_Z5jdHi6B-myT";
97
const password = "test-password-123";
108

@@ -19,8 +17,7 @@ describe("deriveGroupPasswordValues", () => {
1917
expect(result1.passwordKey.value).toEqual(result2.passwordKey.value);
2018
});
2119

22-
it("uses nanoidToBytes for salt", async () => {
23-
await sodium.ready;
20+
it("uses nanoidToBytes for salt", () => {
2421
const groupId = "V1StGXR8_Z5jdHi6B-myT";
2522
const password = "any-password";
2623

new-deepnotes/packages/e2ee/vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default defineConfig({
44
test: {
55
environment: "node",
66
include: ["src/**/*.test.ts"],
7+
testTimeout: 30_000,
78
},
89
});

new-deepnotes/packages/session/src/account-flows.integration.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { fileURLToPath } from "node:url";
44
import { config as loadEnv } from "dotenv";
55
import { and, eq } from "drizzle-orm";
66
import { drizzle } from "drizzle-orm/postgres-js";
7-
import sodium from "libsodium-wrappers-sumo";
87
import { nanoid } from "nanoid";
98
import { authenticator } from "otplib";
109
import postgres from "postgres";
@@ -130,7 +129,7 @@ function testSessionEnv(): SessionEnv {
130129
}
131130

132131
function rand32(): Uint8Array {
133-
return sodium.randombytes_buf(32);
132+
return new Uint8Array(randomBytes(32));
134133
}
135134

136135
/** First `name=value` segment from `Set-Cookie` lines (values are URI-encoded). */
@@ -468,7 +467,7 @@ describe.skipIf(resolveTemplateContext() == null)(
468467
password: newLogin,
469468
salt: phcVals.saltBytes,
470469
});
471-
expect(sodium.memcmp(derived.hash, phcVals.hashBytes)).toBe(true);
470+
expect(Buffer.from(derived.hash).equals(Buffer.from(phcVals.hashBytes))).toBe(true);
472471

473472
const unwrapKey = derived.key;
474473
const privUnwrapped = createPrivateKeyring(new Uint8Array(u!.encPriv)).unwrapSymmetric(

new-deepnotes/packages/session/src/scheduled-cleanup.integration.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { fileURLToPath } from "node:url";
44
import { config as loadEnv } from "dotenv";
55
import { eq } from "drizzle-orm";
66
import { drizzle } from "drizzle-orm/postgres-js";
7-
import sodium from "libsodium-wrappers-sumo";
87
import { nanoid } from "nanoid";
98
import postgres from "postgres";
109
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@@ -51,7 +50,7 @@ function testSessionEnv(): SessionEnv {
5150
}
5251

5352
function rand32(): Uint8Array {
54-
return sodium.randombytes_buf(32);
53+
return new Uint8Array(randomBytes(32));
5554
}
5655

5756
async function buildRegisterBody(email: string, loginHash: Uint8Array) {

0 commit comments

Comments
 (0)