summaryrefslogtreecommitdiff
path: root/pkg/selinux/selinux_test.go
diff options
context:
space:
mode:
authorunclejack <unclejack@users.noreply.github.com>2014-04-09 01:56:01 +0300
committerunclejack <unclejack@users.noreply.github.com>2014-04-09 01:56:01 +0300
commite128a606e39fa63c6b4fd6e53a1d88cf00aad868 (patch)
tree199ee7eb6678ffecd2ddad95fce794c795ad5183 /pkg/selinux/selinux_test.go
parent143c9707a9fafc39e1d9747f528db97b2564f01e (diff)
parentdc9c28f51d669d6b09e81c2381f800f1a33bb659 (diff)
downloaddocker-release-0.10.tar.gz
Merge pull request #5079 from unclejack/bump_v0.10.0release-0.100.10.1-hotfixes
Bump version to v0.10.0
Diffstat (limited to 'pkg/selinux/selinux_test.go')
-rw-r--r--pkg/selinux/selinux_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/pkg/selinux/selinux_test.go b/pkg/selinux/selinux_test.go
new file mode 100644
index 0000000000..fde6ab147d
--- /dev/null
+++ b/pkg/selinux/selinux_test.go
@@ -0,0 +1,59 @@
+package selinux_test
+
+import (
+ "github.com/dotcloud/docker/pkg/selinux"
+ "os"
+ "testing"
+)
+
+func testSetfilecon(t *testing.T) {
+ if selinux.SelinuxEnabled() {
+ tmp := "selinux_test"
+ out, _ := os.OpenFile(tmp, os.O_WRONLY, 0)
+ out.Close()
+ err := selinux.Setfilecon(tmp, "system_u:object_r:bin_t:s0")
+ if err != nil {
+ t.Log("Setfilecon failed")
+ t.Fatal(err)
+ }
+ os.Remove(tmp)
+ }
+}
+
+func TestSELinux(t *testing.T) {
+ var (
+ err error
+ plabel, flabel string
+ )
+
+ if selinux.SelinuxEnabled() {
+ t.Log("Enabled")
+ plabel, flabel = selinux.GetLxcContexts()
+ t.Log(plabel)
+ t.Log(flabel)
+ plabel, flabel = selinux.GetLxcContexts()
+ t.Log(plabel)
+ t.Log(flabel)
+ t.Log("getenforce ", selinux.SelinuxGetEnforce())
+ t.Log("getenforcemode ", selinux.SelinuxGetEnforceMode())
+ pid := os.Getpid()
+ t.Log("PID:%d MCS:%s\n", pid, selinux.IntToMcs(pid, 1023))
+ err = selinux.Setfscreatecon("unconfined_u:unconfined_r:unconfined_t:s0")
+ if err == nil {
+ t.Log(selinux.Getfscreatecon())
+ } else {
+ t.Log("setfscreatecon failed", err)
+ t.Fatal(err)
+ }
+ err = selinux.Setfscreatecon("")
+ if err == nil {
+ t.Log(selinux.Getfscreatecon())
+ } else {
+ t.Log("setfscreatecon failed", err)
+ t.Fatal(err)
+ }
+ t.Log(selinux.Getpidcon(1))
+ } else {
+ t.Log("Disabled")
+ }
+}