Blob Blame History Raw
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/tar/Sanity/tar-using-remote-host-via-ssh
#   Description: It would be nice to have also tested the default behaviour over ssh.
#   Author: Petr Sklenar <psklenar@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
#   This copyrighted material is made available to anyone wishing
#   to use, modify, copy, or redistribute it subject to the terms
#   and conditions of the GNU General Public License version 2.
#
#   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, write to the Free
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
#   Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tar"

rlJournalStart

if rlIsRHEL 5 6; then
    sshpath=`which ssh`
    echo "DEBUG: ssh cmd $sshpath"
    ssh_tar_option="--rsh-command=$sshpath"
else
    # tar on Fedora and RHEL compile in /usr/bin/ssh as the default
    # rsh implementation
    ssh_tar_option=
fi

    rlPhaseStartSetup
        rlAssertRpm $PACKAGE
        rlAssertRpm rmt
        rlFileBackup /etc/ssh/ssh_config \
                     /root/.ssh/authorized_keys \
                     /root/.ssh/config
        rm -rf /tmp/mytarball.tar /tmp/tralalaa.petr
        username=petr$RANDOM
        conf=ssh_config

        echo 'Host localhost' >> /etc/ssh/ssh_config
        echo ' UserKnownHostsFile      /dev/null'  >> /etc/ssh/ssh_config
        echo ' StrictHostKeyChecking   no'  >> /etc/ssh/ssh_config
        echo ' HostbasedAuthentication no'  >> /etc/ssh/ssh_config
    rlPhaseEnd

    rlPhaseStartTest
        ssh_config=/root/.ssh/config
        new_ssh_key="/root/.ssh/id_rsa_$username"
        rlRun "useradd $username"
        rlRun "echo $username | passwd --stdin $username"
        homedir=`getent passwd $username | awk -F: '{print $6}'`
        rlRun "ssh-keygen -t rsa -N '' -f '$new_ssh_key'"
        mkdir /home/$username/.ssh
        cat "$new_ssh_key".pub >> /home/$username/.ssh/authorized_keys
        cat "$new_ssh_key".pub >> /root/.ssh/authorized_keys
        chown -R "$username:$username" "/home/$username/.ssh"
        chmod -R og-rwx "/home/$username/.ssh"
        restorecon -R /home/$username/.ssh
        echo "Host localhost"               >> "$ssh_config"
        echo "  IdentityFile  $new_ssh_key" >> "$ssh_config"
    rlPhaseEnd

    rlPhaseStartTest
        rlAssertNotExists /tmp/mytarball.tar
        echo 'hello world' > tralalaa.petr
        rlRun "tar $ssh_tar_option -c -f $username@localhost:/tmp/mytarball.tar tralalaa.petr"
        rlAssertExists /tmp/mytarball.tar
    rlPhaseEnd

    rlPhaseStartTest
        rm -rf tralalaa.petr
        rlRun "tar xvf /tmp/mytarball.tar"
        rlRun "cat tralalaa.petr  | grep 'hello world'"
    rlPhaseEnd

    rlPhaseStartCleanup
        rm -rf /tmp/mytarball.tar tralalaa.petr
        userdel -r "$username"
        rlLog "clean up"
        rlFileRestore
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd