2014-09-30 15:10:03 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseSecurityOpt(t *testing.T) {
|
|
|
|
container := &Container{}
|
2014-11-03 17:57:18 -05:00
|
|
|
config := &runconfig.HostConfig{}
|
2014-09-30 15:10:03 -04:00
|
|
|
|
|
|
|
// test apparmor
|
|
|
|
config.SecurityOpt = []string{"apparmor:test_profile"}
|
|
|
|
if err := parseSecurityOpt(container, config); err != nil {
|
|
|
|
t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
|
|
}
|
|
|
|
if container.AppArmorProfile != "test_profile" {
|
|
|
|
t.Fatalf("Unexpected AppArmorProfile, expected: \"test_profile\", got %q", container.AppArmorProfile)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test valid label
|
|
|
|
config.SecurityOpt = []string{"label:user:USER"}
|
|
|
|
if err := parseSecurityOpt(container, config); err != nil {
|
|
|
|
t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test invalid label
|
|
|
|
config.SecurityOpt = []string{"label"}
|
|
|
|
if err := parseSecurityOpt(container, config); err == nil {
|
|
|
|
t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
// test invalid opt
|
|
|
|
config.SecurityOpt = []string{"test"}
|
|
|
|
if err := parseSecurityOpt(container, config); err == nil {
|
|
|
|
t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
|
|
}
|
|
|
|
}
|