...
1 package libcontainer
2
3 import (
4 "testing"
5
6 "github.com/opencontainers/runc/libcontainer/configs"
7 )
8
9 func TestCheckMountDestOnProc(t *testing.T) {
10 dest := "/rootfs/proc/sys"
11 err := checkProcMount("/rootfs", dest, "")
12 if err == nil {
13 t.Fatal("destination inside proc should return an error")
14 }
15 }
16
17 func TestCheckMountDestOnProcChroot(t *testing.T) {
18 dest := "/rootfs/proc/"
19 err := checkProcMount("/rootfs", dest, "/proc")
20 if err != nil {
21 t.Fatal("destination inside proc when using chroot should not return an error")
22 }
23 }
24
25 func TestCheckMountDestInSys(t *testing.T) {
26 dest := "/rootfs//sys/fs/cgroup"
27 err := checkProcMount("/rootfs", dest, "")
28 if err != nil {
29 t.Fatal("destination inside /sys should not return an error")
30 }
31 }
32
33 func TestCheckMountDestFalsePositive(t *testing.T) {
34 dest := "/rootfs/sysfiles/fs/cgroup"
35 err := checkProcMount("/rootfs", dest, "")
36 if err != nil {
37 t.Fatal(err)
38 }
39 }
40
41 func TestCheckMountDestNsLastPid(t *testing.T) {
42 dest := "/rootfs/proc/sys/kernel/ns_last_pid"
43 err := checkProcMount("/rootfs", dest, "/proc")
44 if err != nil {
45 t.Fatal("/proc/sys/kernel/ns_last_pid should not return an error")
46 }
47 }
48
49 func TestNeedsSetupDev(t *testing.T) {
50 config := &configs.Config{
51 Mounts: []*configs.Mount{
52 {
53 Device: "bind",
54 Source: "/dev",
55 Destination: "/dev",
56 },
57 },
58 }
59 if needsSetupDev(config) {
60 t.Fatal("expected needsSetupDev to be false, got true")
61 }
62 }
63
64 func TestNeedsSetupDevStrangeSource(t *testing.T) {
65 config := &configs.Config{
66 Mounts: []*configs.Mount{
67 {
68 Device: "bind",
69 Source: "/devx",
70 Destination: "/dev",
71 },
72 },
73 }
74 if needsSetupDev(config) {
75 t.Fatal("expected needsSetupDev to be false, got true")
76 }
77 }
78
79 func TestNeedsSetupDevStrangeDest(t *testing.T) {
80 config := &configs.Config{
81 Mounts: []*configs.Mount{
82 {
83 Device: "bind",
84 Source: "/dev",
85 Destination: "/devx",
86 },
87 },
88 }
89 if !needsSetupDev(config) {
90 t.Fatal("expected needsSetupDev to be true, got false")
91 }
92 }
93
94 func TestNeedsSetupDevStrangeSourceDest(t *testing.T) {
95 config := &configs.Config{
96 Mounts: []*configs.Mount{
97 {
98 Device: "bind",
99 Source: "/devx",
100 Destination: "/devx",
101 },
102 },
103 }
104 if !needsSetupDev(config) {
105 t.Fatal("expected needsSetupDev to be true, got false")
106 }
107 }
108
View as plain text