sshportal/examples/integration/test.sh

83 lines
2.1 KiB
Bash
Raw Normal View History

2017-11-15 18:24:57 +08:00
#!/bin/sh -e
# Setup a new sshportal and performs some checks
PORT=${PORT:-2222}
SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN=integration
# tempdir
WORK_DIR=`mktemp -d`
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
cd "${WORK_DIR}"
2017-11-15 18:24:57 +08:00
# pre cleanup
docker_cleanup() {
( set -x
docker rm -f -v sshportal-integration 2>/dev/null >/dev/null || true
)
}
tempdir_cleanup() {
rm -rf "${WORK_DIR}"
2017-11-15 18:24:57 +08:00
}
docker_cleanup
trap tempdir_cleanup EXIT
2017-11-15 18:24:57 +08:00
# start server
( set -xe;
docker run \
-d \
-e SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN=${SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN} \
--name=sshportal-integration \
-p${PORT}:2222 \
2017-11-19 08:25:46 +08:00
moul/sshportal --debug
2017-11-15 18:24:57 +08:00
)
2017-11-19 08:25:46 +08:00
while ! nc -z localhost ${PORT}; do
sleep 1
done
sleep 3
2017-11-15 18:24:57 +08:00
# integration suite
xssh() {
set -e
echo "+ ssh {sshportal} $@" >&2
2017-11-15 18:24:57 +08:00
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no localhost -p ${PORT} $@
}
2017-11-19 08:25:46 +08:00
# login
2017-11-15 18:24:57 +08:00
xssh -l invite:integration
2017-11-15 19:23:50 +08:00
# hostgroup/usergroup/acl
xssh -l admin hostgroup create
xssh -l admin hostgroup create --name=hg1
xssh -l admin hostgroup create --name=hg2 --comment=test
xssh -l admin usergroup inspect hg1 hg2
xssh -l admin hostgroup ls
xssh -l admin usergroup create
xssh -l admin usergroup create --name=ug1
xssh -l admin usergroup create --name=ug2 --comment=test
xssh -l admin usergroup inspect ug1 ug2
xssh -l admin usergroup ls
xssh -l admin acl create --ug=ug1 --ug=ug2 --hg=hg1 --hg=hg2 --comment=test --action=allow --weight=42
xssh -l admin acl inspect 2
xssh -l admin acl ls
# basic host create
2017-11-15 18:24:57 +08:00
xssh -l admin host create bob@example.org:1234
xssh -l admin host create test42
xssh -l admin host create --name=testtest --comment=test --password=test test@test.test
2017-11-15 19:23:50 +08:00
xssh -l admin host create --group=hg1 --group=hg2 hostwithgroups.org
xssh -l admin host inspect example test42 testtest hostwithgroups
2017-11-15 18:24:57 +08:00
xssh -l admin host ls
# backup/restore
xssh -l admin config backup --indent > backup-1
xssh -l admin config restore --confirm < backup-1
xssh -l admin config backup --indent > backup-2
diff <(cat backup-1 | grep -v '"date":') <(cat backup-2 | grep -v '"date":')
2017-11-15 18:24:57 +08:00
# post cleanup
#cleanup