nspkg / tests / coracle / sandbox_download_compatibility_test.v
38 lines · 35 sloc · 1.27 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1module coracle
2
3import os
4
5fn sandbox_download_command(executable string, args []string) !string {
6 mut process := os.new_process(executable)
7 process.set_args(args)
8 process.set_redirect_stdio()
9 process.run()
10 defer { process.close() }
11 output := process.stdout_slurp()
12 diagnostic := process.stderr_slurp()
13 process.wait()
14 if process.code != 0 {
15 return error('${executable} ${args} failed ${process.code}: ${diagnostic}\n${output}')
16 }
17 return output
18}
19
20fn test_sandboxed_transport_matches_libalpm_and_keeps_callbacks_in_parent() ! {
21 $if linux {
22 dir := os.join_path(os.temp_dir(), 'alpm-sandbox-download-${os.getpid()}')
23 os.mkdir_all(dir, mode: 0o755)!
24 defer { os.rmdir_all(dir) or { eprintln(err) } }
25 probe := os.join_path(dir, 'probe')
26 sandbox_download_command('v', ['-path', os.dir(@VMODROOT) + '|@vlib|@vmodules', '-o', probe,
27 os.join_path(@VMODROOT, 'tests', 'sandbox_download_probe.v')])!
28 for fs in ['on', 'off'] {
29 for syscalls in ['on', 'off'] {
30 base := os.join_path(dir, '${fs}-${syscalls}')
31 os.mkdir_all(base, mode: 0o755)!
32 output := sandbox_download_command('timeout', ['30s', 'unshare', '--user',
33 '--map-root-user', '--map-auto', '--setgroups=allow', probe, base, fs, syscalls])!
34 assert output.contains('sandbox downloads verified')
35 }
36 }
37 }
38}
39