Skip to content

Make source optional #131

Make source optional

Make source optional #131

Workflow file for this run

name: Self-test
on:
push:
pull_request:
jobs:
selftest:
name: Self-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Generate SSH key
id: ssh-key
run: |
set -e
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa.test -q -N ""
SSH_KEY=$(cat ~/.ssh/id_rsa.test)
echo "::add-mask::${SSH_KEY//$'\n'/'%0A'}"
echo "::set-output name=private-key::${SSH_KEY//$'\n'/'%0A'}"
- name: Start backing server
id: server
run: |
set -e
echo -e "\e[32mBuilding container image...\e[0m"
docker build -t sshd test
echo -e "\e[32mCreating container...\e[0m"
CONTAINER_ID=$(docker create -e "SSH_KEY=$(cat ~/.ssh/id_rsa.test.pub)" -p 2222:2222 sshd)
echo -e "\e[32mStarting container...\e[0m"
docker start "${CONTAINER_ID}"
i=0
echo -e "\e[32mWaiting for the SSH container to be healthy...\e[0m"
until [ "$(docker inspect -f '{{.State.Health.Status}}' "${CONTAINER_ID}")" == "healthy" ]; do
i=$((i+1))
if [ "$i" -gt 30 ]; then
echo -e "\e[31mBacking server failed to come up.\e[0m"
exit 1
fi
echo -e "Still waiting for the SSH container to come up, current status is \e[1m$(docker inspect -f '{{.State.Health.Status}}' "${CONTAINER_ID}")\e[0m..."
sleep 1
done
echo -e "\e[32mSSH server is now up.\e[0m"
echo -e "\e[32mObtaining SSH server RSA host key...\e[0m"
/usr/bin/ssh-keyscan -p 2222 127.0.0.1 >~/.ssh/known_hosts.test
echo "Known hosts are:"
cat ~/.ssh/known_hosts.test
HOST_KEYS=$(cat ~/.ssh/known_hosts.test)
for keytype in $(cat ~/.ssh/known_hosts.test | cut -f 2 -d ' ' | sed -e 's/ssh-//g'); do
ssh -Q key | grep "${keytype}" >> ~/.ssh/keytypes.test
done
HOST_KEY_ALGOS=$(cat ~/.ssh/keytypes.test)
echo "::set-output name=hostkeys::${HOST_KEYS//$'\n'/'%0A'}"
echo "::set-output name=hostkey-algos::${HOST_KEY_ALGOS//$'\n'/','}"
echo -e "\e[32mHost key obtained.\e[0m"
- name: Generate test data
run: |
set -e
mkdir -p testdata
for i in $(seq 1 20); do touch testdata/$i; sleep 1; done
- name: Upload test data
uses: ./
with:
host: 127.0.0.1
port: 2222
username: test
key: ${{ steps.ssh-key.outputs.private-key }}
source: testdata/*
target: /test
known_hosts: ${{ steps.server.outputs.hostkeys }}
- name: Check uploaded files
run: |
set -e
UPLOADED_FILES_COUNT=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "ls /test" | wc -l)
if [ "${UPLOADED_FILES_COUNT}" -ne 20 ]; then
echo "Incorrect number of files found on server: ${UPLOADED_FILES_COUNT}"
exit 1
fi
- name: Upload test data with cleanup
uses: ./
with:
host: 127.0.0.1
port: 2222
username: test
key: ${{ steps.ssh-key.outputs.private-key }}
source: testdata/*
target: /test
cleanup: yes
keep_files_count: 10
known_hosts: ${{ steps.server.outputs.hostkeys }}
- name: Check uploaded files
run: |
set -e
UPLOADED_FILES_COUNT=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "ls -1 /test" | wc -l)
if [ "${UPLOADED_FILES_COUNT}" -ne 10 ]; then
echo -e "\e[31mIncorrect number of files found on server: ${UPLOADED_FILES_COUNT}\e[0m"
exit 1
fi
echo -e "\e[32mCorrect number of files on server.\e[0m"
UPLOADED_FILES=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "ls -1 /test" | sort -n)
EXPECTED_FILES="$(seq 11 20 | sort -n)"
if [ "${UPLOADED_FILES//$'\n'/' '}" != "${EXPECTED_FILES//$'\n'/' '}" ]; then
echo -e "\e[31mMismatching uploaded files.\e[0m"
echo -e "\e[31mFound: ${UPLOADED_FILES//$'\n'/' '}\e[0m"
echo -e "\e[31mExpected: ${EXPECTED_FILES//$'\n'/' '}\e[0m"
exit 1
fi
echo -e "\e[32mCorrect files left on server.\e[0m"
- name: Create hardlinks to some of the previously uploaded files
run: |
set -e
ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "cd /test && cp -l 11 11-copy"
- name: Fill one of the files with new data
run: |
set -e
echo 'Test Data' >> testdata/11
- name: Clean the source directory a bit
run: |
set -e
rm testdata/10 testdata/12 testdata/13 testdata/15 testdata/17
- name: Re-upload the new file(s) without deleting the files with the same names
uses: ./
with:
host: 127.0.0.1
port: 2222
username: test
key: ${{ steps.ssh-key.outputs.private-key }}
source: testdata/1*
target: /test
cleanup: yes
known_hosts: ${{ steps.server.outputs.hostkeys }}
- name: Test if the upload modified the previously hard-linked file(s)
run: |
set -e
SHA256SUM=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "sha256sum /test/11 | cut -f1 -d' '")
if [ "${SHA256SUM}" != "15c94dc2cf2ff71f83d0e5b9f7e7c3eb5efa8ba215dca81108cabf91f1958834" ]; then
echo -e "\e[31mFile was not properly uploaded.\e[0m"
exit 1
fi
SHA256SUM=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "sha256sum /test/11-copy | cut -f1 -d' '")
if [ "${SHA256SUM}" != "15c94dc2cf2ff71f83d0e5b9f7e7c3eb5efa8ba215dca81108cabf91f1958834" ]; then
echo -e "\e[31mPreviously uploaded file wasn't modified by the newly uploaded file.\e[0m"
exit 1
fi
- name: Fill one of the files with (yet more) new data
run: |
set -e
echo 'Test Data Test Data' >> testdata/11
- name: Re-upload the new file(s) deleting the files with the same names
uses: ./
with:
host: 127.0.0.1
port: 2222
username: test
key: ${{ steps.ssh-key.outputs.private-key }}
source: testdata/1*
target: /test
delete_before_upload: yes
cleanup: yes
known_hosts: ${{ steps.server.outputs.hostkeys }}
- name: Test if the upload modified the previously hard-linked file(s)
run: |
set -e
SHA256SUM=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "sha256sum /test/11 | cut -f1 -d' '")
if [ "${SHA256SUM}" != "10237c1e142ed418cddb16ec249c89df4ffd4a9a729fdc2a6b41c8aa41f6d027" ]; then
echo -e "\e[31mFile was not properly uploaded.\e[0m"
exit 1
fi
SHA256SUM=$(ssh -o UserKnownHostsFile=~/.ssh/known_hosts.test -o "HostKeyAlgorithms=${{ steps.server.outputs.hostkey-algos }}" -i ~/.ssh/id_rsa.test -p 2222 test@127.0.0.1 "sha256sum /test/11-copy | cut -f1 -d' '")
if [ "${SHA256SUM}" != "15c94dc2cf2ff71f83d0e5b9f7e7c3eb5efa8ba215dca81108cabf91f1958834" ]; then
echo -e "\e[31mPreviously uploaded file was modified by the newly uploaded file.\e[0m"
exit 1
fi