From 2ba9ccc1ab25e5c631afcbb12b53f4545ca7f750 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 11 May 2023 13:53:45 +0100 Subject: fix(runtime): `ChildProcess::kill()` doesn't require additional perms (#15339) Fixes #15217. --- cli/tests/integration/run_tests.rs | 5 +++++ cli/tests/testdata/spawn_kill_permissions.ts | 6 ++++++ cli/tests/unit/command_test.ts | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 cli/tests/testdata/spawn_kill_permissions.ts (limited to 'cli/tests') diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 26aacc6fd..e6ea85da4 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -3435,6 +3435,11 @@ itest!(test_and_bench_are_noops_in_run { output_str: Some(""), }); +itest!(spawn_kill_permissions { + args: "run --quiet --unstable --allow-run=deno spawn_kill_permissions.ts", + output_str: Some(""), +}); + itest!(followup_dyn_import_resolved { args: "run --unstable --allow-read run/followup_dyn_import_resolves/main.ts", output: "run/followup_dyn_import_resolves/main.ts.out", diff --git a/cli/tests/testdata/spawn_kill_permissions.ts b/cli/tests/testdata/spawn_kill_permissions.ts new file mode 100644 index 000000000..e0c1b7bfd --- /dev/null +++ b/cli/tests/testdata/spawn_kill_permissions.ts @@ -0,0 +1,6 @@ +const child = new Deno.Command("deno", { + args: ["eval", "await new Promise(r => setTimeout(r, 2000))"], + stdout: "null", + stderr: "null", +}).spawn(); +child.kill("SIGTERM"); diff --git a/cli/tests/unit/command_test.ts b/cli/tests/unit/command_test.ts index 0763a7ac6..198f94aed 100644 --- a/cli/tests/unit/command_test.ts +++ b/cli/tests/unit/command_test.ts @@ -867,3 +867,21 @@ Deno.test( } }, ); + +Deno.test( + { permissions: { run: true, read: true } }, + async function commandKillAfterStatus() { + const command = new Deno.Command(Deno.execPath(), { + args: ["help"], + stdout: "null", + stderr: "null", + }); + const child = command.spawn(); + await child.status; + assertThrows( + () => child.kill(), + TypeError, + "Child process has already terminated.", + ); + }, +); -- cgit v1.2.3