support/testing/tests/core/test_selinux: new tests for the packages SELinux functiona...
authorAntoine Tenart <antoine.tenart@bootlin.com>
Mon, 28 Sep 2020 14:54:24 +0000 (16:54 +0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Tue, 6 Oct 2020 13:30:12 +0000 (15:30 +0200)
Add tests to ensure the packages SELinux functionalities (being able to
select an extra SELinux module in the refpolicy, and being able to
provide a custom SELinux module) are working as expected.

We use a BR2_EXTERNAL folder, provided in the tests, to use a custom
SELinux enabled package.

Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
support/testing/tests/core/test_selinux.py
support/testing/tests/core/test_selinux/br2_external/Config.in [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/external.desc [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/external.mk [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/package/selinux-test/Config.in [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux-test.mk [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.fc [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.if [new file with mode: 0644]
support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.te [new file with mode: 0644]

index bb6604590ab527d76d38da925f77c5e01606b593..28d99d3a691230ec7c1417b50ec6ca323275bedb 100644 (file)
@@ -58,3 +58,25 @@ class TestSELinuxCustomGit(TestSELinuxInfra):
 
     def test_run(self):
         pass
+
+class TestSELinuxPackage(TestSELinuxInfra):
+    br2_external = [infra.filepath("tests/core/test_selinux/br2_external")]
+    config = TestSELinuxInfra.config + \
+             """
+             BR2_PACKAGE_SELINUX_TEST=y
+             """
+
+    def test_run(self):
+        TestSELinuxInfra.base_test_run(self)
+
+        out, ret = self.emulator.run("seinfo -t ntpd_t", 15)
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[2].strip(), "ntpd_t")
+
+        out, ret = self.emulator.run("seinfo -t tor_t", 15)
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[2].strip(), "tor_t")
+
+        out, ret = self.emulator.run("seinfo -t buildroot_test_t", 15)
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[2].strip(), "buildroot_test_t")
diff --git a/support/testing/tests/core/test_selinux/br2_external/Config.in b/support/testing/tests/core/test_selinux/br2_external/Config.in
new file mode 100644 (file)
index 0000000..9d9c84e
--- /dev/null
@@ -0,0 +1 @@
+source "$BR2_EXTERNAL_SELINUX_PATH/package/selinux-test/Config.in"
diff --git a/support/testing/tests/core/test_selinux/br2_external/external.desc b/support/testing/tests/core/test_selinux/br2_external/external.desc
new file mode 100644 (file)
index 0000000..44b5b95
--- /dev/null
@@ -0,0 +1 @@
+name: SELINUX
diff --git a/support/testing/tests/core/test_selinux/br2_external/external.mk b/support/testing/tests/core/test_selinux/br2_external/external.mk
new file mode 100644 (file)
index 0000000..54d2402
--- /dev/null
@@ -0,0 +1 @@
+include $(sort $(wildcard $(BR2_EXTERNAL_SELINUX_PATH)/package/*/*.mk))
diff --git a/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/Config.in b/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/Config.in
new file mode 100644 (file)
index 0000000..e30ac83
--- /dev/null
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_SELINUX_TEST
+       bool "SELinux test package"
+       help
+         Test package for SELinux Buildroot helpers.
diff --git a/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux-test.mk b/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux-test.mk
new file mode 100644 (file)
index 0000000..0100b71
--- /dev/null
@@ -0,0 +1,9 @@
+################################################################################
+#
+# SELinux test package
+#
+################################################################################
+
+SELINUX_TEST_SELINUX_MODULES = ntp tor
+
+$(eval $(generic-package))
diff --git a/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.fc b/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.fc
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.if b/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.if
new file mode 100644 (file)
index 0000000..acf797e
--- /dev/null
@@ -0,0 +1 @@
+## <summary>Buildroot rules</summary>
diff --git a/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.te b/support/testing/tests/core/test_selinux/br2_external/package/selinux-test/selinux/buildroot.te
new file mode 100644 (file)
index 0000000..266bc03
--- /dev/null
@@ -0,0 +1,3 @@
+policy_module(buildroot, 1.0.0)
+
+type buildroot_test_t;