aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/bwrap/config_test.go
blob: 53265714d9ca51907b4d41315c59a3248be5abfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package bwrap

import (
	"slices"
	"testing"
)

func TestConfig_Args(t *testing.T) {
	testCases := []struct {
		name string
		conf *Config
		want []string
	}{
		{
			name: "xdg-dbus-proxy constraint sample",
			conf: &Config{
				Unshare:  nil,
				UserNS:   false,
				Clearenv: true,
				Symlink: []PermConfig[[2]string]{
					{Path: [2]string{"usr/bin", "/bin"}},
					{Path: [2]string{"var/home", "/home"}},
					{Path: [2]string{"usr/lib", "/lib"}},
					{Path: [2]string{"usr/lib64", "/lib64"}},
					{Path: [2]string{"run/media", "/media"}},
					{Path: [2]string{"var/mnt", "/mnt"}},
					{Path: [2]string{"var/opt", "/opt"}},
					{Path: [2]string{"sysroot/ostree", "/ostree"}},
					{Path: [2]string{"var/roothome", "/root"}},
					{Path: [2]string{"usr/sbin", "/sbin"}},
					{Path: [2]string{"var/srv", "/srv"}},
				},
				Bind: [][2]string{
					{"/run", "/run"},
					{"/tmp", "/tmp"},
					{"/var", "/var"},
					{"/run/user/1971/.dbus-proxy/", "/run/user/1971/.dbus-proxy/"},
				},
				ROBind: [][2]string{
					{"/boot", "/boot"},
					{"/dev", "/dev"},
					{"/proc", "/proc"},
					{"/sys", "/sys"},
					{"/sysroot", "/sysroot"},
					{"/usr", "/usr"},
					{"/etc", "/etc"},
				},
				DieWithParent: true,
			},
			want: []string{
				"--unshare-all",
				"--unshare-user",
				"--disable-userns",
				"--assert-userns-disabled",
				"--clearenv",
				"--die-with-parent",
				"--bind", "/run", "/run",
				"--bind", "/tmp", "/tmp",
				"--bind", "/var", "/var",
				"--bind", "/run/user/1971/.dbus-proxy/", "/run/user/1971/.dbus-proxy/",
				"--ro-bind", "/boot", "/boot",
				"--ro-bind", "/dev", "/dev",
				"--ro-bind", "/proc", "/proc",
				"--ro-bind", "/sys", "/sys",
				"--ro-bind", "/sysroot", "/sysroot",
				"--ro-bind", "/usr", "/usr",
				"--ro-bind", "/etc", "/etc",
				"--symlink", "usr/bin", "/bin",
				"--symlink", "var/home", "/home",
				"--symlink", "usr/lib", "/lib",
				"--symlink", "usr/lib64", "/lib64",
				"--symlink", "run/media", "/media",
				"--symlink", "var/mnt", "/mnt",
				"--symlink", "var/opt", "/opt",
				"--symlink", "sysroot/ostree", "/ostree",
				"--symlink", "var/roothome", "/root",
				"--symlink", "usr/sbin", "/sbin",
				"--symlink", "var/srv", "/srv"},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			if got := tc.conf.Args(); !slices.Equal(got, tc.want) {
				t.Errorf("Args() = %#v, want %#v", got, tc.want)
			}
		})
	}
}