2014-04-25 00:17:45 +00:00
|
|
|
package libcontainer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2014-05-20 00:13:00 +00:00
|
|
|
|
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer/mount/nodes"
|
2014-04-25 00:17:45 +00:00
|
|
|
)
|
|
|
|
|
2014-05-17 00:44:10 +00:00
|
|
|
// Checks whether the expected capability is specified in the capabilities.
|
2014-05-20 00:13:00 +00:00
|
|
|
func contains(expected string, values []string) bool {
|
|
|
|
for _, v := range values {
|
|
|
|
if v == expected {
|
2014-05-17 00:44:10 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2014-04-25 00:17:45 +00:00
|
|
|
func TestContainerJsonFormat(t *testing.T) {
|
|
|
|
f, err := os.Open("container.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to open container.json")
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
var container *Container
|
|
|
|
if err := json.NewDecoder(f).Decode(&container); err != nil {
|
2014-05-05 19:34:21 +00:00
|
|
|
t.Fatalf("failed to decode container config: %s", err)
|
2014-04-25 00:17:45 +00:00
|
|
|
}
|
|
|
|
if container.Hostname != "koye" {
|
|
|
|
t.Log("hostname is not set")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if !container.Tty {
|
|
|
|
t.Log("tty should be set to true")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-17 07:06:29 +00:00
|
|
|
if len(container.Routes) != 2 {
|
|
|
|
t.Log("should have found 2 routes")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:34:21 +00:00
|
|
|
if !container.Namespaces["NEWNET"] {
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Log("namespaces should contain NEWNET")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:34:21 +00:00
|
|
|
if container.Namespaces["NEWUSER"] {
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Log("namespaces should not contain NEWUSER")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:13:00 +00:00
|
|
|
if contains("SYS_ADMIN", container.Capabilities) {
|
2014-04-25 06:02:30 +00:00
|
|
|
t.Log("SYS_ADMIN should not be enabled in capabilities mask")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:13:00 +00:00
|
|
|
if !contains("MKNOD", container.Capabilities) {
|
2014-04-25 06:02:30 +00:00
|
|
|
t.Log("MKNOD should be enabled in capabilities mask")
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:13:00 +00:00
|
|
|
if contains("SYS_CHROOT", container.Capabilities) {
|
2014-04-25 06:02:30 +00:00
|
|
|
t.Log("capabilities mask should not contain SYS_CHROOT")
|
2014-04-25 00:17:45 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
2014-05-20 00:13:00 +00:00
|
|
|
|
|
|
|
for _, n := range nodes.DefaultNodes {
|
2014-05-21 00:36:50 +00:00
|
|
|
if !contains(n, container.RequiredDeviceNodes) {
|
2014-05-20 00:13:00 +00:00
|
|
|
t.Logf("devices should contain %s", n)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 00:17:45 +00:00
|
|
|
}
|