From 65cafd2edffced763424e407eaf275f08f6da3b0 Mon Sep 17 00:00:00 2001 From: J2P Date: Sat, 9 Feb 2019 19:31:03 +0900 Subject: [PATCH] Add --allow-read test code --- tools/permission_prompt_test.py | 24 ++++++++++++++++++++++++ tools/permission_prompt_test.ts | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tools/permission_prompt_test.py b/tools/permission_prompt_test.py index e2557e8418..88fc791bf0 100755 --- a/tools/permission_prompt_test.py +++ b/tools/permission_prompt_test.py @@ -51,12 +51,15 @@ class Prompt(object): def run(self, arg, bytes_input, + allow_read=False, allow_write=False, allow_net=False, allow_env=False, allow_run=False): "Returns (return_code, stdout, stderr)." cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg] + if allow_read: + cmd.append("--allow-read") if allow_write: cmd.append("--allow-write") if allow_net: @@ -71,6 +74,24 @@ class Prompt(object): # ignore the ts compiling message self.run('needsWrite', b'', allow_write=True) + def test_read_yes(self): + code, stdout, stderr = self.run('needsRead', b'y\n') + assert code == 0 + assert stdout == b'' + assert b'⚠️ Deno requests read access' in stderr + + def test_read_arg(self): + code, stdout, stderr = self.run('needsRead', b'', allow_read=True) + assert code == 0 + assert stdout == b'' + assert stderr == b'' + + def test_read_no(self): + code, _stdout, stderr = self.run('needsRead', b'N\n') + assert code == 1 + assert b'PermissionDenied: permission denied' in stderr + assert b'⚠️ Deno requests read access' in stderr + def test_write_yes(self): code, stdout, stderr = self.run('needsWrite', b'y\n') assert code == 0 @@ -147,6 +168,9 @@ class Prompt(object): def permission_prompt_test(deno_exe): p = Prompt(deno_exe) p.warm_up() + p.test_read_yes() + p.test_read_arg() + p.test_read_no() p.test_write_yes() p.test_write_arg() p.test_write_no() diff --git a/tools/permission_prompt_test.ts b/tools/permission_prompt_test.ts index 7f62bc37d2..954d12a6ed 100644 --- a/tools/permission_prompt_test.ts +++ b/tools/permission_prompt_test.ts @@ -1,8 +1,11 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { args, listen, env, exit, makeTempDirSync, run } from "deno"; +import { args, listen, env, exit, makeTempDirSync, readFile, run} from "deno"; const name = args[1]; const test = { + needsRead: () => { + readFile("package.json") + }, needsWrite: () => { makeTempDirSync(); },