psss / rpms / libsemanage

Forked from rpms/libsemanage 5 years ago
Clone
cefaa03
#!/bin/bash
cefaa03
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
cefaa03
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cefaa03
#
cefaa03
#   runtest.sh of /CoreOS/libsemanage/Sanity/verify-options-in-semanage-conf
cefaa03
#   Description: Are the verify options in semanage.conf honored?
cefaa03
#   Author: Milos Malik <mmalik@redhat.com>
cefaa03
#
cefaa03
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cefaa03
#
cefaa03
#   Copyright (c) 2016 Red Hat, Inc.
cefaa03
#
cefaa03
#   This copyrighted material is made available to anyone wishing
cefaa03
#   to use, modify, copy, or redistribute it subject to the terms
cefaa03
#   and conditions of the GNU General Public License version 2.
cefaa03
#
cefaa03
#   This program is distributed in the hope that it will be
cefaa03
#   useful, but WITHOUT ANY WARRANTY; without even the implied
cefaa03
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
cefaa03
#   PURPOSE. See the GNU General Public License for more details.
cefaa03
#
cefaa03
#   You should have received a copy of the GNU General Public
cefaa03
#   License along with this program; if not, write to the Free
cefaa03
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
cefaa03
#   Boston, MA 02110-1301, USA.
cefaa03
#
cefaa03
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cefaa03
cefaa03
# Include Beaker environment
cefaa03
. /usr/bin/rhts-environment.sh || exit 1
cefaa03
. /usr/share/beakerlib/beakerlib.sh || exit 1
cefaa03
cefaa03
PACKAGE="libsemanage"
cefaa03
MODULE_NAME="empty"
cefaa03
SEMANAGE_CONF="/etc/selinux/semanage.conf"
cefaa03
cefaa03
rlJournalStart
cefaa03
	rlPhaseStartSetup
cefaa03
		rlAssertRpm ${PACKAGE}
cefaa03
		rlAssertRpm policycoreutils
cefaa03
		rlAssertRpm selinux-policy
cefaa03
		rlFileBackup ${SEMANAGE_CONF}
cefaa03
		rlRun "rpm -qf /usr/sbin/semanage"
cefaa03
		rlRun "grep -v -e '^#' -e '^$' ${SEMANAGE_CONF}"
cefaa03
		OUTPUT_FILE=`mktemp`
cefaa03
		
cefaa03
		rlRun "setenforce 1"
cefaa03
		rlRun "sestatus"
cefaa03
		rlRun "ls -l ${MODULE_NAME}.te"
cefaa03
		rlRun "make -f /usr/share/selinux/devel/Makefile"
cefaa03
		rlRun "ls -l ${MODULE_NAME}.pp"
cefaa03
    rlPhaseEnd
cefaa03
cefaa03
	rlLog "positive cases follow"
cefaa03
	# TODO: /bin/true could be replaced a script, which prints the supplied arguments into a file for further inspection
cefaa03
cefaa03
	rlPhaseStartTest "verify kernel"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify kernel]\npath = /bin/true\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}"
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}"
cefaa03
	rlPhaseEnd
cefaa03
cefaa03
	rlPhaseStartTest "verify module"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify module]\npath = /bin/true\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}"
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}"
cefaa03
	rlPhaseEnd
cefaa03
cefaa03
    if rlIsRHEL '<7.3' ; then # because "[verify linked]" was dropped
cefaa03
	rlPhaseStartTest "verify linked"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify linked]\npath = /bin/true\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}"
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertNotGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}"
cefaa03
	rlPhaseEnd
cefaa03
    fi
cefaa03
cefaa03
	rlLog "negative cases follow"
cefaa03
	# TODO: /bin/false could be replaced a script, which prints the supplied arguments into a file for further inspection
cefaa03
cefaa03
	rlPhaseStartTest "verify kernel"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify kernel]\npath = /bin/false\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}" 1
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}" 1
cefaa03
	rlPhaseEnd
cefaa03
cefaa03
	rlPhaseStartTest "verify module"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify module]\npath = /bin/false\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}" 1
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}" 1
cefaa03
	rlPhaseEnd
cefaa03
cefaa03
    if rlIsRHEL '<7.3' ; then # because "[verify linked]" was dropped
cefaa03
	rlPhaseStartTest "verify linked"
cefaa03
		rlRun "semodule -r ${MODULE_NAME}" 0,1
cefaa03
		rlFileRestore
cefaa03
		rlRun "echo -en '[verify linked]\npath = /bin/false\nargs = \$@\n[end]\n' >> ${SEMANAGE_CONF}"
cefaa03
		rlRun "semodule -i ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "semodule.*failed" ${OUTPUT_FILE} -i
cefaa03
		rlRun "semodule -l | grep ${MODULE_NAME}" 1
cefaa03
		rlRun "semanage module -a ${MODULE_NAME}.pp 2>&1 | tee ${OUTPUT_FILE}"
cefaa03
		rlAssertGrep "could not commit semanage transaction|no such file or directory" ${OUTPUT_FILE} -Ei
cefaa03
		rlRun "semanage module -l | grep ${MODULE_NAME}" 1
cefaa03
	rlPhaseEnd
cefaa03
    fi
cefaa03
cefaa03
	rlPhaseStartCleanup
cefaa03
		rlRun "rm -f ${MODULE_NAME}.pp ${OUTPUT_FILE}"
cefaa03
		rlFileRestore	
cefaa03
	rlPhaseEnd
cefaa03
rlJournalPrintText
cefaa03
rlJournalEnd
cefaa03