1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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) { if (typeof permissions == "object" && permissions != null) {
const serializedPermissions = { __proto__: null }; const serializedPermissions = { __proto__: null };
for ( for (
const key of new SafeArrayIterator(["read", "write", "run", "ffi"]) const key of new SafeArrayIterator([
"read",
"write",
"run",
"ffi",
"import",
])
) { ) {
if (ArrayIsArray(permissions[key])) { if (ArrayIsArray(permissions[key])) {
serializedPermissions[key] = ArrayPrototypeMap( 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();