#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/lftp/Regression/bz1793557-SFTP-over-LFTP-hangs-if-host-key-of-the-remote
# Description: Test for BZ#1793557 (SFTP over LFTP hangs if host key of the remote)
# Author: Ondrej Mejzlik <omejzlik@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# 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, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="lftp"
TEST_USER="USER234576"
TEST_PASS="medved"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE || rlDie "Package $PACKAGE not installed"
rlLog "Arch: $(arch), PC name: $(hostname), $(hostname -A) User: $(whoami)"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir" 0 "Going into tmp directory $TmpDir"
rlRun "useradd $TEST_USER" 0 "Adding user $TEST_USER"
rlRun "touch /home/$TEST_USER/testFile" 0 "Create test file"
rlRun "echo $TEST_PASS | passwd $TEST_USER --stdin" 0 "Create password for $TEST_USER"
rlRun "rlFileBackup --missing-ok /root/.ssh/known_hosts" 0 "Back up known_hosts"
rlPhaseEnd
rlGetTestState && {
rlPhaseStartTest
rlRun "rm -f /home/$TEST_USER/.ssh/known_hosts" 0 "Remove known_hosts"
rlRun "timeout 20 lftp -e 'set sftp:connect-program \"ssh -v -a -x\"; set sftp:auto-confirm yes; cd /home/USER234576; ls; quit' sftp://$TEST_USER:$TEST_PASS@127.0.0.1 &>out.txt" 0 "Run lftp"
cat out.txt
rlAssertExists "/root/.ssh/known_hosts"
rlAssertGrep "127.0.0.1" /root/.ssh/known_hosts
rlAssertGrep "testFile" out.txt
rlPhaseEnd
}
rlPhaseStartCleanup
# known_hosts may not exist, erro nothing backed up is ok here
rlRun "userdel -rf $TEST_USER" 0 "Removing $TEST_USER"
rlRun "rlFileRestore" 0,16 "Restore known_hosts"
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd