vmojzis / tests / selinux

Forked from tests/selinux 4 years ago
Clone
f97a294
#!/bin/bash
f97a294
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
f97a294
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f97a294
#
f97a294
#   runtest.sh of /CoreOS/policycoreutils/Sanity/sestatus
f97a294
#   Description: tests everything about sestatus
f97a294
#   Author: Milos Malik <mmalik@redhat.com>
f97a294
#
f97a294
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f97a294
#
f97a294
#   Copyright (c) 2011 Red Hat, Inc. All rights reserved.
f97a294
#
f97a294
#   This copyrighted material is made available to anyone wishing
f97a294
#   to use, modify, copy, or redistribute it subject to the terms
f97a294
#   and conditions of the GNU General Public License version 2.
f97a294
#
f97a294
#   This program is distributed in the hope that it will be
f97a294
#   useful, but WITHOUT ANY WARRANTY; without even the implied
f97a294
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
f97a294
#   PURPOSE. See the GNU General Public License for more details.
f97a294
#
f97a294
#   You should have received a copy of the GNU General Public
f97a294
#   License along with this program; if not, write to the Free
f97a294
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
f97a294
#   Boston, MA 02110-1301, USA.
f97a294
#
f97a294
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f97a294
f97a294
# Include rhts environment
f97a294
. /usr/bin/rhts-environment.sh
f97a294
. /usr/share/beakerlib/beakerlib.sh
f97a294
f97a294
PACKAGE="policycoreutils"
f97a294
if rlIsRHEL 5 6 ; then
f97a294
    SELINUX_FS_MOUNT="/selinux"
f97a294
else # RHEL-7 and above
f97a294
    SELINUX_FS_MOUNT="/sys/fs/selinux"
f97a294
fi
f97a294
f97a294
rlJournalStart
f97a294
    rlPhaseStartSetup
f97a294
        rlAssertRpm ${PACKAGE}
f97a294
        rlFileBackup /etc/sestatus.conf
f97a294
        rlRun "mount | grep -i selinux" 0,1
f97a294
        OUTPUT_FILE=`mktemp`
f97a294
    rlPhaseEnd
f97a294
f97a294
    rlPhaseStartTest "basic use"
f97a294
        rlRun "sestatus"
f97a294
        rlRun "sestatus -b 2>&1 | tee ${OUTPUT_FILE}"
f97a294
        rlAssertGrep "policy booleans" ${OUTPUT_FILE} -i
f97a294
        rlRun "sestatus -v 2>&1 | tee ${OUTPUT_FILE}"
f97a294
        rlAssertGrep "process contexts" ${OUTPUT_FILE} -i
f97a294
        rlAssertGrep "file contexts" ${OUTPUT_FILE} -i
f97a294
        rlAssertGrep "current context" ${OUTPUT_FILE} -i
f97a294
        rlAssertGrep "init context" ${OUTPUT_FILE} -i
f97a294
        rlAssertGrep "controlling term" ${OUTPUT_FILE} -i
f97a294
        rlRun "sestatus --xyz 2>&1 | tee ${OUTPUT_FILE}"
f97a294
        rlAssertGrep "invalid option" ${OUTPUT_FILE} -i
f97a294
    rlPhaseEnd
f97a294
f97a294
    rlPhaseStartTest "extreme cases"
f97a294
        # pretend that the config file contains an invalid section
f97a294
        rlRun "sed -i 's/files/xyz/' /etc/sestatus.conf"
f97a294
        rlRun "sestatus -v 2>&1 | tee ${OUTPUT_FILE}"
f97a294
        rlAssertGrep "line not in a section" ${OUTPUT_FILE} -i
f97a294
        rlRun "rm -f /etc/sestatus.conf"
f97a294
        rlRun "mkdir /etc/sestatus.conf" # intentionally replaced a file with a directory
f97a294
        rlRun "sestatus -v"
f97a294
        # pretend that the config file is missing
f97a294
        rlRun "rm -rf /etc/sestatus.conf"
f97a294
        for OPTION in "-bv" "-v" ; do
f97a294
            rlRun "sestatus ${OPTION} 2>&1 | tee ${OUTPUT_FILE}"
f97a294
            rlAssertGrep "unable to open /etc/sestatus.conf" ${OUTPUT_FILE} -i
f97a294
        done
f97a294
        rlFileRestore
f97a294
        # pretend that SELinux is disabled
f97a294
        rlRun "umount ${SELINUX_FS_MOUNT}"
f97a294
        for OPTION in "" "-b" "-v" "-bv" ; do
f97a294
            rlRun "sestatus ${OPTION} 2>&1 | tee ${OUTPUT_FILE}"
f97a294
            rlAssertGrep "selinux status.*disabled" ${OUTPUT_FILE} -i
f97a294
        done
f97a294
        rlRun "mount -t selinuxfs none ${SELINUX_FS_MOUNT}"
f97a294
        # pretend that no booleans are defined
f97a294
        rlRun "mkdir ./booleans"
f97a294
        rlRun "mount --bind ./booleans ${SELINUX_FS_MOUNT}/booleans"
f97a294
        rlRun "sestatus -b 2>&1 | tee ${OUTPUT_FILE}"
f97a294
        rlRun "umount ${SELINUX_FS_MOUNT}/booleans"
f97a294
        rlAssertNotGrep "booleans" ${OUTPUT_FILE} -i
f97a294
        rlRun "rmdir ./booleans"
f97a294
    rlPhaseEnd
f97a294
f97a294
    # This bug is not worth fixing in RHEL-5
f97a294
    if ! rlIsRHEL 5 ; then
f97a294
    rlPhaseStartTest
f97a294
        rlRun "rpm -ql ${PACKAGE} | grep /usr/sbin/sestatus"
f97a294
        rlRun "rpm -ql ${PACKAGE} | grep /usr/share/man/man8/sestatus.8"
f97a294
        for OPTION in b v ; do
f97a294
            rlRun "sestatus --help 2>&1 | grep -- -${OPTION}"
f97a294
            rlRun "man sestatus | col -b | grep -- -${OPTION}"
f97a294
        done
f97a294
        if ! rlIsRHEL 6 ; then
f97a294
            rlRun "man -w sestatus.conf"
f97a294
        fi
f97a294
    rlPhaseEnd
f97a294
    fi
f97a294
f97a294
    rlPhaseStartCleanup
f97a294
        rlFileRestore
f97a294
        rm -f ${OUTPUT_FILE}
f97a294
    rlPhaseEnd
f97a294
rlJournalPrintText
f97a294
rlJournalEnd
f97a294