annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15748
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test for "rvim" or "vim -Z"
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source shared.vim
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4
15778
cf702b29ea0d patch 8.1.0896: tests for restricted mode no run for MS-Windows GUI
Bram Moolenaar <Bram@vim.org>
parents: 15756
diff changeset
5 "if has('win32') && has('gui')
cf702b29ea0d patch 8.1.0896: tests for restricted mode no run for MS-Windows GUI
Bram Moolenaar <Bram@vim.org>
parents: 15756
diff changeset
6 " " Win32 GUI shows a dialog instead of displaying the error in the last line.
cf702b29ea0d patch 8.1.0896: tests for restricted mode no run for MS-Windows GUI
Bram Moolenaar <Bram@vim.org>
parents: 15756
diff changeset
7 " finish
cf702b29ea0d patch 8.1.0896: tests for restricted mode no run for MS-Windows GUI
Bram Moolenaar <Bram@vim.org>
parents: 15756
diff changeset
8 "endif
15756
e43f30c5bad8 patch 8.1.0885: test for restricted hangs on MS-Windows GUI
Bram Moolenaar <Bram@vim.org>
parents: 15748
diff changeset
9
19787
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
10 func Test_restricted_mode()
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
11 let lines =<< trim END
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
12 if has('lua')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
13 call assert_fails('lua print("Hello, Vim!")', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
14 call assert_fails('luado return "hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
15 call assert_fails('luafile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
16 call assert_fails('call luaeval("expression")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
17 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
18
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
19 if has('mzscheme')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
20 call assert_fails('mzscheme statement', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
21 call assert_fails('mzfile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
22 call assert_fails('call mzeval("expression")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
23 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
24
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
25 if has('perl')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
26 " TODO: how to make Safe mode fail?
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
27 " call assert_fails('perl system("ls")', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
28 " call assert_fails('perldo system("hello")', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
29 " call assert_fails('perlfile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
30 " call assert_fails('call perleval("system(\"ls\")")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
31 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
32
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
33 if has('python')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
34 call assert_fails('python print "hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
35 call assert_fails('pydo return "hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
36 call assert_fails('pyfile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
37 call assert_fails('call pyeval("expression")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
38 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
39
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
40 if has('python3')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
41 call assert_fails('py3 print "hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
42 call assert_fails('py3do return "hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
43 call assert_fails('py3file somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
44 call assert_fails('call py3eval("expression")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
45 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
46
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
47 if has('ruby')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
48 call assert_fails('ruby print "Hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
49 call assert_fails('rubydo print "Hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
50 call assert_fails('rubyfile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
51 endif
15748
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52
19787
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
53 if has('tcl')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
54 call assert_fails('tcl puts "Hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
55 call assert_fails('tcldo puts "Hello"', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
56 call assert_fails('tclfile somefile', 'E981:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
57 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
58
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
59 if has('clientserver')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
60 call assert_fails('let s=remote_peek(10)', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
61 call assert_fails('let s=remote_read(10)', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
62 call assert_fails('let s=remote_send("vim", "abc")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
63 call assert_fails('let s=server2client(10, "abc")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
64 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
65
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
66 if has('terminal')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
67 call assert_fails('terminal', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
68 call assert_fails('call term_start("vim")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
69 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
70 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
71
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
72 if has('channel')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
73 call assert_fails("call ch_logfile('Xlog')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
74 call assert_fails("call ch_open('localhost:8765')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
75 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
76
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
77 if has('job')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
78 call assert_fails("call job_start('vim')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
79 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
80
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
81 if has('libcall')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
82 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
83 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
84 call assert_fails("call rename('a', 'b')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
85 call assert_fails("call delete('Xfile')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
86 call assert_fails("call mkdir('Xdir')", 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
87 call assert_fails('!ls', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
88 call assert_fails('shell', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
89 call assert_fails('stop', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
90 call assert_fails('suspend', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
91 call assert_fails('call system("vim")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
92 call assert_fails('call systemlist("vim")', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
93 if has('unix')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
94 call assert_fails('cd `pwd`', 'E145:')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
95 endif
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
96
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
97 call writefile(v:errors, 'Xresult')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
98 qa!
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
99 END
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
100 call writefile(lines, 'Xrestricted')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
101 if RunVim([], [], '-Z --clean -S Xrestricted')
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
102 call assert_equal([], readfile('Xresult'))
15748
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 endif
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 call delete('Xrestricted')
19787
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
106 call delete('Xresult')
15748
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 endfunc
93b78c4a7cd5 patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108
19787
906269bf83d5 patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents: 15778
diff changeset
109 " vim: shiftwidth=2 sts=2 expandtab