Update tests

This commit is contained in:
Adria Navarro 2024-02-13 09:48:31 +01:00
parent 6f6100e7a2
commit f0a149984d
1 changed files with 20 additions and 38 deletions

View File

@ -1,21 +1,4 @@
// import { validate as isValidUUID } from "uuid" import { validate as isValidUUID } from "uuid"
jest.mock("@budibase/handlebars-helpers/lib/math", () => {
const actual = jest.requireActual("@budibase/handlebars-helpers/lib/math")
return {
...actual,
random: () => 10,
}
})
jest.mock("@budibase/handlebars-helpers/lib/uuid", () => {
const actual = jest.requireActual("@budibase/handlebars-helpers/lib/uuid")
return {
...actual,
uuid: () => "f34ebc66-93bd-4f7c-b79b-92b5569138bc",
}
})
import { processStringSync, encodeJSBinding } from "@budibase/string-templates" import { processStringSync, encodeJSBinding } from "@budibase/string-templates"
@ -47,8 +30,7 @@ describe("jsRunner", () => {
expect(output).toBe(3) expect(output).toBe(3)
}) })
// TODO This should be reenabled when running on isolated-vm it("should prevent sandbox escape", async () => {
it.skip("should prevent sandbox escape", async () => {
const output = await processJS( const output = await processJS(
`return this.constructor.constructor("return process")()` `return this.constructor.constructor("return process")()`
) )
@ -58,26 +40,26 @@ describe("jsRunner", () => {
describe("helpers", () => { describe("helpers", () => {
runJsHelpersTests({ runJsHelpersTests({
funcWrap: (func: any) => config.doInContext(config.getAppId(), func), funcWrap: (func: any) => config.doInContext(config.getAppId(), func),
// testsToSkip: ["random", "uuid"], testsToSkip: ["random", "uuid"],
}) })
// describe("uuid", () => { describe("uuid", () => {
// it("uuid helper returns a valid uuid", async () => { it("uuid helper returns a valid uuid", async () => {
// const result = await processJS("return helpers.uuid()") const result = await processJS("return helpers.uuid()")
// expect(result).toBeDefined() expect(result).toBeDefined()
// expect(isValidUUID(result)).toBe(true) expect(isValidUUID(result)).toBe(true)
// }) })
// }) })
// describe("random", () => { describe("random", () => {
// it("random helper returns a valid number", async () => { it("random helper returns a valid number", async () => {
// const min = 1 const min = 1
// const max = 8 const max = 8
// const result = await processJS(`return helpers.random(${min}, ${max})`) const result = await processJS(`return helpers.random(${min}, ${max})`)
// expect(result).toBeDefined() expect(result).toBeDefined()
// expect(result).toBeGreaterThanOrEqual(min) expect(result).toBeGreaterThanOrEqual(min)
// expect(result).toBeLessThanOrEqual(max) expect(result).toBeLessThanOrEqual(max)
// }) })
// }) })
}) })
}) })