#!/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"
ls -la $sshpath
which ssh
sshcmd="--rsh-command=$sshpath"
else
sshcmd=""
fi
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlAssertRpm rmt
rlFileBackup /etc/ssh/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
# copy&paste from http://pkgs.devel.redhat.com/cgit/tests/openssh/tree/sshd/sanity/runtest.sh
rlRun "useradd $username"
rlRun "echo $username | passwd --stdin $username"
homedir=`getent passwd $username | awk -F: '{print $6}'`
ls /root/.ssh/id_rsa || ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa
rlAssert0 "ssh-keygen passed" $?
mkdir /home/$username/.ssh
cat /root/.ssh/id_rsa.pub >> /home/$username/.ssh/authorized_keys
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
restorecon -R /home/$username/.ssh
rlPhaseEnd
rlPhaseStartTest
rlAssertNotExists /tmp/mytarball.tar
echo 'hello world' > tralalaa.petr
rlRun "tar $sshcmd -c -f $username@localhost:/tmp/mytarball.tar tralalaa.petr"
rlAssertExists /tmp/mytarball.tar
rlPhaseEnd
rlPhaseStartTest
rlLog "nothing"
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 $username
rlLog "clean up"
rlFileRestore
rlPhaseEnd
rlJournalPrintText
rlJournalEnd