2015-04-22 04:46:27 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package libcontainer
|
|
|
|
|
2016-04-08 13:01:39 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
|
|
)
|
2015-04-22 04:46:27 +08:00
|
|
|
|
|
|
|
func TestCheckMountDestOnProc(t *testing.T) {
|
2018-06-29 23:13:45 +08:00
|
|
|
dest := "/rootfs/proc/sys"
|
2019-09-24 04:45:45 +08:00
|
|
|
err := checkProcMount("/rootfs", dest, "")
|
2015-04-22 04:46:27 +08:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("destination inside proc should return an error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-29 23:13:45 +08:00
|
|
|
func TestCheckMountDestOnProcChroot(t *testing.T) {
|
|
|
|
dest := "/rootfs/proc/"
|
2019-09-24 04:45:45 +08:00
|
|
|
err := checkProcMount("/rootfs", dest, "/proc")
|
2018-06-29 23:13:45 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("destination inside proc when using chroot should not return an error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 04:46:27 +08:00
|
|
|
func TestCheckMountDestInSys(t *testing.T) {
|
|
|
|
dest := "/rootfs//sys/fs/cgroup"
|
2019-09-24 04:45:45 +08:00
|
|
|
err := checkProcMount("/rootfs", dest, "")
|
2015-05-09 01:47:51 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("destination inside /sys should not return an error")
|
2015-04-22 04:46:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckMountDestFalsePositive(t *testing.T) {
|
|
|
|
dest := "/rootfs/sysfiles/fs/cgroup"
|
2019-09-24 04:45:45 +08:00
|
|
|
err := checkProcMount("/rootfs", dest, "")
|
2015-04-22 04:46:27 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 01:23:42 +08:00
|
|
|
|
2016-04-08 13:01:39 +08:00
|
|
|
func TestNeedsSetupDev(t *testing.T) {
|
|
|
|
config := &configs.Config{
|
|
|
|
Mounts: []*configs.Mount{
|
|
|
|
{
|
|
|
|
Device: "bind",
|
|
|
|
Source: "/dev",
|
|
|
|
Destination: "/dev",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if needsSetupDev(config) {
|
|
|
|
t.Fatal("expected needsSetupDev to be false, got true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNeedsSetupDevStrangeSource(t *testing.T) {
|
|
|
|
config := &configs.Config{
|
|
|
|
Mounts: []*configs.Mount{
|
|
|
|
{
|
|
|
|
Device: "bind",
|
|
|
|
Source: "/devx",
|
|
|
|
Destination: "/dev",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if needsSetupDev(config) {
|
|
|
|
t.Fatal("expected needsSetupDev to be false, got true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNeedsSetupDevStrangeDest(t *testing.T) {
|
|
|
|
config := &configs.Config{
|
|
|
|
Mounts: []*configs.Mount{
|
|
|
|
{
|
|
|
|
Device: "bind",
|
|
|
|
Source: "/dev",
|
|
|
|
Destination: "/devx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !needsSetupDev(config) {
|
|
|
|
t.Fatal("expected needsSetupDev to be true, got false")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNeedsSetupDevStrangeSourceDest(t *testing.T) {
|
|
|
|
config := &configs.Config{
|
|
|
|
Mounts: []*configs.Mount{
|
|
|
|
{
|
|
|
|
Device: "bind",
|
|
|
|
Source: "/devx",
|
|
|
|
Destination: "/devx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !needsSetupDev(config) {
|
|
|
|
t.Fatal("expected needsSetupDev to be true, got false")
|
|
|
|
}
|
|
|
|
}
|