Mercurial > vim
annotate src/testdir/test_restricted.vim @ 24851:528e605caece
Added tag v8.2.2963 for changeset f8906bd5b277f421c41d5106c4ced2eb14f4b9ae
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 08 Jun 2021 20:15:06 +0200 |
parents | 12518b40c161 |
children | ef32ea9fbe6c |
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 |
19852
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
81 if has('unix') && has('libcall') |
19787
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:') |
19852
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
90 call assert_fails('exe "normal \<C-Z>"', 'E145:') |
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
91 set insertmode |
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
92 call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E145:') |
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
93 set insertmode& |
19787
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('suspend', 'E145:') |
19852
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
95 call assert_fails('call system("ls")', 'E145:') |
12518b40c161
patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19787
diff
changeset
|
96 call assert_fails('call systemlist("ls")', 'E145:') |
19787
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
97 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
|
98 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
|
99 endif |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
100 |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
101 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
|
102 qa! |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
103 END |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 endif |
93b78c4a7cd5
patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 |
93b78c4a7cd5
patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 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
|
110 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
|
111 endfunc |
93b78c4a7cd5
patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 |
19787
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
15778
diff
changeset
|
113 " vim: shiftwidth=2 sts=2 expandtab |