diff options
Diffstat (limited to 'cli/tests/workers')
-rw-r--r-- | cli/tests/workers/dynamic_remote.ts | 2 | ||||
-rw-r--r-- | cli/tests/workers/parent_read_check_granular_worker.js | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_blob_local.ts | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_blob_local.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_blob_remote.ts | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_blob_remote.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_data_local.ts | 5 | ||||
-rw-r--r-- | cli/tests/workers/permissions_data_local.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_data_remote.ts | 5 | ||||
-rw-r--r-- | cli/tests/workers/permissions_data_remote.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/workers/permissions_dynamic_remote.ts | 11 | ||||
-rw-r--r-- | cli/tests/workers/permissions_dynamic_remote.ts.out | 10 | ||||
-rw-r--r-- | cli/tests/workers/permissions_remote_remote.ts | 3 | ||||
-rw-r--r-- | cli/tests/workers/permissions_remote_remote.ts.out | 4 | ||||
-rw-r--r-- | cli/tests/workers/read_check_granular_worker.js | 4 | ||||
-rw-r--r-- | cli/tests/workers/static_remote.ts | 2 | ||||
-rw-r--r-- | cli/tests/workers/test.ts | 27 |
17 files changed, 87 insertions, 14 deletions
diff --git a/cli/tests/workers/dynamic_remote.ts b/cli/tests/workers/dynamic_remote.ts new file mode 100644 index 000000000..381c7f374 --- /dev/null +++ b/cli/tests/workers/dynamic_remote.ts @@ -0,0 +1,2 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +await import("https://example.com/some/file.ts"); diff --git a/cli/tests/workers/parent_read_check_granular_worker.js b/cli/tests/workers/parent_read_check_granular_worker.js index 474b8a61b..1391190cd 100644 --- a/cli/tests/workers/parent_read_check_granular_worker.js +++ b/cli/tests/workers/parent_read_check_granular_worker.js @@ -1,5 +1,3 @@ -import { fromFileUrl } from "../../../test_util/std/path/mod.ts"; - const worker = new Worker( new URL("./read_check_granular_worker.js", import.meta.url).href, { @@ -31,7 +29,7 @@ worker.onmessage = ({ data: childResponse }) => { onmessage = async ({ data }) => { const { state } = await Deno.permissions.query({ name: "read", - path: fromFileUrl(new URL(data.route, import.meta.url)), + path: data.path, }); messages[data.index] = state === "granted"; diff --git a/cli/tests/workers/permissions_blob_local.ts b/cli/tests/workers/permissions_blob_local.ts new file mode 100644 index 000000000..e75557912 --- /dev/null +++ b/cli/tests/workers/permissions_blob_local.ts @@ -0,0 +1,4 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///local_file.ts";`; +const blob = new Blob([code]); +new Worker(URL.createObjectURL(blob), { type: "module" }); diff --git a/cli/tests/workers/permissions_blob_local.ts.out b/cli/tests/workers/permissions_blob_local.ts.out new file mode 100644 index 000000000..7ccb56e1d --- /dev/null +++ b/cli/tests/workers/permissions_blob_local.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires read access to "/local_file.ts", run again with the --allow-read flag + at blob:null/[WILDCARD]:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/permissions_blob_remote.ts b/cli/tests/workers/permissions_blob_remote.ts new file mode 100644 index 000000000..4808bc57b --- /dev/null +++ b/cli/tests/workers/permissions_blob_remote.ts @@ -0,0 +1,4 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +const blob = new Blob([code]); +new Worker(URL.createObjectURL(blob), { type: "module" }); diff --git a/cli/tests/workers/permissions_blob_remote.ts.out b/cli/tests/workers/permissions_blob_remote.ts.out new file mode 100644 index 000000000..c89f7b41c --- /dev/null +++ b/cli/tests/workers/permissions_blob_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at blob:null/[WILDCARD]:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/permissions_data_local.ts b/cli/tests/workers/permissions_data_local.ts new file mode 100644 index 000000000..938a76add --- /dev/null +++ b/cli/tests/workers/permissions_data_local.ts @@ -0,0 +1,5 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///local_file.ts";`; +new Worker(`data:application/javascript;base64,${btoa(code)}`, { + type: "module", +}); diff --git a/cli/tests/workers/permissions_data_local.ts.out b/cli/tests/workers/permissions_data_local.ts.out new file mode 100644 index 000000000..e282bb5aa --- /dev/null +++ b/cli/tests/workers/permissions_data_local.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires read access to "/local_file.ts", run again with the --allow-read flag + at data:application/javascript;base64,aW1wb3J0ICJmaWxlOi8vL2xvY2FsX2ZpbGUudHMiOw==:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/permissions_data_remote.ts b/cli/tests/workers/permissions_data_remote.ts new file mode 100644 index 000000000..b37bd661d --- /dev/null +++ b/cli/tests/workers/permissions_data_remote.ts @@ -0,0 +1,5 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +new Worker(`data:application/javascript;base64,${btoa(code)}`, { + type: "module", +}); diff --git a/cli/tests/workers/permissions_data_remote.ts.out b/cli/tests/workers/permissions_data_remote.ts.out new file mode 100644 index 000000000..2c4080672 --- /dev/null +++ b/cli/tests/workers/permissions_data_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at data:application/javascript;base64,aW1wb3J0ICJodHRwczovL2V4YW1wbGUuY29tL3NvbWUvZmlsZS50cyI7:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/permissions_dynamic_remote.ts b/cli/tests/workers/permissions_dynamic_remote.ts new file mode 100644 index 000000000..a5d293e16 --- /dev/null +++ b/cli/tests/workers/permissions_dynamic_remote.ts @@ -0,0 +1,11 @@ +new Worker( + "http://localhost:4545/cli/tests/workers/dynamic_remote.ts", + { + type: "module", + deno: { + permissions: { + net: false, + }, + }, + }, +); diff --git a/cli/tests/workers/permissions_dynamic_remote.ts.out b/cli/tests/workers/permissions_dynamic_remote.ts.out new file mode 100644 index 000000000..3bfb16205 --- /dev/null +++ b/cli/tests/workers/permissions_dynamic_remote.ts.out @@ -0,0 +1,10 @@ +error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag +await import("https://example.com/some/file.ts"); +^ + at async http://localhost:4545/cli/tests/workers/dynamic_remote.ts:2:1 +error: Uncaught (in worker "") TypeError: Requires net access to "example.com", run again with the --allow-net flag +await import("https://example.com/some/file.ts"); +^ + at async http://localhost:4545/cli/tests/workers/dynamic_remote.ts:2:1 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/permissions_remote_remote.ts b/cli/tests/workers/permissions_remote_remote.ts new file mode 100644 index 000000000..b1f954a31 --- /dev/null +++ b/cli/tests/workers/permissions_remote_remote.ts @@ -0,0 +1,3 @@ +new Worker("http://localhost:4545/cli/tests/workers/static_remote.ts", { + type: "module", +}); diff --git a/cli/tests/workers/permissions_remote_remote.ts.out b/cli/tests/workers/permissions_remote_remote.ts.out new file mode 100644 index 000000000..714150a3a --- /dev/null +++ b/cli/tests/workers/permissions_remote_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at http://localhost:4545/cli/tests/workers/static_remote.ts:2:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#poll (deno:runtime/js/11_workers.js:246:23) diff --git a/cli/tests/workers/read_check_granular_worker.js b/cli/tests/workers/read_check_granular_worker.js index d1a205391..25f2058b3 100644 --- a/cli/tests/workers/read_check_granular_worker.js +++ b/cli/tests/workers/read_check_granular_worker.js @@ -1,9 +1,7 @@ -import { fromFileUrl } from "../../../test_util/std/path/mod.ts"; - onmessage = async ({ data }) => { const { state } = await Deno.permissions.query({ name: "read", - path: fromFileUrl(new URL(data.route, import.meta.url)), + path: data.path, }); postMessage({ diff --git a/cli/tests/workers/static_remote.ts b/cli/tests/workers/static_remote.ts new file mode 100644 index 000000000..2d6e820fd --- /dev/null +++ b/cli/tests/workers/static_remote.ts @@ -0,0 +1,2 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +import "https://example.com/some/file.ts"; diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index 41988d204..954737b3a 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -8,6 +8,7 @@ import { assertThrows, } from "../../../test_util/std/testing/asserts.ts"; import { deferred } from "../../../test_util/std/async/deferred.ts"; +import { fromFileUrl } from "../../../test_util/std/path/mod.ts"; Deno.test({ name: "worker terminate", @@ -476,8 +477,16 @@ Deno.test("Worker limit children permissions granularly", async function () { //Routes are relative to the spawned worker location const routes = [ - { permission: false, route: "read_check_granular_worker.js" }, - { permission: true, route: "read_check_worker.js" }, + { + permission: false, + path: fromFileUrl( + new URL("read_check_granular_worker.js", import.meta.url), + ), + }, + { + permission: true, + path: fromFileUrl(new URL("read_check_worker.js", import.meta.url)), + }, ]; let checked = 0; @@ -490,10 +499,10 @@ Deno.test("Worker limit children permissions granularly", async function () { } }; - routes.forEach(({ route }, index) => + routes.forEach(({ path }, index) => worker.postMessage({ index, - route, + path, }) ); @@ -553,12 +562,14 @@ Deno.test("Nested worker limit children permissions granularly", async function { childHasPermission: false, parentHasPermission: true, - route: "read_check_granular_worker.js", + path: fromFileUrl( + new URL("read_check_granular_worker.js", import.meta.url), + ), }, { childHasPermission: false, parentHasPermission: false, - route: "read_check_worker.js", + path: fromFileUrl(new URL("read_check_worker.js", import.meta.url)), }, ]; @@ -579,10 +590,10 @@ Deno.test("Nested worker limit children permissions granularly", async function }; // Index needed cause requests will be handled asynchronously - routes.forEach(({ route }, index) => + routes.forEach(({ path }, index) => worker.postMessage({ index, - route, + path, }) ); |