nspkg / engine / sandbox_test.v
35 lines · 33 sloc · 1.18 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1module engine
2
3import os
4
5fn test_sandbox_access_masks_and_nonroot_activation() ! {
6 assert sandbox_filesystem_mask(1) == 0x1fff
7 assert sandbox_filesystem_mask(2) == 0x3fff
8 assert sandbox_filesystem_mask(3) == 0x7fff
9 assert sandbox_filesystem_mask(99) == 0x7fff
10 assert sandbox_denied_syscalls.len == 83
11 dir := os.join_path(os.vtmp_dir(), 'native-sandbox-options-${os.getpid()}')
12 os.mkdir_all(dir)!
13 defer { os.rmdir_all(dir) or { eprintln(err) } }
14 mut handle := initialize('/', dir)!
15 defer { handle.release() or { eprintln(err) } }
16 assert !handle.uses_download_sandbox()!
17 if C.getuid() != 0 {
18 handle.set_string_option(.sandbox_user, 'root')!
19 assert !handle.uses_download_sandbox()!
20 if _ := handle.sandbox_setup_child('root', none, true) {
21 assert false
22 }
23 assert handle.errno() == .ok
24 if _ := handle.register_syncdb('', 0) {
25 assert false
26 }
27 mut public_code := -1
28 handle.sandbox_setup_child('root', none, true) or { public_code = err.code() }
29 assert public_code == int(Errno.wrong_args)
30 mut worker_code := -1
31 handle.sandbox_setup_identity(0, 0, none, true) or { worker_code = err.code() }
32 assert worker_code == int(Errno.badperms)
33 assert handle.errno() == .wrong_args
34 }
35}
36