From f9ccbbe081b447c36ae8b472dc64124833fb8c79 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 3 Oct 2024 13:11:01 +0100 Subject: [PATCH] Fix jsRunner.spec.ts. --- packages/server/src/jsRunner/tests/jsRunner.spec.ts | 7 ++++--- packages/server/src/jsRunner/vm/isolated-vm.ts | 2 +- packages/string-templates/src/errors.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/server/src/jsRunner/tests/jsRunner.spec.ts b/packages/server/src/jsRunner/tests/jsRunner.spec.ts index 2b9fc08041..7d2df17c1f 100644 --- a/packages/server/src/jsRunner/tests/jsRunner.spec.ts +++ b/packages/server/src/jsRunner/tests/jsRunner.spec.ts @@ -41,10 +41,11 @@ describe("jsRunner (using isolated-vm)", () => { }) it("should prevent sandbox escape", async () => { - const output = await processJS( - `return this.constructor.constructor("return process.env")()` + await expect( + processJS(`return this.constructor.constructor("return process.env")()`) + ).rejects.toThrow( + "error while running user-supplied JavaScript: ReferenceError: process is not defined" ) - expect(output).toBe("ReferenceError: process is not defined") }) describe("helpers", () => { diff --git a/packages/server/src/jsRunner/vm/isolated-vm.ts b/packages/server/src/jsRunner/vm/isolated-vm.ts index 9262687925..0a9e93f475 100644 --- a/packages/server/src/jsRunner/vm/isolated-vm.ts +++ b/packages/server/src/jsRunner/vm/isolated-vm.ts @@ -22,7 +22,7 @@ class UserScriptError extends Error { code = "USER_SCRIPT_ERROR" constructor(readonly userScriptError: Error) { super( - `error while running user-supplied JavaScript: ${userScriptError.message}`, + `error while running user-supplied JavaScript: ${userScriptError.toString()}`, { cause: userScriptError } ) } diff --git a/packages/string-templates/src/errors.ts b/packages/string-templates/src/errors.ts index 4c7cbdb360..d68461561e 100644 --- a/packages/string-templates/src/errors.ts +++ b/packages/string-templates/src/errors.ts @@ -7,7 +7,7 @@ export class UserScriptError extends Error { constructor(readonly userScriptError: Error) { super( - `error while running user-supplied JavaScript: ${userScriptError.message}` + `error while running user-supplied JavaScript: ${userScriptError.toString()}` ) } }