public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Jan Zarsky <jzarsky@redhat.com>
To: git-commits@fedoraproject.org
Subject: [tests/selinux] pr775-checkpolicy-revdeps: test sestatus, avcstat, getenforce
Date: Fri, 11 Sep 2026 13:17:19 GMT	[thread overview]
Message-ID: <178913263944.1.2798431553636577671.tests-selinux-b8b6880b0d86@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : b8b6880b0d86e940b4d3270c5c151c150ce1706c
            Author : Jan Zarsky <jzarsky@redhat.com>
            Date   : 2018-07-31T22:52:50+02:00
            Stats  : +197/-0 in 4 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/b8b6880b0d86e940b4d3270c5c151c150ce1706c?branch=pr775-checkpolicy-revdeps

            Log:
            test sestatus, avcstat, getenforce

Test that output of sestatus matches information in /sys/fs/selinux.
Test that avcstat works. Test getenforce.

Warning: this tests runs setenforce.

---
diff --git a/policycoreutils/selinux-info/Makefile b/policycoreutils/selinux-info/Makefile
new file mode 100644
index 0000000..c48feef
--- /dev/null
+++ b/policycoreutils/selinux-info/Makefile
@@ -0,0 +1,63 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/policycoreutils/Sanity/selinux-info
+#   Description: Test sestatus, avcstat, getenforce and other information gathering tools
+#   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/selinux-info
+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 sestatus, avcstat, getenforce and other information gathering tools" >> $(METADATA)
+	@echo "Type:            Sanity" >> $(METADATA)
+	@echo "TestTime:        1m" >> $(METADATA)
+	@echo "RunFor:          policycoreutils" >> $(METADATA)
+	@echo "Requires:        policycoreutils" >> $(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/selinux-info/PURPOSE b/policycoreutils/selinux-info/PURPOSE
new file mode 100644
index 0000000..c67fcf0
--- /dev/null
+++ b/policycoreutils/selinux-info/PURPOSE
@@ -0,0 +1,3 @@
+PURPOSE of /CoreOS/policycoreutils/Sanity/selinux-info
+Description: Test sestatus, avcstat, getenforce and other information gathering tools
+Author: Jan Zarsky <jzarsky@redhat.com>

diff --git a/policycoreutils/selinux-info/main.fmf b/policycoreutils/selinux-info/main.fmf
new file mode 100644
index 0000000..4ce0eb4
--- /dev/null
+++ b/policycoreutils/selinux-info/main.fmf
@@ -0,0 +1,8 @@
+path: /policycoreutils/selinux-info
+summary: test sestatus, avcstat, getenforce
+description: |
+    Test that output of sestatus matches information in /sys/fs/selinux.
+    Test that avcstat works. Test getenforce. Warning: this tests runs
+    setenforce.
+relevancy:
+    - "distro = rhel-4, rhel-5, rhel-6: False"

diff --git a/policycoreutils/selinux-info/runtest.sh b/policycoreutils/selinux-info/runtest.sh
new file mode 100755
index 0000000..13a92e6
--- /dev/null
+++ b/policycoreutils/selinux-info/runtest.sh
@@ -0,0 +1,123 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/policycoreutils/Sanity/selinux-info
+#   Description: Test sestatus, avcstat, getenforce and other information gathering tools
+#   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
+
+        ENFORCING=$(cat /sys/fs/selinux/enforce)
+        MLS=$(cat /sys/fs/selinux/mls)
+        DENY=$(cat /sys/fs/selinux/deny_unknown)
+        POLICYVERSION=$(cat /sys/fs/selinux/policyvers)
+        POLICY_TYPE=$(grep -E '^SELINUXTYPE=' /etc/selinux/config | cut -f2 -d'=')
+        MODE=$(grep -E '^SELINUX=' /etc/selinux/config | cut -f2 -d'=')
+
+        BOOL_ON="mount_anyfile"
+        BOOL_OFF="deny_ptrace"
+        PROC_CON="unconfined_u:unconfined_r:unconfined_t:s0"
+        INIT_CON="system_u:system_r:init_t:s0"
+        # generic context:
+        CON="[[:alpha:]_]*_u:[[:alpha:]_]*_r:[[:alpha:]_]*_t:s[[:digit:]]*"
+    rlPhaseEnd
+
+    rlPhaseStartTest "sestatus"
+        rlRun "sestatus >stdout"
+        rlAssertGrep "SELinux status: *enabled" stdout
+        rlAssertGrep "SELinuxfs mount: */sys/fs/selinux" stdout
+        rlAssertGrep "SELinux root directory: *[a-zA-Z0-9/]*" stdout
+        rlAssertGrep "Loaded policy name: $POLICYTYPE" stdout
+        if [[ $ENFORCING ]]; then
+            rlAssertGrep "Current mode: *enforcing" stdout
+        else
+            rlAssertGrep "Current mode: *permissive" stdout
+        fi
+        rlAssertGrep "Mode from config file: *$MODE" stdout
+        if [[ $MLS ]]; then
+            rlAssertGrep "Policy MLS status: *enabled" stdout
+        else
+            rlAssertGrep "Policy MLS status: *disabled" stdout
+        fi
+        if [[ $DENY ]]; then
+            rlAssertGrep "Policy deny_unknown status: *allowed" stdout
+        else
+            rlAssertGrep "Policy deny_unknown status: *denied" stdout
+        fi
+        rlAssertGrep "Max kernel policy version: *$VERS" stdout
+
+        rlRun "sestatus -b >stdout"
+        rlAssertGrep "Policy booleans:" stdout
+        rlAssertGrep "$BOOL_ON *on" stdout
+        rlAssertGrep "$BOOL_OFF *off" stdout
+
+        rlRun "sestatus -v >stdout"
+        rlAssertGrep "Process contexts:" stdout
+        rlAssertGrep "Current context: *$PROC_CON" stdout
+        rlAssertGrep "Init context: *$INIT_CON" stdout
+        rlAssertGrep "File contexts:" stdout
+        # Disable this test as there's no controlling terminal when it's run via ansible
+        # rlAssertGrep "Controlling terminal: *$CON" stdout
+        rlAssertGrep "/etc/passwd *$CON" stdout
+    rlPhaseEnd
+
+    rlPhaseStartTest "avcstat"
+        rlRun "avcstat >stdout"
+        rlAssertGrep " *lookups *hits *misses *allocs *reclaims *frees" stdout
+        rlAssertGrep " *[[:digit:]]* *[[:digit:]]* *[[:digit:]]* *[[:digit:]]* *[[:digit:]]* *[[:digit:]]*" stdout
+
+        rlRun "avcstat >stdout2"
+        rlAssertDiffer stdout stdout2
+    rlPhaseEnd
+
+    rlPhaseStartTest "getenforce"
+        rlRun "getenforce >stdout"
+        if [[ $ENFORCING ]]; then
+            rlAssertGrep "Enforcing" stdout
+        else
+            rlAssertGrep "Permissive" stdout
+        fi
+
+        rlRun "setenforce 0"
+        rlRun "getenforce | grep Permissive"
+        rlRun "setenforce 1"
+        rlRun "getenforce | grep Enforcing"
+
+        if [[ ! $ENFORCING ]]; then
+            rlRun "setenforce 0"
+        fi
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        rlRun "rm stdout stdout2"
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd

                 reply	other threads:[~2026-09-11 13:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178913263944.1.2798431553636577671.tests-selinux-b8b6880b0d86@fedoraproject.org \
    --to=jzarsky@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox