Notification time stamped 2018-07-31 20:53:30 UTC
From b8b6880b0d86e940b4d3270c5c151c150ce1706c Mon Sep 17 00:00:00 2001
From: Jan Zarsky <jzarsky(a)redhat.com>
Date: Jul 31 2018 20:52:50 +0000
Subject: 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(a)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(a)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(a)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(a)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
https://src.fedoraproject.org/tests/selinux/c/b8b6880b0d86e940b4d3270c5c1...