1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Testing the following:
// | `deno run --allow-run=binary` | `which path == "/usr/bin/binary"` at startup | `which path != "/usr/bin/binary"` at startup |
// |---------------------------------------|----------------------------------------------|--------------------------------------------|
// | **`Deno.Command("binary")`** | :white_check_mark: | :white_check_mark: |
// | **`Deno.Command("/usr/bin/binary")`** | :white_check_mark: | :x: |
// | `deno run --allow-run=/usr/bin/binary | `which path == "/usr/bin/binary"` at runtime | `which path != "/usr/bin/binary"` at runtime |
// |---------------------------------------|----------------------------------------------|--------------------------------------------|
// | **`Deno.Command("binary")`** | :white_check_mark: | :x: |
// | **`Deno.Command("/usr/bin/binary")`** | :white_check_mark: | :white_check_mark: |
const binaryName = Deno.build.os === "windows" ? "binary.exe" : "binary";
const pathSep = Deno.build.os === "windows" ? "\\" : "/";
const cwd = Deno.cwd();
const execPathParent = `${Deno.cwd()}${pathSep}sub`;
const execPath = `${execPathParent}${pathSep}${binaryName}`;
Deno.mkdirSync(execPathParent);
Deno.copyFileSync(Deno.execPath(), execPath);
const testUrl = `data:application/typescript;base64,${
btoa(`
console.error(await Deno.permissions.query({ name: "run", command: "binary" }));
console.error(await Deno.permissions.query({ name: "run", command: "${
execPath.replaceAll("\\", "\\\\")
}" }));
Deno.env.set("PATH", "");
console.error(await Deno.permissions.query({ name: "run", command: "binary" }));
console.error(await Deno.permissions.query({ name: "run", command: "${
execPath.replaceAll("\\", "\\\\")
}" }));
`)
}`;
await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--allow-env",
"--allow-run=binary",
testUrl,
],
stdout: "inherit",
stderr: "inherit",
env: { "PATH": execPathParent },
}).output();
console.error("---");
await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--allow-env",
"--allow-run=binary",
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();
|