From 41bc4a327698f878f3925b8c58fc80de6bee3ac1 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 25 Mar 2024 23:22:52 -0400 Subject: [PATCH 01/14] test: fix spelling errors Signed-off-by: Joel Savitz --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 82633179..c74de095 100755 --- a/test.sh +++ b/test.sh @@ -71,7 +71,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 +121,7 @@ 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 \ From 4b075c2ce29a2ae7b377715181ca4768bcd31cd0 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 25 Mar 2024 22:56:22 -0400 Subject: [PATCH 02/14] test: drop assignment of env vars for warpdrive Since warpdrive defaults are now sane, simply use them directly. When testing on prod/staging, sudo is needed and this matches current invocation of podman compose. Signed-off-by: Joel Savitz --- test.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/test.sh b/test.sh index c74de095..471af7bc 100755 --- a/test.sh +++ b/test.sh @@ -19,8 +19,6 @@ 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 @@ -29,7 +27,6 @@ if [ ! -z "$DEVEL" ]; then POP_PORT=1995 SMTP_PORT=1465 EMAIL_HOSTNAME="localhost" - export DOCKER="podman" fi if [ ! -z "$STAGING" ]; then From 009005d264724b6421f73f0f3a54d8cdcd4357e2 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 25 Mar 2024 23:04:34 -0400 Subject: [PATCH 03/14] test: fix line continuation to properly capture pop stdout Signed-off-by: Joel Savitz --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 471af7bc..d8632da9 100755 --- a/test.sh +++ b/test.sh @@ -142,7 +142,7 @@ curl --url "pop3s://localhost:$POP_PORT/1" \ --insecure \ --fail \ --no-progress-meter \ - --user user:pass + --user user:pass \ > test/pop_get_message test_pop_get_message=$? From 0eee0d71ee487cf0c84f03c7a43de89c662d918a Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 25 Mar 2024 23:21:20 -0400 Subject: [PATCH 04/14] test: check output of all tests Signed-off-by: Joel Savitz --- test.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test.sh b/test.sh index d8632da9..5ac7b245 100755 --- a/test.sh +++ b/test.sh @@ -119,6 +119,7 @@ curl --url "pop3s://localhost:$POP_PORT" \ CR=$(printf "\r") # Check that the user can send a message to the server +( curl --url "smtps://localhost:$SMTP_PORT" \ --verbose \ --insecure \ @@ -127,14 +128,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=$? + | 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 style compliance python -m venv orbit-dev From 193baac1215b238cadea9a9190b7e0a3120de2ab Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 25 Mar 2024 23:22:08 -0400 Subject: [PATCH 05/14] test: forcibly remove any previous test artifacts with sudo Signed-off-by: Joel Savitz --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 5ac7b245..635ac466 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ set -exuo pipefail # 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 From 308ef401c58df5f99d418b8eeba47522539ce639 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 01:37:24 -0400 Subject: [PATCH 06/14] test: bail at the begining when dependencies are lacking Signed-off-by: Joel Savitz --- test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.sh b/test.sh index 635ac466..255ed3b3 100755 --- a/test.sh +++ b/test.sh @@ -4,6 +4,11 @@ set -exuo pipefail +command -v curl || { echo "error: curl command required yet absent" ; exit 1 ; } +command -v flake8 || { echo "error: flake8 command required yet absent" ; exit 1 ; } +command -v chcon || { echo "error: chcon command required yet absent" ; exit 1 ; } +command -v podman || { echo "error: podman command required yet absent" ; exit 1 ; } + # Reset the tests and mail directories sudo rm -rf test email/logs/* email/mail/* mkdir -p test From 96c387ac1c84585f22a291d217b447d7b3202aef Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 01:36:56 -0400 Subject: [PATCH 07/14] test: drop the virtualenv around flake8 invocation Signed-off-by: Joel Savitz --- test.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test.sh b/test.sh index 255ed3b3..fc983736 100755 --- a/test.sh +++ b/test.sh @@ -160,10 +160,6 @@ orbit/warpdrive.sh \ | grep "user" # Check style compliance -python -m venv orbit-dev -source orbit-dev/bin/activate -pip install -r orbit/dev-requirements.txt pushd orbit ./test-style.sh popd - From ddd6d4a53b94d9c4e6a49810e67edb4d1b3e07e5 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 17:54:52 -0400 Subject: [PATCH 08/14] test: use more universal shabang to specify the bash interpreter Signed-off-by: Joel Savitz --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index fc983736..6363ced0 100755 --- a/test.sh +++ b/test.sh @@ -1,5 +1,5 @@ -#!/bin/bash -# +#!/usr/bin/env bash + # Testing script for singularity and orbit set -exuo pipefail From 3a4476f95cb41ba03850a5ee138116d3e4f838e2 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:01:53 -0400 Subject: [PATCH 09/14] test: document the options passed to the set command Signed-off-by: Joel Savitz --- test.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test.sh b/test.sh index 6363ced0..36311209 100755 --- a/test.sh +++ b/test.sh @@ -2,6 +2,12 @@ # 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 command -v curl || { echo "error: curl command required yet absent" ; exit 1 ; } From 406c5e51f113d8d75bc69a2181e4dccd54fde3b0 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:04:14 -0400 Subject: [PATCH 10/14] test: clarify comment on python style checking Signed-off-by: Joel Savitz --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 36311209..2b9a4862 100755 --- a/test.sh +++ b/test.sh @@ -165,7 +165,7 @@ orbit/warpdrive.sh \ | tee test/delete_user \ | grep "user" -# Check style compliance +# Check python style compliance with flake8 pushd orbit ./test-style.sh popd From 1d730261633e6960b65840ac2295e13f32840753 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:07:22 -0400 Subject: [PATCH 11/14] test: fix nonzero string size checks to pass shellcheck Signed-off-by: Joel Savitz --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 2b9a4862..f263568d 100755 --- a/test.sh +++ b/test.sh @@ -33,14 +33,14 @@ EMAIL_HOSTNAME="kdlp.underground.software" # 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" fi -if [ ! -z "$STAGING" ]; then +if [ -n "$STAGING" ]; then EMAIL_HOSTNAME="dev.underground.software" fi From c31863b71b727606d638f6ac738debe0fe01fa2e Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:13:13 -0400 Subject: [PATCH 12/14] test: simplify test-style.sh to remove bloat and pass shellcheck Signed-off-by: Joel Savitz --- orbit/test-style.sh | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) 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 From 7dba3b60b4b147bd01cf8e637518378d2c87bef1 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:14:35 -0400 Subject: [PATCH 13/14] test: use shellcheck to scan the two scripts in the repo Signed-off-by: Joel Savitz --- test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.sh b/test.sh index f263568d..db955bab 100755 --- a/test.sh +++ b/test.sh @@ -165,7 +165,12 @@ orbit/warpdrive.sh \ | tee test/delete_user \ | grep "user" +# Check for shell script styyle compliance with shellcheck +shellcheck test.sh +shellcheck orbit/test-style.sh + # Check python style compliance with flake8 pushd orbit ./test-style.sh popd + From 9e32ca953cfa5ff134425719740fd393573b71de Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 26 Mar 2024 18:16:59 -0400 Subject: [PATCH 14/14] test: create abstraction for command requirements checking Signed-off-by: Joel Savitz --- test.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test.sh b/test.sh index db955bab..8ed9ed5c 100755 --- a/test.sh +++ b/test.sh @@ -10,10 +10,12 @@ # of the furthest right failing command or zero if no command failed (o pipefail) set -exuo pipefail -command -v curl || { echo "error: curl command required yet absent" ; exit 1 ; } -command -v flake8 || { echo "error: flake8 command required yet absent" ; exit 1 ; } -command -v chcon || { echo "error: chcon command required yet absent" ; exit 1 ; } -command -v podman || { echo "error: podman command required yet absent" ; exit 1 ; } +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 sudo rm -rf test email/logs/* email/mail/*