0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2024-12-22 13:14:42 -05:00

Add basic unit testing

This commit is contained in:
Adrian Dvergsdal 2015-11-23 13:39:17 +01:00
parent e03db0f4d9
commit bc2cbdef4f
3 changed files with 96 additions and 0 deletions

27
tests/id_rsa Normal file
View file

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAxww0MPWvZohlgxFyxvZjEezrld7n5pIJuYbZ7bmZ8UcNbFH8
kpoHmmOWQ7x8ObhDLpcWEv8ifoS8RYLI97VMCJcEc/ckcq82ZvoAROF4bG/jYXWj
EHRZzEp93FMPFBzvBZkXeBS4ksd9sfqRfNyZzUeu/t380oNsCpr8+TnaEEhC5+E6
UbjreH0CPttkD0aRjrszer1hkGs2Py80VZSnidZGrFRNafxigjcLRNp4ZJNweFc7
mcuLIfBapJXIJGuj2XAxrt86pBQoESfaETg0m3DWl4Z1w6wZZ26WnIiVOHdiXcj3
U0tdZwCixPihH5yYYyy6fE11kMw9sQdhx+4BHQIDAQABAoIBAFGxrpIRpCW/AXrj
5GnIoiyvQpnGXQODGL6unC83p/khIl883x8EXO5+xSOT7qB6AgjTNdoiIPQwYl1d
KkKQhF5aLRezbaAsTXXCUe3zZEuNOJO9hmmwd1KjmDifVmb44Rk5FirQxlhnzC0K
HEBVAkMAktBEKAn2qpdHuWBI4Dkh1hWIpChtkq4h1brsgaYurkfRnJOv1i/8kIWa
QlpzxZk2m5i1TpyfRsxuqt3migcrUSJsCmMwkFylDNKYQVS4HRZAXZndq3o51ZF5
AzwgMjCty9G1eQGFx4k8CzDvahhTKHds73RHFTEGqWZiJNayuzb0Yz0wvaFlHnWl
35E11bkCgYEA5ALPklJ36jLNJiCzReH7SlAczIN9Rh1kRReHDD4St5cxA/nCynhI
HET2g8QBnonup1V3WPsDmLTga0hPhXhrI3oSm7jhBc2HOqNaJ/z6jYgGbE6pP05u
PgCi8gubX59733FJINmy5XOMzRaVTCfO2lh3zB4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8Fqklcgka6PZcDGu3zqkFCgRJ9oRODSbcNaXhnXDrBlnbpaciJU4d2JdyPdTS11nAKLE+KEfnJhjLLp8TXWQzD2xB2HH7gEd atmoz@arch-book

68
tests/run Executable file
View file

@ -0,0 +1,68 @@
#!/bin/bash
# See: https://github.com/djui/bashunit
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
buildDir="$scriptDir/.."
tmpDir="/tmp/atmoz_sftp_test"
build=${1:-"build"}
sftpImageName="atmoz/sftp_test"
sftpContainerName="atmoz_sftp_test"
function beforeTest() {
if [ "$build" == "build" ]; then
docker build --pull=true --tag "$sftpImageName" "$buildDir"
fi
rm -rf "$tmpDir" # clean state
mkdir "$tmpDir"
docker run \
-v "$scriptDir/id_rsa.pub":/home/test/.ssh/keys/id_rsa.pub:ro \
-v "$tmpDir":/home/test/share \
--name "$sftpContainerName" \
--expose 22 \
-d "$sftpImageName" \
test:123:$(id -u):$(id -g) \
> /dev/null
sleep 1 # wait for sftp server to get ready
}
function afterTest() {
docker rm -fv "$sftpContainerName" > /dev/null
rm -rf "$tmpDir"
}
function getSftpIp() {
docker inspect -f {{.NetworkSettings.IPAddress}} "$sftpContainerName"
}
function runSftpCommands() {
ip="$(getSftpIp)"
echo "$@" | sftp \
-i "$scriptDir/id_rsa" \
-oStrictHostKeyChecking=no \
-oUserKnownHostsFile=/dev/null \
-b - test@$ip \
> /dev/null 2>&1
}
function testContainerIsRunning() {
ps="$(docker ps -q -f name="$sftpContainerName")"
assertNotEqual "$ps" ""
}
function testLoginUsingSshKey() {
runSftpCommands "exit"
assertReturn $? 0
}
function testWritePermission() {
runSftpCommands $'cd share\nmkdir test'
test -d "$tmpDir/test"
assertReturn $? 0
}
# Run tests
source "$scriptDir/bashunit.bash"
# Nothing happens after this