fix(unstable/worker): ensure import permissions are passed (#26101)

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

Closes #26074
This commit is contained in:
David Sherret 2024-10-10 14:01:42 +01:00 committed by GitHub
parent 06aadcd22b
commit 66929de3ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 1 deletions

View File

@ -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(

View File

@ -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
}
}
}

View File

@ -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]

View File

@ -0,0 +1,8 @@
new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
deno: {
permissions: {
import: ["127.0.0.1:4250"],
},
},
});

View File

@ -0,0 +1,8 @@
new Worker(import.meta.resolve("./worker.ts"), {
type: "module",
deno: {
permissions: {
import: [],
},
},
});

View File

@ -0,0 +1,4 @@
const specifier = "jsr:@std/assert/assert";
await import(specifier);
console.log(1);
close();