Blame tests/login/test.sh

7f89380
#!/bin/bash
7f89380
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
7f89380
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7f89380
#
7f89380
#   runtest.sh of /CoreOS/bash/Sanity/login-shell
7f89380
#   Description: the test creates user with bash as login shell and verified the user can log in and get th
7f89380
#   Author: Martin Kyral <mkyral@redhat.com>
7f89380
#
7f89380
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7f89380
#
7f89380
#   Copyright (c) 2016 Red Hat, Inc.
7f89380
#
7f89380
#   This program is free software: you can redistribute it and/or
7f89380
#   modify it under the terms of the GNU General Public License as
7f89380
#   published by the Free Software Foundation, either version 2 of
7f89380
#   the License, or (at your option) any later version.
7f89380
#
7f89380
#   This program is distributed in the hope that it will be
7f89380
#   useful, but WITHOUT ANY WARRANTY; without even the implied
7f89380
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7f89380
#   PURPOSE.  See the GNU General Public License for more details.
7f89380
#
7f89380
#   You should have received a copy of the GNU General Public License
7f89380
#   along with this program. If not, see http://www.gnu.org/licenses/.
7f89380
#
7f89380
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7f89380
7f89380
# Include Beaker environment
7f89380
. /usr/share/beakerlib/beakerlib.sh || exit 1
7f89380
7f89380
PACKAGES=${PACKAGES:-"bash"}
7f89380
SH_BIN=${SH_BIN:-"bash"}
7f89380
7f89380
rlJournalStart
7f89380
    rlPhaseStartSetup
7f89380
        rlAssertRpm --all
7f89380
        rlAssertBinaryOrigin $SH_BIN
7f89380
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
7f89380
        rlRun "cp script.exp ssh.exp tst.sh $TmpDir"
7f89380
        rlRun "pushd $TmpDir"
7f89380
        #USER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
7f89380
        USER="user${RANDOM}"
7f89380
        rlRun "useradd -s /bin/${SH_BIN} -d /home/${USER} ${USER}"
7f89380
        rlRun "echo krava | passwd --stdin ${USER}"
7f89380
        rlRun "sed -i 's/shelluser/${USER}/g' script.exp"
7f89380
        rlRun "sed -i 's/shelluser/${USER}/g' ssh.exp"
7f89380
        rlRun "sed -i 's/shelluser/${USER}/g' tst.sh"
7f89380
        rlRun "sed -i 's/shellbin/${SH_BIN}/g' script.exp"
7f89380
        rlRun "sed -i 's/shellbin/${SH_BIN}/g' ssh.exp"
7f89380
        rlRun "sed -i 's/shellbin/${SH_BIN}/g' tst.sh"
7f89380
        rlRun "cp tst.sh /home/${USER}/"
7f89380
        rlRun "chown ${USER} /home/${USER}/tst.sh"
7f89380
        rlRun "mv /etc/profile.d/tps-cd.sh /root/tps-cd.sh" 0,1 "Backing tps-cd.sh up"
7f89380
    rlPhaseEnd
7f89380
7f89380
    rlPhaseStartTest
7f89380
        rlLog "::::: 'su -c' test :::::"
7f89380
        rlRun "su ${USER} -c 'echo something' | tee test1.log" 0 "echo something test"
7f89380
        rlLog "test1.log: $(cat test1.log)"
7f89380
        rlAssertGrep "something" "test1.log"
7f89380
        rlRun "su ${USER} -c 'echo \$0 | tee /home/${USER}/ps1.log'" 0 "shell detection test"
7f89380
        rlLog "ps1.log: $(cat /home/${USER}/ps1.log)"
7f89380
        rlAssertGrep "$SH_BIN" "/home/${USER}/ps1.log"
7f89380
        # the following does not work with pdksh for some reason
7f89380
        # not a big deal, ssh test can substitute this
7f89380
        [ "$SH_BIN" != "pdksh" ] && {
7f89380
        rlLog "::::: 'su -l' test :::::"
7f89380
        expect script.exp &
7f89380
        sleep 20
7f89380
        pgrep expect && pkill expect
7f89380
        rlLog "test2.log: $(cat /home/${USER}/test2.log)"
7f89380
        rlAssertGrep "something" "/home/${USER}/test2.log"
7f89380
        rlLog "ps2.log: $(cat /home/${USER}/ps2.log)"
7f89380
        rlAssertGrep "$SH_BIN" "/home/${USER}/ps2.log"
7f89380
        }
7f89380
        rlLog "::::: ssh login test :::::"
7f89380
        expect ssh.exp &
7f89380
        sleep 20
7f89380
        pgrep expect && pkill expect
7f89380
        rlLog "ps3.log: $(cat /home/${USER}/ps3.log)"
7f89380
        rlAssertGrep "$SH_BIN" "/home/${USER}/ps3.log"
7f89380
        rlAssertExists "/home/${USER}/tst.dat"
7f89380
    rlPhaseEnd
7f89380
7f89380
    rlPhaseStartCleanup
7f89380
        rlRun "mv /root/tps-cd.sh /etc/profile.d/tps-cd.sh" 0,1 "Restoring tps-cd.sh"
7f89380
        rlRun "su -c 'kill -9 -1' ${USER}" 0 "Killing all processes of ${USER}"
7f89380
        rlRun "userdel -r ${USER}"
7f89380
        rlRun "popd"
7f89380
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
7f89380
    rlPhaseEnd
7f89380
rlJournalPrintText
7f89380
rlJournalEnd