public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: test basic module functionality
@ 2026-09-11 13:17 Jan Zarsky
0 siblings, 0 replies; only message in thread
From: Jan Zarsky @ 2026-09-11 13:17 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : tests/selinux
Branch : pr775-checkpolicy-revdeps
Commit : 604c9303445303fdec68b5b786b87febe05faaf0
Author : Jan Zarsky <jzarsky@redhat.com>
Date : 2018-07-31T21:22:12+02:00
Stats : +279/-0 in 4 file(s)
URL : https://src.fedoraproject.org/tests/selinux/c/604c9303445303fdec68b5b786b87febe05faaf0?branch=pr775-checkpolicy-revdeps
Log:
test basic module functionality
The test compiles a TE module, loads it via semodule, and checks that
the rules are enforced. The same is done with a CIL module. Module
overriding using priorities and module disabling is also tested.
This test requires policycoreutils and selinux-policy-devel packages.
---
diff --git a/policycoreutils/modules/Makefile b/policycoreutils/modules/Makefile
new file mode 100644
index 0000000..4689f27
--- /dev/null
+++ b/policycoreutils/modules/Makefile
@@ -0,0 +1,64 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Makefile of /CoreOS/policycoreutils/Sanity/modules
+# Description: Test module compiling and loading
+# Author: Jan Zarsky <jzarsky@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2018 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/policycoreutils/Sanity/modules
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+ ./runtest.sh
+
+build: $(BUILT_FILES)
+ test -x runtest.sh || chmod a+x runtest.sh
+
+clean:
+ rm -f *~ $(BUILT_FILES)
+
+
+include /usr/share/rhts/lib/rhts-make.include
+
+$(METADATA): Makefile
+ @echo "Owner: Jan Zarsky <jzarsky@redhat.com>" > $(METADATA)
+ @echo "Name: $(TEST)" >> $(METADATA)
+ @echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
+ @echo "Path: $(TEST_DIR)" >> $(METADATA)
+ @echo "Description: Test module compiling and loading" >> $(METADATA)
+ @echo "Type: Sanity" >> $(METADATA)
+ @echo "TestTime: 10m" >> $(METADATA)
+ @echo "RunFor: policycoreutils" >> $(METADATA)
+ @echo "Requires: policycoreutils" >> $(METADATA)
+ @echo "Requires: selinux-policy-devel" >> $(METADATA)
+ @echo "Priority: Normal" >> $(METADATA)
+ @echo "License: GPLv2+" >> $(METADATA)
+ @echo "Confidential: no" >> $(METADATA)
+ @echo "Destructive: no" >> $(METADATA)
+ @echo "Releases: -RHEL4 -RHELClient5 -RHELServer5 -RHEL6" >> $(METADATA)
+
+ rhts-lint $(METADATA)
diff --git a/policycoreutils/modules/PURPOSE b/policycoreutils/modules/PURPOSE
new file mode 100644
index 0000000..5f2d254
--- /dev/null
+++ b/policycoreutils/modules/PURPOSE
@@ -0,0 +1,3 @@
+PURPOSE of /CoreOS/policycoreutils/Sanity/modules
+Description: Test module compiling and loading
+Author: Jan Zarsky <jzarsky@redhat.com>
diff --git a/policycoreutils/modules/main.fmf b/policycoreutils/modules/main.fmf
new file mode 100644
index 0000000..3b5d389
--- /dev/null
+++ b/policycoreutils/modules/main.fmf
@@ -0,0 +1,11 @@
+path: /policycoreutils/modules
+summary: test basic module functionality
+description: |
+ The test compiles a TE module, loads it via semodule, and checks
+ that the rules are enforced. The same is done with a CIL module.
+ Module overriding using priorities and module disabling is also
+ tested. This test requires policycoreutils and selinux-policy-devel
+ packages.
+relevancy:
+ - "distro = rhel-4, rhel-5, rhel-6: False"
+duration: 10m
diff --git a/policycoreutils/modules/runtest.sh b/policycoreutils/modules/runtest.sh
new file mode 100755
index 0000000..0d7a704
--- /dev/null
+++ b/policycoreutils/modules/runtest.sh
@@ -0,0 +1,201 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# runtest.sh of /CoreOS/policycoreutils/Sanity/modules
+# Description: Test module compiling and loading
+# Author: Jan Zarsky <jzarsky@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2018 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include Beaker environment
+. /usr/bin/rhts-environment.sh || exit 1
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="policycoreutils"
+
+rlJournalStart
+ rlPhaseStartSetup
+ rlAssertRpm $PACKAGE
+ rlAssertRpm "selinux-policy-devel"
+ rlPhaseEnd
+
+ rlPhaseStartTest "TE module using Makefile"
+ rlRun "mkdir test"
+ rlRun "pushd test"
+
+ # create new type, allow reading, do not allow writing
+ rlRun "cat << EOF >test_module.te
+module test_module 1.0;
+
+require {
+ type unconfined_t;
+ type fs_t;
+ class file { getattr ioctl lock open read relabelto write };
+ class filesystem { associate };
+}
+
+type test_t;
+
+allow test_t fs_t:filesystem { associate };
+allow unconfined_t test_t:file { getattr ioctl lock open read relabelto};
+dontaudit unconfined_t test_t:file { write };
+EOF"
+ # compile the module
+ rlRun "make -f /usr/share/selinux/devel/Makefile test_module.pp"
+
+ # load it
+ rlRun "semodule -i test_module.pp"
+
+ # test that the rules are enforced
+ rlRun "touch test_file"
+ rlRun "chcon -t test_t test_file"
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 1
+
+ # unload the module
+ rlRun "semodule -r test_module"
+
+ rlRun "popd"
+ rlRun "rm -rf test"
+ rlPhaseEnd
+
+ rlPhaseStartTest "CIL module"
+ rlRun "mkdir test"
+ rlRun "pushd test"
+
+ # create new type, allow reading, do not allow writing
+ rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+
+ # load the module
+ rlRun "semodule -i test_module.cil"
+
+ # test that the rules are enforced
+ rlRun "touch test_file"
+ rlRun "chcon -t test_t test_file"
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 1
+
+ # unload the module
+ rlRun "semodule -r test_module"
+
+ rlRun "popd"
+ rlRun "rm -rf test"
+ rlPhaseEnd
+
+ rlPhaseStartTest "Priorities"
+ rlRun "mkdir test"
+ rlRun "pushd test"
+
+ # create new type, allow reading and writing
+ rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto
+ write)))
+EOF"
+
+ # load the module at priority 400
+ rlRun "semodule -i test_module.cil -X 400"
+
+ # test that both reading and writing is allowed
+ rlRun "touch test_file"
+ rlRun "chcon -t test_t test_file"
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 0
+
+ # create new type, allow only reading
+ rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+
+ # load the module at priority 500
+ rlRun "semodule -i test_module.cil -X 500"
+
+ # test that only reading is allowed
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 1
+
+ # unload both modules
+ rlRun "semodule -r test_module -X 400"
+ rlRun "semodule -r test_module -X 500"
+
+ rlRun "popd"
+ rlRun "rm -rf test"
+ rlPhaseEnd
+
+ rlPhaseStartTest "Disabling modules"
+ rlRun "mkdir test"
+ rlRun "pushd test"
+
+ # create new type, allow reading
+ rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+ # allow writing
+ rlRun "cat << EOF >test_module_writing.cil
+(allow unconfined_t test_t (file (write)))
+EOF"
+
+ # load the modules
+ rlRun "semodule -i test_module.cil test_module_writing.cil"
+
+ # test that reading and writing is allowed
+ rlRun "touch test_file"
+ rlRun "chcon -t test_t test_file"
+ rlRun "cat test_file"
+ rlRun "echo asdf >test_file"
+
+ # disable writing
+ rlRun "semodule -d test_module_writing"
+
+ # test that writing is not allowed
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 1
+
+ # enable the module
+ rlRun "semodule -e test_module_writing"
+
+ # test that writing is allowed
+ rlRun "cat test_file" 0
+ rlRun "echo asdf >test_file" 0
+
+ # unload the modules
+ rlRun "semodule -r test_module test_module_writing"
+
+ rlRun "popd"
+ rlRun "rm -rf test"
+ rlPhaseEnd
+
+ rlPhaseStartCleanup
+ rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-11 13:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 13:17 [tests/selinux] pr775-checkpolicy-revdeps: test basic module functionality Jan Zarsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox