mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
Add --allow-read test code
This commit is contained in:
parent
636e234e4c
commit
65cafd2edf
2 changed files with 28 additions and 1 deletions
|
@ -51,12 +51,15 @@ class Prompt(object):
|
||||||
def run(self,
|
def run(self,
|
||||||
arg,
|
arg,
|
||||||
bytes_input,
|
bytes_input,
|
||||||
|
allow_read=False,
|
||||||
allow_write=False,
|
allow_write=False,
|
||||||
allow_net=False,
|
allow_net=False,
|
||||||
allow_env=False,
|
allow_env=False,
|
||||||
allow_run=False):
|
allow_run=False):
|
||||||
"Returns (return_code, stdout, stderr)."
|
"Returns (return_code, stdout, stderr)."
|
||||||
cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]
|
cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]
|
||||||
|
if allow_read:
|
||||||
|
cmd.append("--allow-read")
|
||||||
if allow_write:
|
if allow_write:
|
||||||
cmd.append("--allow-write")
|
cmd.append("--allow-write")
|
||||||
if allow_net:
|
if allow_net:
|
||||||
|
@ -71,6 +74,24 @@ class Prompt(object):
|
||||||
# ignore the ts compiling message
|
# ignore the ts compiling message
|
||||||
self.run('needsWrite', b'', allow_write=True)
|
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):
|
def test_write_yes(self):
|
||||||
code, stdout, stderr = self.run('needsWrite', b'y\n')
|
code, stdout, stderr = self.run('needsWrite', b'y\n')
|
||||||
assert code == 0
|
assert code == 0
|
||||||
|
@ -147,6 +168,9 @@ class Prompt(object):
|
||||||
def permission_prompt_test(deno_exe):
|
def permission_prompt_test(deno_exe):
|
||||||
p = Prompt(deno_exe)
|
p = Prompt(deno_exe)
|
||||||
p.warm_up()
|
p.warm_up()
|
||||||
|
p.test_read_yes()
|
||||||
|
p.test_read_arg()
|
||||||
|
p.test_read_no()
|
||||||
p.test_write_yes()
|
p.test_write_yes()
|
||||||
p.test_write_arg()
|
p.test_write_arg()
|
||||||
p.test_write_no()
|
p.test_write_no()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// 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 name = args[1];
|
||||||
const test = {
|
const test = {
|
||||||
|
needsRead: () => {
|
||||||
|
readFile("package.json")
|
||||||
|
},
|
||||||
needsWrite: () => {
|
needsWrite: () => {
|
||||||
makeTempDirSync();
|
makeTempDirSync();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue