summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/run_tests.rs41
-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.out (renamed from tests/testdata/allow_run_allowlist_resolution.ts.out)12
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/main.ts (renamed from tests/testdata/allow_run_allowlist_resolution.ts)39
-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
-rw-r--r--tests/testdata/run/089_run_allow_list.ts.out2
-rw-r--r--tests/unit/process_test.ts2
22 files changed, 220 insertions, 62 deletions
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs
index 841ef2d18..47fcdb657 100644
--- a/tests/integration/run_tests.rs
+++ b/tests/integration/run_tests.rs
@@ -3683,11 +3683,6 @@ itest!(followup_dyn_import_resolved {
output: "run/followup_dyn_import_resolves/main.ts.out",
});
-itest!(allow_run_allowlist_resolution {
- args: "run --quiet -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",
@@ -4592,16 +4587,32 @@ fn permission_prompt_escapes_ansi_codes_and_control_chars() {
))
});
- util::with_pty(&["repl"], |mut console| {
- console.write_line_raw(r#"const boldANSI = "\u001b[1m";"#);
- console.expect("undefined");
- console.write_line_raw(r#"const unboldANSI = "\u001b[22m";"#);
- console.expect("undefined");
- console.write_line_raw(
- r#"new Deno.Command(`${boldANSI}cat${unboldANSI}`).spawn();"#,
- );
- console.expect("\u{250f} \u{26a0}\u{fe0f} Deno requests run access to \"\\u{1b}[1mcat\\u{1b}[22m\".");
- });
+ // windows doesn't support backslashes in paths, so just try this on unix
+ if cfg!(unix) {
+ let context = TestContextBuilder::default().use_temp_cwd().build();
+ context
+ .new_command()
+ .env("PATH", context.temp_dir().path())
+ .env("DYLD_FALLBACK_LIBRARY_PATH", "")
+ .env("LD_LIBRARY_PATH", "")
+ .args_vec(["repl", "--allow-write=."])
+ .with_pty(|mut console| {
+ console.write_line_raw(r#"const boldANSI = "\u001b[1m";"#);
+ console.expect("undefined");
+ console.write_line_raw(r#"const unboldANSI = "\u001b[22m";"#);
+ console.expect("undefined");
+ console.write_line_raw(
+ r#"Deno.writeTextFileSync(`${boldANSI}cat${unboldANSI}`, "");"#,
+ );
+ console.expect("undefined");
+ console.write_line_raw(
+ r#"new Deno.Command(`./${boldANSI}cat${unboldANSI}`).spawn();"#,
+ );
+ console
+ .expect("\u{250f} \u{26a0}\u{fe0f} Deno requests run access to \"");
+ console.expect("\\u{1b}[1mcat\\u{1b}[22m\"."); // ensure escaped
+ });
+ }
}
itest!(node_builtin_modules_ts {
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/testdata/allow_run_allowlist_resolution.ts.out b/tests/specs/run/allow_run_allowlist_resolution/main.out
index 16ba6754a..f61f9b550 100644
--- a/tests/testdata/allow_run_allowlist_resolution.ts.out
+++ b/tests/specs/run/allow_run_allowlist_resolution/main.out
@@ -1,15 +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 }
+---
+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/testdata/allow_run_allowlist_resolution.ts b/tests/specs/run/allow_run_allowlist_resolution/main.ts
index c7369d928..bf33d8cbe 100644
--- a/tests/testdata/allow_run_allowlist_resolution.ts
+++ b/tests/specs/run/allow_run_allowlist_resolution/main.ts
@@ -1,26 +1,26 @@
// 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.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")`** | ✅ | ✅ |
+// | **`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: "${
+ 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.log(await Deno.permissions.query({ name: "run", command: "deno" }));
- console.log(await Deno.permissions.query({ name: "run", command: "${
+ console.error(await Deno.permissions.query({ name: "run", command: "deno" }));
+ console.error(await Deno.permissions.query({ name: "run", command: "${
execPath.replaceAll("\\", "\\\\")
}" }));
`)
@@ -29,38 +29,39 @@ const testUrl = `data:application/typescript;base64,${
const process1 = await new Deno.Command(Deno.execPath(), {
args: [
"run",
- "--quiet",
"--allow-env",
"--allow-run=deno",
testUrl,
],
- stderr: "null",
+ stdout: "inherit",
+ stderr: "inherit",
env: { "PATH": execPathParent },
}).output();
-console.log(new TextDecoder().decode(process1.stdout));
-const process2 = await new Deno.Command(Deno.execPath(), {
+console.error("---");
+
+await new Deno.Command(Deno.execPath(), {
args: [
"run",
- "--quiet",
"--allow-env",
"--allow-run=deno",
testUrl,
],
- stderr: "null",
+ stderr: "inherit",
+ stdout: "inherit",
env: { "PATH": "" },
}).output();
-console.log(new TextDecoder().decode(process2.stdout));
-const process3 = await new Deno.Command(Deno.execPath(), {
+console.error("---");
+
+await new Deno.Command(Deno.execPath(), {
args: [
"run",
- "--quiet",
"--allow-env",
`--allow-run=${execPath}`,
testUrl,
],
- stderr: "null",
+ stderr: "inherit",
+ stdout: "inherit",
env: { "PATH": execPathParent },
}).output();
-console.log(new TextDecoder().decode(process3.stdout));
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);
+}
diff --git a/tests/testdata/run/089_run_allow_list.ts.out b/tests/testdata/run/089_run_allow_list.ts.out
index 68a4a2ac5..0fc1c80c2 100644
--- a/tests/testdata/run/089_run_allow_list.ts.out
+++ b/tests/testdata/run/089_run_allow_list.ts.out
@@ -1,3 +1,3 @@
-[WILDCARD]PermissionDenied: Requires run access to "ls", run again with the --allow-run flag
+[WILDCARD]PermissionDenied: Requires run access to "[WILDLINE]ls[WILDLINE]", run again with the --allow-run flag
[WILDCARD]
true
diff --git a/tests/unit/process_test.ts b/tests/unit/process_test.ts
index a35362d09..383f17f38 100644
--- a/tests/unit/process_test.ts
+++ b/tests/unit/process_test.ts
@@ -611,6 +611,6 @@ Deno.test(
p.close();
p.stdout.close();
assertStrictEquals(code, 1);
- assertStringIncludes(stderr, "Failed getting cwd.");
+ assertStringIncludes(stderr, "failed resolving cwd:");
},
);