diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-05-23 22:47:55 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-23 23:47:55 +0300 |
commit | 1105982586d9554a5e7bf54fd4dc25c8724cd130 (patch) | |
tree | 4e15f0ad3098204ae2eca8f0ccdb644b8d8be9a7 /tools/complex_permissions_test.py | |
parent | f92af3576afe9567d829aed3cf78836cb587c944 (diff) |
re-fix permissions for dial and listen (#2400)
Closes #2397
Diffstat (limited to 'tools/complex_permissions_test.py')
-rwxr-xr-x | tools/complex_permissions_test.py | 152 |
1 files changed, 118 insertions, 34 deletions
diff --git a/tools/complex_permissions_test.py b/tools/complex_permissions_test.py index 8fdc99d8b..0b8269849 100755 --- a/tools/complex_permissions_test.py +++ b/tools/complex_permissions_test.py @@ -8,6 +8,7 @@ import subprocess import sys import time +import http_server from util import build_path, root_path, executable_suffix, green_ok, red_failed PERMISSIONS_PROMPT_TEST_TS = "tools/complex_permissions_test.ts" @@ -96,15 +97,53 @@ class Prompt(object): test_type) wrap_test(test_name_base + "_no_prefix", self.test_no_prefix, test_type) + + test_name = "net_fetch" + test_name_base = "test_" + test_name wrap_test(test_name_base + "_allow_localhost_4545", - self.test_allow_localhost_4545) + self.test_allow_localhost_4545, test_name, + ["http://localhost:4545"]) wrap_test(test_name_base + "_allow_deno_land", - self.test_allow_deno_land) + self.test_allow_deno_land, test_name, + ["http://localhost:4545"]) wrap_test(test_name_base + "_allow_localhost_4545_fail", - self.test_allow_localhost_4545_fail) + self.test_allow_localhost_4545_fail, test_name, + ["http://localhost:4546"]) wrap_test(test_name_base + "_allow_localhost", - self.test_allow_localhost) + self.test_allow_localhost, test_name, [ + "http://localhost:4545", "http://localhost:4546", + "http://localhost:4547" + ]) + + test_name = "net_dial" + test_name_base = "test_" + test_name + wrap_test(test_name_base + "_allow_127.0.0.1:4545", + self.test_allow_localhost_ip_4555, test_name, + ["127.0.0.1:4545"]) + wrap_test(test_name_base + "_allow_deno_land", + self.test_allow_deno_land, test_name, ["127.0.0.1:4545"]) + wrap_test(test_name_base + "_allow_127.0.0.1:4545_fail", + self.test_allow_localhost_ip_4545_fail, test_name, + ["127.0.0.1:4546"]) + wrap_test(test_name_base + "_allow_127.0.0.1", + self.test_allow_localhost_ip, test_name, + ["127.0.0.1:4545", "127.0.0.1:4546", "127.0.0.1:4547"]) + test_name = "net_listen" + test_name_base = "test_" + test_name + wrap_test(test_name_base + "_allow_localhost_4555", + self.test_allow_localhost_4555, test_name, + ["localhost:4555"]) + wrap_test(test_name_base + "_allow_deno_land", + self.test_allow_deno_land, test_name, ["localhost:4545"]) + wrap_test(test_name_base + "_allow_localhost_4555_fail", + self.test_allow_localhost_4555_fail, test_name, + ["localhost:4556"]) + wrap_test(test_name_base + "_allow_localhost", + self.test_allow_localhost, test_name, + ["localhost:4555", "localhost:4556", "localhost:4557"]) + + # read/write tests def test_inside_project_dir(self, test_type): code, _stdout, stderr = self.run( ["--no-prompt", "--allow-" + test_type + "=" + root_path], @@ -149,63 +188,107 @@ class Prompt(object): assert not PROMPT_PATTERN in stderr assert not PERMISSION_DENIED_PATTERN in stderr - def test_allow_localhost_4545(self): + def test_relative(self, test_type): + # Save and restore curdir + saved_curdir = os.getcwd() + os.chdir(root_path) + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-" + test_type + "=" + "./tests"], + [test_type, "tests/subdir/config.json"], b'') + assert code == 0 + assert not PROMPT_PATTERN in stderr + assert not PERMISSION_DENIED_PATTERN in stderr + os.chdir(saved_curdir) + + def test_no_prefix(self, test_type): + # Save and restore curdir + saved_curdir = os.getcwd() + os.chdir(root_path) + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-" + test_type + "=" + "tests"], + [test_type, "tests/subdir/config.json"], b'') + assert code == 0 + assert not PROMPT_PATTERN in stderr + assert not PERMISSION_DENIED_PATTERN in stderr + os.chdir(saved_curdir) + + # net tests + def test_allow_net(self, test_type, allowed_host, hosts): + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-net=" + allowed_host], + [test_type] + hosts, b'') + assert code == 0 + assert not PROMPT_PATTERN in stderr + assert not PERMISSION_DENIED_PATTERN in stderr + + def test_allow_localhost_4545(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-net=localhost:4545"], - ["net", "http://localhost:4545"], b'') + ["--no-prompt", "--allow-net=localhost:4545"], [test_type] + hosts, + b'') assert code == 0 assert not PROMPT_PATTERN in stderr assert not PERMISSION_DENIED_PATTERN in stderr - def test_allow_deno_land(self): + def test_allow_localhost_ip_4555(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-net=deno.land"], - ["net", "http://localhost:4545"], b'') + ["--no-prompt", "--allow-net=127.0.0.1:4545"], [test_type] + hosts, + b'') + assert code == 0 + assert not PROMPT_PATTERN in stderr + assert not PERMISSION_DENIED_PATTERN in stderr + + def test_allow_localhost_4555(self, test_type, hosts): + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-net=localhost:4555"], [test_type] + hosts, + b'') + assert code == 0 + assert not PROMPT_PATTERN in stderr + assert not PERMISSION_DENIED_PATTERN in stderr + + def test_allow_deno_land(self, test_type, hosts): + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-net=deno.land"], [test_type] + hosts, b'') assert code == 1 assert not PROMPT_PATTERN in stderr assert PERMISSION_DENIED_PATTERN in stderr - def test_allow_localhost_4545_fail(self): + def test_allow_localhost_4545_fail(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-net=localhost:4545"], - ["net", "http://localhost:4546"], b'') + ["--no-prompt", "--allow-net=localhost:4545"], [test_type] + hosts, + b'') assert code == 1 assert not PROMPT_PATTERN in stderr assert PERMISSION_DENIED_PATTERN in stderr - def test_allow_localhost(self): + def test_allow_localhost_ip_4545_fail(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-net=localhost"], [ - "net", "http://localhost:4545", "http://localhost:4546", - "http://localhost:4547" - ], b'') - assert code == 0 + ["--no-prompt", "--allow-net=127.0.0.1:4545"], [test_type] + hosts, + b'') + assert code == 1 assert not PROMPT_PATTERN in stderr - assert not PERMISSION_DENIED_PATTERN in stderr + assert PERMISSION_DENIED_PATTERN in stderr - def test_relative(self, test_type): - # Save and restore curdir - saved_curdir = os.getcwd() - os.chdir(root_path) + def test_allow_localhost_4555_fail(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-" + test_type + "=" + "./tests"], - [test_type, "tests/subdir/config.json"], b'') + ["--no-prompt", "--allow-net=localhost:4555"], [test_type] + hosts, + b'') + assert code == 1 + assert not PROMPT_PATTERN in stderr + assert PERMISSION_DENIED_PATTERN in stderr + + def test_allow_localhost(self, test_type, hosts): + code, _stdout, stderr = self.run( + ["--no-prompt", "--allow-net=localhost"], [test_type] + hosts, b'') assert code == 0 assert not PROMPT_PATTERN in stderr assert not PERMISSION_DENIED_PATTERN in stderr - os.chdir(saved_curdir) - def test_no_prefix(self, test_type): - # Save and restore curdir - saved_curdir = os.getcwd() - os.chdir(root_path) + def test_allow_localhost_ip(self, test_type, hosts): code, _stdout, stderr = self.run( - ["--no-prompt", "--allow-" + test_type + "=" + "tests"], - [test_type, "tests/subdir/config.json"], b'') + ["--no-prompt", "--allow-net=127.0.0.1"], [test_type] + hosts, b'') assert code == 0 assert not PROMPT_PATTERN in stderr assert not PERMISSION_DENIED_PATTERN in stderr - os.chdir(saved_curdir) def complex_permissions_test(deno_exe): @@ -216,6 +299,7 @@ def complex_permissions_test(deno_exe): def main(): print "Permissions prompt tests" deno_exe = os.path.join(build_path(), "deno" + executable_suffix) + http_server.spawn() complex_permissions_test(deno_exe) |