Blame Sanity/sftp/runtest.sh

fa530fb
#!/bin/bash
fa530fb
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
fa530fb
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fa530fb
#
fa530fb
#   runtest.sh of /CoreOS/lftp/Sanity/sftp
fa530fb
#   Description: Basic test for SFTP file transfer
fa530fb
#   Author: Martin Frodl <mfrodl@redhat.com>
fa530fb
#
fa530fb
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fa530fb
#
fa530fb
#   Copyright (c) 2016 Red Hat, Inc.
fa530fb
#
fa530fb
#   This program is free software: you can redistribute it and/or
fa530fb
#   modify it under the terms of the GNU General Public License as
fa530fb
#   published by the Free Software Foundation, either version 2 of
fa530fb
#   the License, or (at your option) any later version.
fa530fb
#
fa530fb
#   This program is distributed in the hope that it will be
fa530fb
#   useful, but WITHOUT ANY WARRANTY; without even the implied
fa530fb
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
fa530fb
#   PURPOSE.  See the GNU General Public License for more details.
fa530fb
#
fa530fb
#   You should have received a copy of the GNU General Public License
fa530fb
#   along with this program. If not, see http://www.gnu.org/licenses/.
fa530fb
#
fa530fb
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fa530fb
fa530fb
# Include Beaker environment
fa530fb
. /usr/share/beakerlib/beakerlib.sh || exit 1
fa530fb
fa530fb
PACKAGES="lftp"
fa530fb
fa530fb
rlJournalStart
fa530fb
    rlPhaseStartSetup
fa530fb
        rlAssertRpm "$PACKAGES"
fa530fb
fa530fb
        rlRun "useradd lftp" 0 "Creating user lftp"
fa530fb
        rlRun "passwd --stdin lftp <<< lftp" 0 "Setting password"
fa530fb
fa530fb
        rlRun "REMOTE=\$(mktemp -d)" 0 "Creating remote directory"
fa530fb
        rlRun "touch ${REMOTE}/file1" 0 "Creating remote file"
fa530fb
        rlRun "mkdir ${REMOTE}/dir" 0 "Creating remote subdirectory"
fa530fb
        rlRun "touch ${REMOTE}/dir/file2" 0 "Creating another remote file"
fa530fb
        rlRun "chmod -R 0755 ${REMOTE}" 0 "Allowing access to remote directory for user lftp"
fa530fb
fa530fb
        rlRun "LOCAL=\$(mktemp -d)" 0 "Creating local directory"
fa530fb
        rlRun "pushd ${LOCAL}"
fa530fb
        if ! rlIsRHEL '<8'; then
fa530fb
            if ! test -e ~/.ssh/known_hosts; then
fa530fb
                rlRun "mkdir -p ~/.ssh" 0 "Create ~/.ssh"
fa530fb
            fi
fa530fb
            rlRun "ssh-keyscan $(hostname) >> ~/.ssh/known_hosts" 0 "Add localhost to known_hosts"
fa530fb
        fi
fa530fb
    rlPhaseEnd
fa530fb
fa530fb
    rlPhaseStartTest "Mirroring files and directories"
fa530fb
        rlRun "lftp -u lftp,lftp -e 'mirror ${REMOTE} ${LOCAL}; exit' sftp://${HOSTNAME}" \
fa530fb
            0 "Mirroring ${REMOTE} to ${LOCAL}"
fa530fb
        rlAssertExists "file1"
fa530fb
        rlAssertExists "dir"
fa530fb
        rlAssertExists "dir/file2"
fa530fb
        rlRun "rm -rf *" 0 "Cleaning local directory"
fa530fb
    rlPhaseEnd
fa530fb
fa530fb
    rlPhaseStartTest "Mirroring symlinks [BZ#1305235]"
fa530fb
        rlRun "TARGET=\$(mktemp -d)" 0 "Creating another directory"
fa530fb
        rlRun "touch ${TARGET}/file3" 0 "Creating file inside it"
fa530fb
        rlRun "ln -s ${TARGET} ${REMOTE}/symlink1" 0 "Creating symlink to it"
fa530fb
        rlRun "chmod -R 0755 ${TARGET}" 0 "Allowing access to remote directory for user lftp"
fa530fb
fa530fb
        rlRun "lftp -u lftp,lftp -e 'mirror -L ${REMOTE} ${LOCAL}; exit' sftp://${HOSTNAME}" \
fa530fb
            0 "Mirroring ${REMOTE} to ${LOCAL} (follow symlinks)"
fa530fb
        rlAssertExists "symlink1"
fa530fb
        rlAssertExists "symlink1/file3"
fa530fb
        rlRun "rm -rf *" 0 "Cleaning local directory"
fa530fb
    rlPhaseEnd
fa530fb
fa530fb
    rlPhaseStartTest "Mirroring circular symlinks"
fa530fb
        rlRun "ln -s ${REMOTE} ${TARGET}/symlink2" 0 "Creating symlink cycle"
fa530fb
        rlRun "lftp -u lftp,lftp  -e 'mirror -L ${REMOTE} ${LOCAL}; exit' sftp://${HOSTNAME}" \
fa530fb
            0,41,1 "Mirroring ${REMOTE} to ${LOCAL} (follow symlinks)"
fa530fb
        rlAssertExists "symlink1"
fa530fb
        rlAssertExists "symlink1/file3"
fa530fb
        rlAssertExists "symlink1/symlink2"
fa530fb
        rlAssertExists "symlink1/symlink2/file1"
fa530fb
        rlRun "rm -rf *" 0 "Cleaning local directory"
fa530fb
    rlPhaseEnd
fa530fb
fa530fb
    rlPhaseStartCleanup
fa530fb
        rlRun "popd"
fa530fb
        rlRun "rm -r ${REMOTE} ${LOCAL} ${TARGET}" 0 "Removing test directories"
fa530fb
        rlRun "userdel -rf lftp" 0 "Deleting user lftp"
fa530fb
    rlPhaseEnd
fa530fb
rlJournalPrintText
fa530fb
rlJournalEnd