summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/complex_permissions_test.py223
-rw-r--r--tools/complex_permissions_test.ts38
-rwxr-xr-xtools/is_tty_test.py23
-rwxr-xr-xtools/permission_prompt_test.py144
-rw-r--r--tools/permission_prompt_test.ts67
5 files changed, 0 insertions, 495 deletions
diff --git a/tools/complex_permissions_test.py b/tools/complex_permissions_test.py
deleted file mode 100755
index 9f0fcd7e7..000000000
--- a/tools/complex_permissions_test.py
+++ /dev/null
@@ -1,223 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import os
-import unittest
-
-import http_server
-from test_util import DenoTestCase, run_tests
-from util import root_path, tty_capture
-
-PERMISSIONS_PROMPT_TEST_TS = "tools/complex_permissions_test.ts"
-
-PROMPT_PATTERN = b'⚠️'
-PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'
-
-
-@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
-class BaseComplexPermissionTest(DenoTestCase):
- def _run_deno(self, flags, args):
- "Returns (return_code, stdout, stderr)."
- cmd = ([self.deno_exe, "run", "--no-prompt"] + flags +
- [PERMISSIONS_PROMPT_TEST_TS] + args)
- return tty_capture(cmd, b'')
-
-
-class BaseReadWritePermissionsTest(object):
- test_type = None
-
- def test_inside_project_dir(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-" + self.test_type + "=" + root_path],
- [self.test_type, "package.json", "cli/tests/subdir/config.json"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_outside_test_dir(self):
- code, _stdout, stderr = self._run_deno([
- "--allow-" + self.test_type + "=" + os.path.join(
- root_path, "cli/tests")
- ], [self.test_type, "package.json"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_inside_test_dir(self):
- code, _stdout, stderr = self._run_deno([
- "--allow-" + self.test_type + "=" + os.path.join(
- root_path, "cli/tests")
- ], [self.test_type, "cli/tests/subdir/config.json"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_outside_test_and_js_dir(self):
- code, _stdout, stderr = self._run_deno([
- "--allow-" + self.test_type + "=" + os.path.join(
- root_path, "cli/tests") + "," + os.path.join(
- root_path, "cli/js")
- ], [self.test_type, "package.json"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_inside_test_and_js_dir(self):
- code, _stdout, stderr = self._run_deno([
- "--allow-" + self.test_type + "=" + os.path.join(
- root_path, "cli/tests") + "," + os.path.join(
- root_path, "cli/js")
- ], [
- self.test_type, "cli/js/dir_test.ts",
- "cli/tests/subdir/config.json"
- ])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_relative(self):
- # Save and restore curdir
- saved_curdir = os.getcwd()
- os.chdir(root_path)
- code, _stdout, stderr = self._run_deno(
- ["--allow-" + self.test_type + "=" + "./cli/tests"],
- [self.test_type, "cli/tests/subdir/config.json"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
- os.chdir(saved_curdir)
-
- def test_no_prefix(self):
- # Save and restore curdir
- saved_curdir = os.getcwd()
- os.chdir(root_path)
- code, _stdout, stderr = self._run_deno(
- ["--allow-" + self.test_type + "=" + "cli/tests"],
- [self.test_type, "cli/tests/subdir/config.json"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
- os.chdir(saved_curdir)
-
-
-class TestReadPermissions(BaseReadWritePermissionsTest,
- BaseComplexPermissionTest):
- test_type = "read"
-
-
-class TestWritePermissions(BaseReadWritePermissionsTest,
- BaseComplexPermissionTest):
- test_type = "write"
-
-
-class TestNetFetchPermissions(BaseComplexPermissionTest):
- test_type = "netFetch"
-
- def test_allow_localhost_4545(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=localhost:4545"],
- [self.test_type, "http://localhost:4545"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_allow_deno_land(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=deno.land"],
- [self.test_type, "http://localhost:4545"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost_4545_fail(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=localhost:4545"],
- [self.test_type, "http://localhost:4546"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost(self):
- code, _stdout, stderr = self._run_deno(["--allow-net=localhost"], [
- self.test_type, "http://localhost:4545", "http://localhost:4546",
- "http://localhost:4547"
- ])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
-
-class TestNetDialPermissions(BaseComplexPermissionTest):
- test_type = "netDial"
-
- def test_allow_localhost_ip_4555(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=127.0.0.1:4545"], [self.test_type, "127.0.0.1:4545"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_allow_deno_land(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=deno.land"], [self.test_type, "127.0.0.1:4545"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost_ip_4545_fail(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=127.0.0.1:4545"], [self.test_type, "127.0.0.1:4546"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost_ip(self):
- code, _stdout, stderr = self._run_deno(["--allow-net=127.0.0.1"], [
- self.test_type, "127.0.0.1:4545", "127.0.0.1:4546",
- "127.0.0.1:4547"
- ])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
-
-class TestNetListenPermissions(BaseComplexPermissionTest):
- test_type = "netListen"
-
- def test_allow_localhost_4555(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=localhost:4555"], [self.test_type, "localhost:4555"])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_allow_deno_land(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=deno.land"], [self.test_type, "localhost:4545"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost_4555_fail(self):
- code, _stdout, stderr = self._run_deno(
- ["--allow-net=localhost:4555"], [self.test_type, "localhost:4556"])
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_allow_localhost(self):
- code, _stdout, stderr = self._run_deno(["--allow-net=localhost"], [
- self.test_type, "localhost:4555", "localhost:4556",
- "localhost:4557"
- ])
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert PERMISSION_DENIED_PATTERN not in stderr
-
-
-def complex_permissions_tests():
- return BaseComplexPermissionTest.__subclasses__()
-
-
-if __name__ == "__main__":
- run_tests()
diff --git a/tools/complex_permissions_test.ts b/tools/complex_permissions_test.ts
deleted file mode 100644
index a2e0f7824..000000000
--- a/tools/complex_permissions_test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-const { args, readFileSync, writeFileSync, exit } = Deno;
-
-const name = args[1];
-const test: (args: string[]) => void = {
- read(files: string[]): void {
- files.forEach(file => readFileSync(file));
- },
- write(files: string[]): void {
- files.forEach(file =>
- writeFileSync(file, new Uint8Array(0), { append: true })
- );
- },
- netFetch(hosts: string[]): void {
- hosts.forEach(host => fetch(host));
- },
- netListen(hosts: string[]): void {
- hosts.forEach(host => {
- const [hostname, port] = host.split(":");
- const listener = Deno.listen({ hostname, port: Number(port) });
- listener.close();
- });
- },
- async netDial(hosts: string[]): Promise<void> {
- for (const host of hosts) {
- const [hostname, port] = host.split(":");
- const listener = await Deno.dial({ hostname, port: Number(port) });
- listener.close();
- }
- }
-}[name];
-
-if (!test) {
- console.log("Unknown test:", name);
- exit(1);
-}
-
-test(args.slice(2));
diff --git a/tools/is_tty_test.py b/tools/is_tty_test.py
deleted file mode 100755
index 16a4ef255..000000000
--- a/tools/is_tty_test.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import os
-import unittest
-from sys import stdin
-
-from test_util import DenoTestCase, run_tests
-from util import tty_capture
-
-IS_TTY_TEST_TS = "tests/is_tty.ts"
-
-
-@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
-class TestIsTty(DenoTestCase):
- def test_is_tty(self):
- cmd = [self.deno_exe, "run", IS_TTY_TEST_TS]
- code, stdout, _ = tty_capture(cmd, b'')
- assert code == 0
- assert str(stdin.isatty()).lower() in stdout
-
-
-if __name__ == "__main__":
- run_tests()
diff --git a/tools/permission_prompt_test.py b/tools/permission_prompt_test.py
deleted file mode 100755
index e5516e450..000000000
--- a/tools/permission_prompt_test.py
+++ /dev/null
@@ -1,144 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import os
-import unittest
-
-from test_util import DenoTestCase, run_tests
-from util import tty_capture
-
-PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts"
-
-PROMPT_PATTERN = b'⚠️'
-FIRST_CHECK_FAILED_PATTERN = b'First check failed'
-PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'
-
-
-@unittest.skipIf(os.name == 'nt', "Unable to test tty on Windows")
-class BasePromptTest(object):
- def _run_deno(self, flags, args, bytes_input):
- "Returns (return_code, stdout, stderr)."
- cmd = [self.deno_exe, "run"] + flags + [PERMISSIONS_PROMPT_TEST_TS
- ] + args
- return tty_capture(cmd, bytes_input)
-
- def test_allow_flag(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- ["--allow-" + test_type], ["needs" + test_type.capitalize()], b'')
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_yes_yes(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'y\ny\n')
- assert code == 0
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_yes_no(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'y\nn\n')
- assert code == 1
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_no_no(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'n\nn\n')
- assert code == 1
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN in stdout
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_no_yes(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'n\ny\n')
- assert code == 0
-
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_allow(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'a\n')
- assert code == 0
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
-
- def test_deny(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'd\n')
- assert code == 1
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN in stdout
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_unrecognized_option(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- [], ["needs" + test_type.capitalize()], b'e\na\n')
- assert code == 0
- assert PROMPT_PATTERN in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
- assert b'Unrecognized option' in stderr
-
- def test_no_prompt(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- ["--no-prompt"], ["needs" + test_type.capitalize()], b'')
- assert code == 1
- assert PROMPT_PATTERN not in stderr
- assert FIRST_CHECK_FAILED_PATTERN in stdout
- assert PERMISSION_DENIED_PATTERN in stderr
-
- def test_no_prompt_allow(self):
- test_type = self.test_type
- code, stdout, stderr = self._run_deno(
- ["--no-prompt", "--allow-" + test_type],
- ["needs" + test_type.capitalize()], b'')
- assert code == 0
- assert PROMPT_PATTERN not in stderr
- assert FIRST_CHECK_FAILED_PATTERN not in stdout
- assert PERMISSION_DENIED_PATTERN not in stderr
-
-
-class ReadPromptTest(DenoTestCase, BasePromptTest):
- test_type = "read"
-
-
-class WritePromptTest(DenoTestCase, BasePromptTest):
- test_type = "write"
-
-
-class EnvPromptTest(DenoTestCase, BasePromptTest):
- test_type = "env"
-
-
-class NetPromptTest(DenoTestCase, BasePromptTest):
- test_type = "net"
-
-
-class RunPromptTest(DenoTestCase, BasePromptTest):
- test_type = "run"
-
-
-def permission_prompt_tests():
- return BasePromptTest.__subclasses__()
-
-
-if __name__ == "__main__":
- run_tests()
diff --git a/tools/permission_prompt_test.ts b/tools/permission_prompt_test.ts
deleted file mode 100644
index 2d01b4ad5..000000000
--- a/tools/permission_prompt_test.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-const { args, env, exit, listen, makeTempDirSync, readFileSync, run } = Deno;
-
-const firstCheckFailedMessage = "First check failed";
-
-const name = args[1];
-const test = {
- async needsRead(): Promise<void> {
- try {
- readFileSync("package.json");
- } catch (e) {
- console.log(firstCheckFailedMessage);
- }
- readFileSync("package.json");
- },
- needsWrite(): void {
- try {
- makeTempDirSync();
- } catch (e) {
- console.log(firstCheckFailedMessage);
- }
- makeTempDirSync();
- },
- needsEnv(): void {
- try {
- env().home;
- } catch (e) {
- console.log(firstCheckFailedMessage);
- }
- env().home;
- },
- needsNet(): void {
- try {
- listen({ hostname: "127.0.0.1", port: 4540 });
- } catch (e) {
- console.log(firstCheckFailedMessage);
- }
- listen({ hostname: "127.0.0.1", port: 4541 });
- },
- needsRun(): void {
- try {
- run({
- args: [
- "python",
- "-c",
- "import sys; sys.stdout.write('hello'); sys.stdout.flush()"
- ]
- });
- } catch (e) {
- console.log(firstCheckFailedMessage);
- }
- run({
- args: [
- "python",
- "-c",
- "import sys; sys.stdout.write('hello'); sys.stdout.flush()"
- ]
- });
- }
-}[name];
-
-if (!test) {
- console.log("Unknown test:", name);
- exit(1);
-}
-
-test();