blob: 3099dfec1e6f8d917503c4eb1cac3b72496c16ac [file] [log] [blame]
Bram Moolenaar8c62a082019-02-08 14:34:10 +01001" Test for "rvim" or "vim -Z"
2
Bram Moolenaar5a669812019-02-11 21:45:00 +01003"if has('win32') && has('gui')
4" " Win32 GUI shows a dialog instead of displaying the error in the last line.
5" finish
6"endif
Bram Moolenaar18c56322019-02-09 11:13:12 +01007
Bram Moolenaar7d941ee2020-03-26 14:11:58 +01008func Test_restricted_mode()
9 let lines =<< trim END
10 if has('lua')
11 call assert_fails('lua print("Hello, Vim!")', 'E981:')
12 call assert_fails('luado return "hello"', 'E981:')
13 call assert_fails('luafile somefile', 'E981:')
14 call assert_fails('call luaeval("expression")', 'E145:')
15 endif
Bram Moolenaar8c62a082019-02-08 14:34:10 +010016
Bram Moolenaar7d941ee2020-03-26 14:11:58 +010017 if has('mzscheme')
18 call assert_fails('mzscheme statement', 'E981:')
19 call assert_fails('mzfile somefile', 'E981:')
20 call assert_fails('call mzeval("expression")', 'E145:')
21 endif
22
23 if has('perl')
24 " TODO: how to make Safe mode fail?
25 " call assert_fails('perl system("ls")', 'E981:')
26 " call assert_fails('perldo system("hello")', 'E981:')
27 " call assert_fails('perlfile somefile', 'E981:')
28 " call assert_fails('call perleval("system(\"ls\")")', 'E145:')
29 endif
30
31 if has('python')
32 call assert_fails('python print "hello"', 'E981:')
33 call assert_fails('pydo return "hello"', 'E981:')
34 call assert_fails('pyfile somefile', 'E981:')
35 call assert_fails('call pyeval("expression")', 'E145:')
36 endif
37
38 if has('python3')
39 call assert_fails('py3 print "hello"', 'E981:')
40 call assert_fails('py3do return "hello"', 'E981:')
41 call assert_fails('py3file somefile', 'E981:')
42 call assert_fails('call py3eval("expression")', 'E145:')
43 endif
44
45 if has('ruby')
46 call assert_fails('ruby print "Hello"', 'E981:')
47 call assert_fails('rubydo print "Hello"', 'E981:')
48 call assert_fails('rubyfile somefile', 'E981:')
49 endif
50
51 if has('tcl')
52 call assert_fails('tcl puts "Hello"', 'E981:')
53 call assert_fails('tcldo puts "Hello"', 'E981:')
54 call assert_fails('tclfile somefile', 'E981:')
55 endif
56
57 if has('clientserver')
58 call assert_fails('let s=remote_peek(10)', 'E145:')
59 call assert_fails('let s=remote_read(10)', 'E145:')
60 call assert_fails('let s=remote_send("vim", "abc")', 'E145:')
61 call assert_fails('let s=server2client(10, "abc")', 'E145:')
62 endif
63
64 if has('terminal')
65 call assert_fails('terminal', 'E145:')
66 call assert_fails('call term_start("vim")', 'E145:')
67 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E145:')
68 endif
69
70 if has('channel')
71 call assert_fails("call ch_logfile('Xlog')", 'E145:')
72 call assert_fails("call ch_open('localhost:8765')", 'E145:')
73 endif
74
75 if has('job')
76 call assert_fails("call job_start('vim')", 'E145:')
77 endif
78
Bram Moolenaarca68ae12020-03-30 19:32:53 +020079 if has('unix') && has('libcall')
Bram Moolenaar7d941ee2020-03-26 14:11:58 +010080 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E145:')
81 endif
82 call assert_fails("call rename('a', 'b')", 'E145:')
83 call assert_fails("call delete('Xfile')", 'E145:')
84 call assert_fails("call mkdir('Xdir')", 'E145:')
85 call assert_fails('!ls', 'E145:')
86 call assert_fails('shell', 'E145:')
87 call assert_fails('stop', 'E145:')
Bram Moolenaarca68ae12020-03-30 19:32:53 +020088 call assert_fails('exe "normal \<C-Z>"', 'E145:')
89 set insertmode
90 call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E145:')
91 set insertmode&
Bram Moolenaar7d941ee2020-03-26 14:11:58 +010092 call assert_fails('suspend', 'E145:')
Bram Moolenaarca68ae12020-03-30 19:32:53 +020093 call assert_fails('call system("ls")', 'E145:')
94 call assert_fails('call systemlist("ls")', 'E145:')
Bram Moolenaar7d941ee2020-03-26 14:11:58 +010095 if has('unix')
96 call assert_fails('cd `pwd`', 'E145:')
97 endif
98
99 call writefile(v:errors, 'Xresult')
100 qa!
101 END
Bram Moolenaardb77cb32022-10-05 21:45:30 +0100102 call writefile(lines, 'Xrestricted', 'D')
Bram Moolenaar7d941ee2020-03-26 14:11:58 +0100103 if RunVim([], [], '-Z --clean -S Xrestricted')
104 call assert_equal([], readfile('Xresult'))
Bram Moolenaar8c62a082019-02-08 14:34:10 +0100105 endif
matveytadbb1bf2022-02-01 17:26:12 +0000106 call delete('Xresult')
107 if has('unix') && RunVimPiped([], [], '--clean -S Xrestricted', 'SHELL=/bin/false ')
108 call assert_equal([], readfile('Xresult'))
109 endif
110 call delete('Xresult')
111 if has('unix') && RunVimPiped([], [], '--clean -S Xrestricted', 'SHELL=/sbin/nologin')
112 call assert_equal([], readfile('Xresult'))
113 endif
Bram Moolenaar8c62a082019-02-08 14:34:10 +0100114
Bram Moolenaar7d941ee2020-03-26 14:11:58 +0100115 call delete('Xresult')
Bram Moolenaar8c62a082019-02-08 14:34:10 +0100116endfunc
117
Bram Moolenaar7d941ee2020-03-26 14:11:58 +0100118" vim: shiftwidth=2 sts=2 expandtab