Skip to content

Commit

Permalink
fix(unstable/worker): ensure import permissions are passed (denoland#…
Browse files Browse the repository at this point in the history
…26101)

We only had integration tests for this and not an integration test.

Closes denoland#26074
  • Loading branch information
dsherret authored Oct 10, 2024
1 parent 06aadcd commit 66929de
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
8 changes: 7 additions & 1 deletion runtime/js/10_permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ function serializePermissions(permissions) {
if (typeof permissions == "object" && permissions != null) {
const serializedPermissions = { __proto__: null };
for (
const key of new SafeArrayIterator(["read", "write", "run", "ffi"])
const key of new SafeArrayIterator([
"read",
"write",
"run",
"ffi",
"import",
])
) {
if (ArrayIsArray(permissions[key])) {
serializedPermissions[key] = ArrayPrototypeMap(
Expand Down
13 changes: 13 additions & 0 deletions tests/specs/permission/allow_import_worker/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tests": {
"allowed": {
"args": "run -A --unstable-worker-options --quiet main.ts",
"output": "1\n"
},
"denied": {
"args": "run -A --unstable-worker-options --quiet main_denied.ts",
"output": "denied.out",
"exitCode": 1
}
}
}
7 changes: 7 additions & 0 deletions tests/specs/permission/allow_import_worker/denied.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: Uncaught (in worker "") (in promise) TypeError: JSR package manifest for '@std/assert' failed to load. Requires import access to "127.0.0.1:4250", run again with the --allow-import flag
await import(specifier);
^
at async file:///[WILDLINE]
error: Uncaught (in promise) Error: Unhandled error in child worker.
at [WILDLINE]
at [WILDLINE]
8 changes: 8 additions & 0 deletions tests/specs/permission/allow_import_worker/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
deno: {
permissions: {
import: ["127.0.0.1:4250"],
},
},
});
8 changes: 8 additions & 0 deletions tests/specs/permission/allow_import_worker/main_denied.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
deno: {
permissions: {
import: [],
},
},
});
4 changes: 4 additions & 0 deletions tests/specs/permission/allow_import_worker/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const specifier = "jsr:@std/assert/assert";
await import(specifier);
console.log(1);
close();

0 comments on commit 66929de

Please sign in to comment.