Mercurial > vim
comparison src/testdir/test_restricted.vim @ 19787:906269bf83d5 v8.2.0450
patch 8.2.0450: not enough testing for restricted mode and function calls
Commit: https://github.com/vim/vim/commit/7d941ee032c02a4b682201881eb5c1f1958f17ee
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 26 14:11:58 2020 +0100
patch 8.2.0450: not enough testing for restricted mode and function calls
Problem: Not enough testing for restricted mode and function calls.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5847)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 Mar 2020 14:15:04 +0100 |
parents | cf702b29ea0d |
children | 12518b40c161 |
comparison
equal
deleted
inserted
replaced
19786:ae9edaa6f0f5 | 19787:906269bf83d5 |
---|---|
5 "if has('win32') && has('gui') | 5 "if has('win32') && has('gui') |
6 " " Win32 GUI shows a dialog instead of displaying the error in the last line. | 6 " " Win32 GUI shows a dialog instead of displaying the error in the last line. |
7 " finish | 7 " finish |
8 "endif | 8 "endif |
9 | 9 |
10 func Test_restricted() | 10 func Test_restricted_mode() |
11 call Run_restricted_test('!ls', 'E145:') | 11 let lines =<< trim END |
12 if has('lua') | |
13 call assert_fails('lua print("Hello, Vim!")', 'E981:') | |
14 call assert_fails('luado return "hello"', 'E981:') | |
15 call assert_fails('luafile somefile', 'E981:') | |
16 call assert_fails('call luaeval("expression")', 'E145:') | |
17 endif | |
18 | |
19 if has('mzscheme') | |
20 call assert_fails('mzscheme statement', 'E981:') | |
21 call assert_fails('mzfile somefile', 'E981:') | |
22 call assert_fails('call mzeval("expression")', 'E145:') | |
23 endif | |
24 | |
25 if has('perl') | |
26 " TODO: how to make Safe mode fail? | |
27 " call assert_fails('perl system("ls")', 'E981:') | |
28 " call assert_fails('perldo system("hello")', 'E981:') | |
29 " call assert_fails('perlfile somefile', 'E981:') | |
30 " call assert_fails('call perleval("system(\"ls\")")', 'E145:') | |
31 endif | |
32 | |
33 if has('python') | |
34 call assert_fails('python print "hello"', 'E981:') | |
35 call assert_fails('pydo return "hello"', 'E981:') | |
36 call assert_fails('pyfile somefile', 'E981:') | |
37 call assert_fails('call pyeval("expression")', 'E145:') | |
38 endif | |
39 | |
40 if has('python3') | |
41 call assert_fails('py3 print "hello"', 'E981:') | |
42 call assert_fails('py3do return "hello"', 'E981:') | |
43 call assert_fails('py3file somefile', 'E981:') | |
44 call assert_fails('call py3eval("expression")', 'E145:') | |
45 endif | |
46 | |
47 if has('ruby') | |
48 call assert_fails('ruby print "Hello"', 'E981:') | |
49 call assert_fails('rubydo print "Hello"', 'E981:') | |
50 call assert_fails('rubyfile somefile', 'E981:') | |
51 endif | |
52 | |
53 if has('tcl') | |
54 call assert_fails('tcl puts "Hello"', 'E981:') | |
55 call assert_fails('tcldo puts "Hello"', 'E981:') | |
56 call assert_fails('tclfile somefile', 'E981:') | |
57 endif | |
58 | |
59 if has('clientserver') | |
60 call assert_fails('let s=remote_peek(10)', 'E145:') | |
61 call assert_fails('let s=remote_read(10)', 'E145:') | |
62 call assert_fails('let s=remote_send("vim", "abc")', 'E145:') | |
63 call assert_fails('let s=server2client(10, "abc")', 'E145:') | |
64 endif | |
65 | |
66 if has('terminal') | |
67 call assert_fails('terminal', 'E145:') | |
68 call assert_fails('call term_start("vim")', 'E145:') | |
69 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E145:') | |
70 endif | |
71 | |
72 if has('channel') | |
73 call assert_fails("call ch_logfile('Xlog')", 'E145:') | |
74 call assert_fails("call ch_open('localhost:8765')", 'E145:') | |
75 endif | |
76 | |
77 if has('job') | |
78 call assert_fails("call job_start('vim')", 'E145:') | |
79 endif | |
80 | |
81 if has('libcall') | |
82 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E145:') | |
83 endif | |
84 call assert_fails("call rename('a', 'b')", 'E145:') | |
85 call assert_fails("call delete('Xfile')", 'E145:') | |
86 call assert_fails("call mkdir('Xdir')", 'E145:') | |
87 call assert_fails('!ls', 'E145:') | |
88 call assert_fails('shell', 'E145:') | |
89 call assert_fails('stop', 'E145:') | |
90 call assert_fails('suspend', 'E145:') | |
91 call assert_fails('call system("vim")', 'E145:') | |
92 call assert_fails('call systemlist("vim")', 'E145:') | |
93 if has('unix') | |
94 call assert_fails('cd `pwd`', 'E145:') | |
95 endif | |
96 | |
97 call writefile(v:errors, 'Xresult') | |
98 qa! | |
99 END | |
100 call writefile(lines, 'Xrestricted') | |
101 if RunVim([], [], '-Z --clean -S Xrestricted') | |
102 call assert_equal([], readfile('Xresult')) | |
103 endif | |
104 | |
105 call delete('Xrestricted') | |
106 call delete('Xresult') | |
12 endfunc | 107 endfunc |
13 | 108 |
14 func Run_restricted_test(ex_cmd, error) | 109 " vim: shiftwidth=2 sts=2 expandtab |
15 let cmd = GetVimCommand('Xrestricted') | |
16 if cmd == '' | |
17 return | |
18 endif | |
19 | |
20 " Use a VimEnter autocommand to avoid that the error message is displayed in | |
21 " a dialog with an OK button. | |
22 call writefile([ | |
23 \ "func Init()", | |
24 \ " silent! " . a:ex_cmd, | |
25 \ " call writefile([v:errmsg], 'Xrestrout')", | |
26 \ " qa!", | |
27 \ "endfunc", | |
28 \ "au VimEnter * call Init()", | |
29 \ ], 'Xrestricted') | |
30 call system(cmd . ' -Z') | |
31 call assert_match(a:error, join(readfile('Xrestrout'))) | |
32 | |
33 call delete('Xrestricted') | |
34 call delete('Xrestrout') | |
35 endfunc | |
36 | |
37 func Test_restricted_lua() | |
38 if !has('lua') | |
39 throw 'Skipped: Lua is not supported' | |
40 endif | |
41 call Run_restricted_test('lua print("Hello, Vim!")', 'E981:') | |
42 call Run_restricted_test('luado return "hello"', 'E981:') | |
43 call Run_restricted_test('luafile somefile', 'E981:') | |
44 call Run_restricted_test('call luaeval("expression")', 'E145:') | |
45 endfunc | |
46 | |
47 func Test_restricted_mzscheme() | |
48 if !has('mzscheme') | |
49 throw 'Skipped: MzScheme is not supported' | |
50 endif | |
51 call Run_restricted_test('mzscheme statement', 'E981:') | |
52 call Run_restricted_test('mzfile somefile', 'E981:') | |
53 call Run_restricted_test('call mzeval("expression")', 'E145:') | |
54 endfunc | |
55 | |
56 func Test_restricted_perl() | |
57 if !has('perl') | |
58 throw 'Skipped: Perl is not supported' | |
59 endif | |
60 " TODO: how to make Safe mode fail? | |
61 " call Run_restricted_test('perl system("ls")', 'E981:') | |
62 " call Run_restricted_test('perldo system("hello")', 'E981:') | |
63 " call Run_restricted_test('perlfile somefile', 'E981:') | |
64 " call Run_restricted_test('call perleval("system(\"ls\")")', 'E145:') | |
65 endfunc | |
66 | |
67 func Test_restricted_python() | |
68 if !has('python') | |
69 throw 'Skipped: Python is not supported' | |
70 endif | |
71 call Run_restricted_test('python print "hello"', 'E981:') | |
72 call Run_restricted_test('pydo return "hello"', 'E981:') | |
73 call Run_restricted_test('pyfile somefile', 'E981:') | |
74 call Run_restricted_test('call pyeval("expression")', 'E145:') | |
75 endfunc | |
76 | |
77 func Test_restricted_python3() | |
78 if !has('python3') | |
79 throw 'Skipped: Python3 is not supported' | |
80 endif | |
81 call Run_restricted_test('py3 print "hello"', 'E981:') | |
82 call Run_restricted_test('py3do return "hello"', 'E981:') | |
83 call Run_restricted_test('py3file somefile', 'E981:') | |
84 call Run_restricted_test('call py3eval("expression")', 'E145:') | |
85 endfunc | |
86 | |
87 func Test_restricted_ruby() | |
88 if !has('ruby') | |
89 throw 'Skipped: Ruby is not supported' | |
90 endif | |
91 call Run_restricted_test('ruby print "Hello"', 'E981:') | |
92 call Run_restricted_test('rubydo print "Hello"', 'E981:') | |
93 call Run_restricted_test('rubyfile somefile', 'E981:') | |
94 endfunc | |
95 | |
96 func Test_restricted_tcl() | |
97 if !has('tcl') | |
98 throw 'Skipped: Tcl is not supported' | |
99 endif | |
100 call Run_restricted_test('tcl puts "Hello"', 'E981:') | |
101 call Run_restricted_test('tcldo puts "Hello"', 'E981:') | |
102 call Run_restricted_test('tclfile somefile', 'E981:') | |
103 endfunc |