summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs5
-rw-r--r--cli/tests/testdata/allow_run_allowlist_resolution.ts66
-rw-r--r--cli/tests/testdata/allow_run_allowlist_resolution.ts.out15
3 files changed, 86 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 22096cb60..e7ff19954 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -3617,6 +3617,11 @@ itest!(followup_dyn_import_resolved {
output: "run/followup_dyn_import_resolves/main.ts.out",
});
+itest!(allow_run_allowlist_resolution {
+ args: "run --quiet --unstable -A allow_run_allowlist_resolution.ts",
+ output: "allow_run_allowlist_resolution.ts.out",
+});
+
itest!(unhandled_rejection {
args: "run --check run/unhandled_rejection.ts",
output: "run/unhandled_rejection.ts.out",
diff --git a/cli/tests/testdata/allow_run_allowlist_resolution.ts b/cli/tests/testdata/allow_run_allowlist_resolution.ts
new file mode 100644
index 000000000..c7369d928
--- /dev/null
+++ b/cli/tests/testdata/allow_run_allowlist_resolution.ts
@@ -0,0 +1,66 @@
+// 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.log(await Deno.permissions.query({ name: "run", command: "deno" }));
+ console.log(await Deno.permissions.query({ name: "run", command: "${
+ execPath.replaceAll("\\", "\\\\")
+ }" }));
+ Deno.env.set("PATH", "");
+ console.log(await Deno.permissions.query({ name: "run", command: "deno" }));
+ console.log(await Deno.permissions.query({ name: "run", command: "${
+ execPath.replaceAll("\\", "\\\\")
+ }" }));
+`)
+}`;
+
+const process1 = await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--quiet",
+ "--allow-env",
+ "--allow-run=deno",
+ testUrl,
+ ],
+ stderr: "null",
+ env: { "PATH": execPathParent },
+}).output();
+console.log(new TextDecoder().decode(process1.stdout));
+
+const process2 = await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--quiet",
+ "--allow-env",
+ "--allow-run=deno",
+ testUrl,
+ ],
+ stderr: "null",
+ env: { "PATH": "" },
+}).output();
+console.log(new TextDecoder().decode(process2.stdout));
+
+const process3 = await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--quiet",
+ "--allow-env",
+ `--allow-run=${execPath}`,
+ testUrl,
+ ],
+ stderr: "null",
+ env: { "PATH": execPathParent },
+}).output();
+console.log(new TextDecoder().decode(process3.stdout));
diff --git a/cli/tests/testdata/allow_run_allowlist_resolution.ts.out b/cli/tests/testdata/allow_run_allowlist_resolution.ts.out
new file mode 100644
index 000000000..16ba6754a
--- /dev/null
+++ b/cli/tests/testdata/allow_run_allowlist_resolution.ts.out
@@ -0,0 +1,15 @@
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "granted", 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 }
+