summaryrefslogtreecommitdiff
path: root/tests/specs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/specs')
-rw-r--r--tests/specs/compile/permissions_denied/__test__.jsonc4
-rw-r--r--tests/specs/compile/permissions_denied/main.out2
-rw-r--r--tests/specs/npm/lifecycle_scripts/node_gyp_not_found.out2
-rw-r--r--tests/specs/permission/path_not_permitted/__test__.jsonc10
-rw-r--r--tests/specs/permission/path_not_permitted/main.out11
-rw-r--r--tests/specs/permission/path_not_permitted/main.ts18
-rw-r--r--tests/specs/permission/path_not_permitted/sub.ts34
-rw-r--r--tests/specs/permission/write_allow_binary/__test__.jsonc5
-rw-r--r--tests/specs/permission/write_allow_binary/main.out6
-rw-r--r--tests/specs/permission/write_allow_binary/main.ts14
-rw-r--r--tests/specs/permission/write_allow_binary/sub.ts3
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc8
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/main.out15
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/main.ts67
-rw-r--r--tests/specs/run/ld_preload/__test__.jsonc6
-rw-r--r--tests/specs/run/ld_preload/env_arg.out12
-rw-r--r--tests/specs/run/ld_preload/env_arg.ts25
-rw-r--r--tests/specs/run/ld_preload/set_with_allow_env.out12
-rw-r--r--tests/specs/run/ld_preload/set_with_allow_env.ts14
19 files changed, 248 insertions, 20 deletions
diff --git a/tests/specs/compile/permissions_denied/__test__.jsonc b/tests/specs/compile/permissions_denied/__test__.jsonc
index 8f8590162..ec683ea62 100644
--- a/tests/specs/compile/permissions_denied/__test__.jsonc
+++ b/tests/specs/compile/permissions_denied/__test__.jsonc
@@ -1,5 +1,9 @@
{
"tempDir": true,
+ "envs": {
+ "DYLD_FALLBACK_LIBRARY_PATH": "",
+ "LD_LIBRARY_PATH": ""
+ },
"steps": [{
"if": "unix",
"args": "compile --output main main.ts",
diff --git a/tests/specs/compile/permissions_denied/main.out b/tests/specs/compile/permissions_denied/main.out
index e9ea45c81..47a4707cc 100644
--- a/tests/specs/compile/permissions_denied/main.out
+++ b/tests/specs/compile/permissions_denied/main.out
@@ -1,2 +1,2 @@
-error: Uncaught (in promise) PermissionDenied: Requires run access to "deno", specify the required permissions during compilation using `deno compile --allow-run`
+error: Uncaught (in promise) PermissionDenied: Requires run access to "[WILDLINE]deno[WILDLINE]", specify the required permissions during compilation using `deno compile --allow-run`
[WILDCARD] \ No newline at end of file
diff --git a/tests/specs/npm/lifecycle_scripts/node_gyp_not_found.out b/tests/specs/npm/lifecycle_scripts/node_gyp_not_found.out
index 65ea53d58..2f0ff11e2 100644
--- a/tests/specs/npm/lifecycle_scripts/node_gyp_not_found.out
+++ b/tests/specs/npm/lifecycle_scripts/node_gyp_not_found.out
@@ -3,6 +3,6 @@ Download http://localhost:4260/@denotest/node-addon-implicit-node-gyp
Download http://localhost:4260/@denotest/node-addon-implicit-node-gyp/1.0.0.tgz
Initialize @denotest/node-addon-implicit-node-gyp@1.0.0
[UNORDERED_END]
-warning: node-gyp was used in a script, but was not listed as a dependency. Either add it as a dependency or install it globally (e.g. `npm install -g node-gyp`)
+Warning node-gyp was used in a script, but was not listed as a dependency. Either add it as a dependency or install it globally (e.g. `npm install -g node-gyp`)
[WILDCARD]
error: script 'install' in '@denotest/node-addon-implicit-node-gyp@1.0.0' failed with exit code 1
diff --git a/tests/specs/permission/path_not_permitted/__test__.jsonc b/tests/specs/permission/path_not_permitted/__test__.jsonc
new file mode 100644
index 000000000..f10e8b389
--- /dev/null
+++ b/tests/specs/permission/path_not_permitted/__test__.jsonc
@@ -0,0 +1,10 @@
+{
+ "tempDir": true,
+ "envs": {
+ "LD_LIBRARY_PATH": "",
+ "LD_PRELOAD": "",
+ "DYLD_FALLBACK_LIBRARY_PATH": ""
+ },
+ "args": "run -A main.ts",
+ "output": "main.out"
+}
diff --git a/tests/specs/permission/path_not_permitted/main.out b/tests/specs/permission/path_not_permitted/main.out
new file mode 100644
index 000000000..3817c2ca5
--- /dev/null
+++ b/tests/specs/permission/path_not_permitted/main.out
@@ -0,0 +1,11 @@
+Running...
+PermissionDenied: Requires run access to "[WILDLINE]deno[WILDLINE]", run again with the --allow-run flag
+ [WILDCARD]
+ at file:///[WILDLINE]/sub.ts:15:5 {
+ name: "PermissionDenied"
+}
+PermissionDenied: Requires run access to "[WILDLINE]deno[WILDLINE]", run again with the --allow-run flag
+ [WILDCARD]
+ at file:///[WILDLINE]/sub.ts:23:22 {
+ name: "PermissionDenied"
+}
diff --git a/tests/specs/permission/path_not_permitted/main.ts b/tests/specs/permission/path_not_permitted/main.ts
new file mode 100644
index 000000000..9e8d627f2
--- /dev/null
+++ b/tests/specs/permission/path_not_permitted/main.ts
@@ -0,0 +1,18 @@
+const binaryName = Deno.build.os === "windows" ? "deno.exe" : "deno";
+Deno.copyFileSync(Deno.execPath(), binaryName);
+
+console.log("Running...");
+new Deno.Command(
+ Deno.execPath(),
+ {
+ args: [
+ "run",
+ "--allow-write",
+ "--allow-read",
+ `--allow-run=${binaryName}`,
+ "sub.ts",
+ ],
+ stderr: "inherit",
+ stdout: "inherit",
+ },
+).outputSync();
diff --git a/tests/specs/permission/path_not_permitted/sub.ts b/tests/specs/permission/path_not_permitted/sub.ts
new file mode 100644
index 000000000..f2b6d6b37
--- /dev/null
+++ b/tests/specs/permission/path_not_permitted/sub.ts
@@ -0,0 +1,34 @@
+const binaryName = Deno.build.os === "windows" ? "deno.exe" : "deno";
+const pathSep = Deno.build.os === "windows" ? "\\" : "/";
+
+Deno.mkdirSync("subdir");
+Deno.copyFileSync(binaryName, "subdir/" + binaryName);
+
+try {
+ const commandResult = new Deno.Command(
+ binaryName,
+ {
+ env: { "PATH": Deno.cwd() + pathSep + "subdir" },
+ stdout: "inherit",
+ stderr: "inherit",
+ },
+ ).outputSync();
+
+ console.log(commandResult.code);
+} catch (err) {
+ console.log(err);
+}
+
+try {
+ const child = Deno.run(
+ {
+ cmd: [binaryName],
+ env: { "PATH": Deno.cwd() + pathSep + "subdir" },
+ stdout: "inherit",
+ stderr: "inherit",
+ },
+ );
+ console.log((await child.status()).code);
+} catch (err) {
+ console.log(err);
+}
diff --git a/tests/specs/permission/write_allow_binary/__test__.jsonc b/tests/specs/permission/write_allow_binary/__test__.jsonc
new file mode 100644
index 000000000..a47fed572
--- /dev/null
+++ b/tests/specs/permission/write_allow_binary/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "tempDir": true,
+ "args": "run -A main.ts",
+ "output": "main.out"
+}
diff --git a/tests/specs/permission/write_allow_binary/main.out b/tests/specs/permission/write_allow_binary/main.out
new file mode 100644
index 000000000..e7c47f288
--- /dev/null
+++ b/tests/specs/permission/write_allow_binary/main.out
@@ -0,0 +1,6 @@
+Running...
+error: Uncaught (in promise) PermissionDenied: Requires write access to "binary[WILDLINE]", run again with the --allow-write flag
+Deno.writeTextFileSync(binaryName, "");
+ ^
+ at [WILDCARD]
+ at file:///[WILDLINE]sub.ts:3:6
diff --git a/tests/specs/permission/write_allow_binary/main.ts b/tests/specs/permission/write_allow_binary/main.ts
new file mode 100644
index 000000000..73deeab9a
--- /dev/null
+++ b/tests/specs/permission/write_allow_binary/main.ts
@@ -0,0 +1,14 @@
+const binaryName = Deno.build.os === "windows" ? "binary.exe" : "binary";
+Deno.copyFileSync(Deno.execPath(), binaryName);
+
+console.log("Running...");
+const result = new Deno.Command(
+ Deno.execPath(),
+ {
+ args: ["run", "--allow-write", `--allow-run=./${binaryName}`, "sub.ts"],
+ stderr: "inherit",
+ stdout: "inherit",
+ },
+).outputSync();
+
+console.assert(result.code == 1, "Expected failure");
diff --git a/tests/specs/permission/write_allow_binary/sub.ts b/tests/specs/permission/write_allow_binary/sub.ts
new file mode 100644
index 000000000..e865597b1
--- /dev/null
+++ b/tests/specs/permission/write_allow_binary/sub.ts
@@ -0,0 +1,3 @@
+const binaryName = Deno.build.os === "windows" ? "binary.exe" : "binary";
+
+Deno.writeTextFileSync(binaryName, "");
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();
diff --git a/tests/specs/run/ld_preload/__test__.jsonc b/tests/specs/run/ld_preload/__test__.jsonc
index 767e423d0..882f157e9 100644
--- a/tests/specs/run/ld_preload/__test__.jsonc
+++ b/tests/specs/run/ld_preload/__test__.jsonc
@@ -7,13 +7,11 @@
"tests": {
"env_arg": {
"args": "run --allow-run=echo env_arg.ts",
- "output": "env_arg.out",
- "exitCode": 1
+ "output": "env_arg.out"
},
"set_with_allow_env": {
"args": "run --allow-run=echo --allow-env set_with_allow_env.ts",
- "output": "set_with_allow_env.out",
- "exitCode": 1
+ "output": "set_with_allow_env.out"
}
}
}
diff --git a/tests/specs/run/ld_preload/env_arg.out b/tests/specs/run/ld_preload/env_arg.out
index fbf37014a..3df781a8e 100644
--- a/tests/specs/run/ld_preload/env_arg.out
+++ b/tests/specs/run/ld_preload/env_arg.out
@@ -1,4 +1,8 @@
-error: Uncaught (in promise) PermissionDenied: Requires --allow-all permissions to spawn subprocess with LD_PRELOAD environment variable.
-}).spawn();
- ^
- at [WILDCARD]
+PermissionDenied: Requires --allow-all permissions to spawn subprocess with LD_PRELOAD environment variable.
+ [WILDCARD]
+ name: "PermissionDenied"
+}
+PermissionDenied: Requires --allow-all permissions to spawn subprocess with LD_PRELOAD environment variable.
+ [WILDCARD]
+ name: "PermissionDenied"
+}
diff --git a/tests/specs/run/ld_preload/env_arg.ts b/tests/specs/run/ld_preload/env_arg.ts
index 0b236619e..d7ca1073d 100644
--- a/tests/specs/run/ld_preload/env_arg.ts
+++ b/tests/specs/run/ld_preload/env_arg.ts
@@ -1,5 +1,20 @@
-const output = new Deno.Command("echo", {
- env: {
- "LD_PRELOAD": "./libpreload.so",
- },
-}).spawn();
+try {
+ new Deno.Command("echo", {
+ env: {
+ "LD_PRELOAD": "./libpreload.so",
+ },
+ }).spawn();
+} catch (err) {
+ console.log(err);
+}
+
+try {
+ Deno.run({
+ cmd: ["echo"],
+ env: {
+ "LD_PRELOAD": "./libpreload.so",
+ },
+ });
+} catch (err) {
+ console.log(err);
+}
diff --git a/tests/specs/run/ld_preload/set_with_allow_env.out b/tests/specs/run/ld_preload/set_with_allow_env.out
index 2e92763dd..60dba7cff 100644
--- a/tests/specs/run/ld_preload/set_with_allow_env.out
+++ b/tests/specs/run/ld_preload/set_with_allow_env.out
@@ -1,4 +1,8 @@
-error: Uncaught (in promise) PermissionDenied: Requires --allow-all permissions to spawn subprocess with LD_PRELOAD environment variable.
-const output = new Deno.Command("echo").spawn();
- ^
- at [WILDCARD]
+PermissionDenied: Requires --allow-all permissions to spawn subprocess with LD_PRELOAD environment variable.
+ [WILDCARD]
+ name: "PermissionDenied"
+}
+PermissionDenied: Requires --allow-all permissions to spawn subprocess with DYLD_FALLBACK_LIBRARY_PATH, LD_PRELOAD environment variables.
+ [WILDCARD]
+ name: "PermissionDenied"
+}
diff --git a/tests/specs/run/ld_preload/set_with_allow_env.ts b/tests/specs/run/ld_preload/set_with_allow_env.ts
index 9530f4478..79004aa16 100644
--- a/tests/specs/run/ld_preload/set_with_allow_env.ts
+++ b/tests/specs/run/ld_preload/set_with_allow_env.ts
@@ -1,3 +1,15 @@
Deno.env.set("LD_PRELOAD", "./libpreload.so");
-const output = new Deno.Command("echo").spawn();
+try {
+ new Deno.Command("echo").spawn();
+} catch (err) {
+ console.log(err);
+}
+
+Deno.env.set("DYLD_FALLBACK_LIBRARY_PATH", "./libpreload.so");
+
+try {
+ Deno.run({ cmd: ["echo"] }).spawnSync();
+} catch (err) {
+ console.log(err);
+}