diff options
Diffstat (limited to 'tests/specs/run/allow_run_allowlist_resolution')
3 files changed, 90 insertions, 0 deletions
diff --git a/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc b/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc new file mode 100644 index 000000000..173e13027 --- /dev/null +++ b/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "args": "run --quiet -A main.ts", + "output": "main.out", + "envs": { + "DYLD_FALLBACK_LIBRARY_PATH": "", + "LD_LIBRARY_PATH": "" + } +} diff --git a/tests/specs/run/allow_run_allowlist_resolution/main.out b/tests/specs/run/allow_run_allowlist_resolution/main.out new file mode 100644 index 000000000..f61f9b550 --- /dev/null +++ b/tests/specs/run/allow_run_allowlist_resolution/main.out @@ -0,0 +1,15 @@ +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "granted", onchange: null } +--- +Info Failed to resolve 'deno' for allow-run: cannot find binary path +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +--- +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "granted", onchange: null } diff --git a/tests/specs/run/allow_run_allowlist_resolution/main.ts b/tests/specs/run/allow_run_allowlist_resolution/main.ts new file mode 100644 index 000000000..bf33d8cbe --- /dev/null +++ b/tests/specs/run/allow_run_allowlist_resolution/main.ts @@ -0,0 +1,67 @@ +// Testing the following (but with `deno` instead of `echo`): +// | `deno run --allow-run=echo` | `which path == "/usr/bin/echo"` at startup | `which path != "/usr/bin/echo"` at startup | +// |-------------------------------------|--------------------------------------------|--------------------------------------------| +// | **`Deno.Command("echo")`** | ✅ | ✅ | +// | **`Deno.Command("/usr/bin/echo")`** | ✅ | ❌ | + +// | `deno run --allow-run=/usr/bin/echo | `which path == "/usr/bin/echo"` at runtime | `which path != "/usr/bin/echo"` at runtime | +// |-------------------------------------|--------------------------------------------|--------------------------------------------| +// | **`Deno.Command("echo")`** | ✅ | ❌ | +// | **`Deno.Command("/usr/bin/echo")`** | ✅ | ✅ | + +const execPath = Deno.execPath(); +const execPathParent = execPath.replace(/[/\\][^/\\]+$/, ""); + +const testUrl = `data:application/typescript;base64,${ + btoa(` + console.error(await Deno.permissions.query({ name: "run", command: "deno" })); + console.error(await Deno.permissions.query({ name: "run", command: "${ + execPath.replaceAll("\\", "\\\\") + }" })); + Deno.env.set("PATH", ""); + console.error(await Deno.permissions.query({ name: "run", command: "deno" })); + console.error(await Deno.permissions.query({ name: "run", command: "${ + execPath.replaceAll("\\", "\\\\") + }" })); +`) +}`; + +const process1 = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--allow-env", + "--allow-run=deno", + testUrl, + ], + stdout: "inherit", + stderr: "inherit", + env: { "PATH": execPathParent }, +}).output(); + +console.error("---"); + +await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--allow-env", + "--allow-run=deno", + testUrl, + ], + stderr: "inherit", + stdout: "inherit", + env: { "PATH": "" }, +}).output(); + +console.error("---"); + +await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--allow-env", + `--allow-run=${execPath}`, + testUrl, + ], + stderr: "inherit", + stdout: "inherit", + env: { "PATH": execPathParent }, +}).output(); |
