diff --git a/orbit/test-style.sh b/orbit/test-style.sh index 9eb7edf5..62e66bac 100755 --- a/orbit/test-style.sh +++ b/orbit/test-style.sh @@ -1,25 +1,6 @@ #!/bin/bash -FLAKE8_FLAGS="" - -while getopts "v" FLAG; do - case $FLAG in - v) - FLAKE8_FLAGS="$FLAKE8_FLAGS " - ;; - esac -done - -SOURCES="" -scan() { - echo "[SCAN] ${1}" - flake8 ${FLAKE8_FLAGS} ${1} - RES=$? - if test "$RES" -ne "0" - then - exit 1 - fi -} +scan() { echo "[SCAN] ${1}" ; flake8 "${1}" || exit 1 ; } scan radius.py scan config.py diff --git a/test.sh b/test.sh index 82633179..8ed9ed5c 100755 --- a/test.sh +++ b/test.sh @@ -1,11 +1,24 @@ -#!/bin/bash -# +#!/usr/bin/env bash + # Testing script for singularity and orbit +# This line: +# - aborts the script after any pipeline returns nonzero (e) +# - shows all commands as they are run (x) +# - sets any dereference of an unset variable to trigger an error (u) +# - causes the return value of a pipeline to be the nonzero return value +# of the furthest right failing command or zero if no command failed (o pipefail) set -exuo pipefail +require() { command -v "$1" || { echo "error: $1 command required yet absent" ; exit 1 ; } ; } +require curl +require flake8 +require chcon +require podman +require shellcheck + # Reset the tests and mail directories -rm -rf test email/logs/* email/mail/* +sudo rm -rf test email/logs/* email/mail/* mkdir -p test # This is a temporary workaround until we properly implement volumes @@ -19,20 +32,17 @@ PORT=${PORT:-443} POP_PORT=${POP_PORT:-995} SMTP_PORT=${SMTP_PORT:-465} EMAIL_HOSTNAME="kdlp.underground.software" -export DOCKER=${DOCKER:-"sudo podman"} -export CONTAINER=${CONTAINER:-"singularity_orbit_1"} # NOTE: don't set DEVEL and STAGING at the same time -if [ ! -z "$DEVEL" ]; then +if [ -n "$DEVEL" ]; then PORT=1443 POP_PORT=1995 SMTP_PORT=1465 EMAIL_HOSTNAME="localhost" - export DOCKER="podman" fi -if [ ! -z "$STAGING" ]; then +if [ -n "$STAGING" ]; then EMAIL_HOSTNAME="dev.underground.software" fi @@ -71,7 +81,7 @@ curl --url "https://localhost:$PORT/register" \ | tee test/register_fail_wrong \ | grep "msg = no such student" -# Check that registration suceeds with correct student id +# Check that registration succeeds with correct student id curl --url "https://localhost:$PORT/register" \ --verbose \ --insecure \ @@ -121,7 +131,8 @@ curl --url "pop3s://localhost:$POP_PORT" \ | diff <(printf '\r\n') /dev/stdin CR=$(printf "\r") -# Check that the user can send a message to the sever +# Check that the user can send a message to the server +( curl --url "smtps://localhost:$SMTP_PORT" \ --verbose \ --insecure \ @@ -130,14 +141,15 @@ curl --url "smtps://localhost:$SMTP_PORT" \ --mail-from "user@$EMAIL_HOSTNAME" \ --mail-rcpt "other@$EMAIL_HOSTNAME" \ --upload-file - \ - --user 'user:pass' \ - > test/smtp_send_email < test/pop_get_message -test_pop_get_message=$? + --user user:pass \ + | tee test/pop_get_message \ + | grep "Bottom text" # Check that we can delete a user orbit/warpdrive.sh \ -u user -w \ - > test/delete_user + | tee test/delete_user \ + | grep "user" + +# Check for shell script styyle compliance with shellcheck +shellcheck test.sh +shellcheck orbit/test-style.sh -# Check style compliance -python -m venv orbit-dev -source orbit-dev/bin/activate -pip install -r orbit/dev-requirements.txt +# Check python style compliance with flake8 pushd orbit ./test-style.sh popd