evobackup/test/main.bats

129 lines
3.8 KiB
Plaintext
Raw Normal View History

2018-03-05 15:29:08 +01:00
#!/usr/bin/env bats
setup() {
2018-03-05 16:15:35 +01:00
port=$(awk -v min=2222 -v max=2999 'BEGIN{srand(); print int(min+rand()*(max-min+1))}')
2018-03-28 15:11:49 +02:00
date=$(date +"%Y-%m-%d-%H")
inode=$(stat --format=%i /backup)
2018-03-05 15:29:08 +01:00
rm -f /root/bkctld.key* && ssh-keygen -t rsa -N "" -f /root/bkctld.key -q
2019-01-08 11:01:17 +01:00
. /usr/lib/bkctld/config
JAILNAME=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w15 | head -n1)
2018-03-28 15:11:49 +02:00
}
teardown() {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-remove "${JAILNAME}" && rm -rf "${INCDIR}/*"
2018-03-28 15:11:49 +02:00
}
@test "init" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
inode=$(stat --format=%i /backup)
run test -d "${CONFDIR}/${JAILNAME}"
[ "${status}" -eq 0 ]
2018-03-28 15:11:49 +02:00
}
@test "start" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
pid=$(cat "${RUNDIR}/${JAILNAME}/sshd.pid")
2018-03-28 15:11:49 +02:00
run ps --pid "${pid}"
[ "${status}" -eq 0 ]
}
@test "stop" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
pid=$(cat "${RUNDIR}/${JAILNAME}/sshd.pid")
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-stop "${JAILNAME}"
2018-03-28 15:11:49 +02:00
run ps --pid "${pid}"
[ "${status}" -ne 0 ]
}
@test "reload" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
/usr/lib/bkctld/bkctld-reload "${JAILNAME}"
run grep "Received SIGHUP; restarting." "${JAILDIR}/${JAILNAME}/var/log/authlog"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
}
@test "restart" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
bpid=$(cat "${RUNDIR}/${JAILNAME}/sshd.pid")
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-restart "${JAILNAME}"
apid=$(cat "${RUNDIR}/${JAILNAME}/sshd.pid")
2018-03-28 15:11:49 +02:00
[ "${bpid}" -ne "${apid}" ]
2018-03-05 15:29:08 +01:00
}
2018-03-28 15:11:49 +02:00
@test "status" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
run /usr/lib/bkctld/bkctld-status "${JAILNAME}"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
}
@test "key" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-key "${JAILNAME}" /root/bkctld.key.pub
run cat "${CONFDIR}/${JAILNAME}/ssh/authorized_keys"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
[ "${output}" = $(cat /root/bkctld.key.pub) ]
2018-03-05 15:29:08 +01:00
}
2018-03-05 16:15:35 +01:00
@test "port" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
/usr/lib/bkctld/bkctld-port "${JAILNAME}" "${port}"
2018-03-05 16:15:35 +01:00
run nc -vz 127.0.0.1 "${port}"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
2018-03-05 16:15:35 +01:00
}
2018-03-28 15:11:49 +02:00
@test "inc" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-inc
2018-03-28 15:11:49 +02:00
if [ "${inode}" -eq 256 ]; then
run stat --format=%i "${MOUNT_POINT}/${JAILNAME}/${date}"
2018-03-28 15:11:49 +02:00
[ "${output}" -eq 256 ]
else
run test -d "${MOUNT_POINT}/${JAILNAME}/${date}"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
fi
}
2018-03-05 16:15:35 +01:00
@test "ssh" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
/usr/lib/bkctld/bkctld-port "${JAILNAME}" "${port}"
/usr/lib/bkctld/bkctld-key "${JAILNAME}" /root/bkctld.key.pub
2018-03-05 16:15:35 +01:00
run ssh -p "${port}" -i /root/bkctld.key -oStrictHostKeyChecking=no root@127.0.0.1 ls
2018-03-05 15:43:36 +01:00
[ "$status" -eq 0 ]
2018-03-05 15:29:08 +01:00
}
@test "rsync" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
/usr/lib/bkctld/bkctld-port "${JAILNAME}" "${port}"
/usr/lib/bkctld/bkctld-key "${JAILNAME}" /root/bkctld.key.pub
2018-03-05 16:15:35 +01:00
run rsync -a -e "ssh -p ${port} -i /root/bkctld.key -oStrictHostKeyChecking=no" /tmp/ root@127.0.0.1:/var/backup/
[ "$status" -eq 0 ]
}
2019-01-08 11:01:17 +01:00
@test "check-ok" {
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
run /usr/lib/bkctld/bkctld-check
[ "$status" -eq 0 ]
}
@test "check-warning" {
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
touch --date="$(date -d -2days)" "${LOGDIR}/${JAILNAME}/lastlog"
2019-01-08 11:01:17 +01:00
run /usr/lib/bkctld/bkctld-check
[ "$status" -eq 1 ]
}
@test "check-critical" {
/usr/lib/bkctld/bkctld-init "${JAILNAME}"
touch --date="$(date -d -3days)" "${LOGDIR}/${JAILNAME}/lastlog"
2019-01-08 11:01:17 +01:00
run /usr/lib/bkctld/bkctld-check
[ "$status" -eq 2 ]
}