Skip to content

Commit

Permalink
Add --allow-run test code (denoland#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
J2P authored and ry committed Jan 12, 2019
1 parent 6c9695a commit 37e3db0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 25 additions & 1 deletion tools/permission_prompt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def run(self,
bytes_input,
allow_write=False,
allow_net=False,
allow_env=False):
allow_env=False,
allow_run=False):
"Returns (return_code, stdout, stderr)."
cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]
if allow_write:
Expand All @@ -60,6 +61,8 @@ def run(self,
cmd.append("--allow-net")
if allow_env:
cmd.append("--allow-env")
if allow_run:
cmd.append("--allow-run")
return tty_capture(cmd, bytes_input)

def warm_up(self):
Expand Down Expand Up @@ -120,6 +123,24 @@ def test_net_no(self):
assert b'PermissionDenied: permission denied' in stderr
assert b'Deno requests network access' in stderr

def test_run_yes(self):
code, stdout, stderr = self.run('needsRun', b'y\n')
assert code == 0
assert stdout == b'hello'
assert b'Deno requests access to run' in stderr

def test_run_arg(self):
code, stdout, stderr = self.run('needsRun', b'', allow_run=True)
assert code == 0
assert stdout == b'hello'
assert stderr == b''

def test_run_no(self):
code, _stdout, stderr = self.run('needsRun', b'N\n')
assert code == 1
assert b'PermissionDenied: permission denied' in stderr
assert b'Deno requests access to run' in stderr


def permission_prompt_test(deno_exe):
p = Prompt(deno_exe)
Expand All @@ -133,6 +154,9 @@ def permission_prompt_test(deno_exe):
p.test_net_yes()
p.test_net_arg()
p.test_net_no()
p.test_run_yes()
p.test_run_arg()
p.test_run_no()


def main():
Expand Down
5 changes: 4 additions & 1 deletion tools/permission_prompt_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { args, listen, env, exit, makeTempDirSync } from "deno";
import { args, listen, env, exit, makeTempDirSync, run } from "deno";

const name = args[1];
const test = {
Expand All @@ -10,6 +10,9 @@ const test = {
},
needsNet: () => {
listen("tcp", "127.0.0.1:4540");
},
needsRun: () => {
run({ args: ["python", "-c", "import sys; sys.stdout.write('hello')"] });
}
}[name];

Expand Down

0 comments on commit 37e3db0

Please sign in to comment.