Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ RUN dnf update -y && \
python-flake8 \
python-virtualenv \
python-pip \
git
gawk \
socat \
git \
git-email

# needed because for some reason newuidmap and newgidmap programs
# lose their xattrs giving them caps when the container image for
Expand Down
4 changes: 2 additions & 2 deletions git/admin.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -e

DOCKER_COMPOSE=${DOCKER_COMPOSE:-podman-compose}
PODMAN_COMPOSE=${PODMAN_COMPOSE:-podman-compose}

$DOCKER_COMPOSE exec git ./create-repo.sh "$@"
$PODMAN_COMPOSE exec git ./create-repo.sh "$@"
4 changes: 2 additions & 2 deletions orbit/warpdrive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

set -e

DOCKER_COMPOSE=${DOCKER_COMPOSE:-podman-compose}
PODMAN_COMPOSE=${PODMAN_COMPOSE:-podman-compose}

$DOCKER_COMPOSE exec orbit ./hyperspace.py "$@"
$PODMAN_COMPOSE exec orbit ./hyperspace.py "$@"
9 changes: 7 additions & 2 deletions script-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ require shellcheck

set -ex

# -x needed to make shellcheck follow `source` command
shellcheck script-lint.sh
shellcheck test.sh
shellcheck -x test.sh
shellcheck -x test-sub.sh
shellcheck -x test-sub-check.sh
shellcheck -x test-sub2.sh
shellcheck -x test-sub3.sh
shellcheck -x test-sub4.sh
shellcheck orbit/warpdrive.sh
shellcheck denis/configure.sh
shellcheck mailman/inspector.sh
Expand All @@ -16,6 +22,5 @@ shellcheck git/setup-repo.sh
shellcheck git/cgi-bin/git-receive-pack
shellcheck git/hooks/post-update

# -x needed to make shellcheck follow `source` command
shellcheck -x backup/backup.sh
shellcheck -x backup/restore.sh
21 changes: 21 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ podman-compose logs -f submatrix 2>&1 | sed '/Synapse now listening on TCP port
if [ -f test.sh ]
then
./test.sh
if [ -f test-sub.sh ]
then
podman-compose down -v
podman-compose up -d
podman-compose logs -f submatrix 2>&1 | sed '/Synapse now listening on TCP port 8008/ q'
./dev_sockets.sh &
git config --global user.name PINP
git config --global user.email podman@podman
./test-sub.sh
./test-sub-check.sh
podman-compose down -v
podman-compose up -d
./test-sub2.sh
podman-compose down -v
podman-compose up -d
./test-sub3.sh
podman-compose down -v
podman-compose up -d
./test-sub4.sh

fi
else
virtualenv .
pip install -r requirements.txt
Expand Down
195 changes: 195 additions & 0 deletions test-lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# 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

PODMAN=${PODMAN:-podman}
PODMAN_COMPOSE=${PODMAN_COMPOSE:-podman-compose}
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
WORKDIR=$(mktemp -d)

HOSTNAME_FROM_DOTENV="$(sh -c '
set -o allexport
. ./.env
exec jq -r -n "env.SINGULARITY_HOSTNAME"
')"

SINGULARITY_HOSTNAME=${SINGULARITY_HOSTNAME:-"${HOSTNAME_FROM_DOTENV}"}

setup_testdir() {
# Create test dir if it does not exist yet
mkdir -p test

# Reset the test directory
rm -f test/*

# put the cert in there
${PODMAN} cp singularity_nginx_1:/etc/ssl/nginx/fullchain.pem test/ca_cert.pem
}

CURL_OPTS=( \
--verbose \
--cacert test/ca_cert.pem \
--fail \
--no-progress-meter \
)


get_git_port() { ${PODMAN} port singularity_git_1 | awk -F':' '{ print $2 }' ; } ;

# preconditions:
# - SCRIPT_DIR defined (singularity repo root)
# - WORKDIR defined (arbitrary) temp directory
setup_submissions_and_grading_repo() {
pushd "$SCRIPT_DIR"
# nuke grading repo inside container
# shellcheck disable=SC2016
${PODMAN_COMPOSE} exec git ash -c 'cd /var/lib/git/grading.git && for t in $(git tag); do git tag -d $t; done'
# crete and push fresh submissions repo
rm -rf repos/submissions
git/admin.sh submissions "course submissions repository"
pushd repos
git init --bare submissions
echo "course submissions repository" > submissions/description
# create a temporary workdir to push an initial commit to the submission repo
git init submissions_init
pushd submissions_init
echo "# submissions" > README.md
git add README.md
git status
git -c user.name=singularity -c user.email=singularity@singularity commit -sm 'init submissions repo'
git push ../submissions master
popd
rm -rf submissions_init
pushd submissions
git push --mirror http://localhost:"$(get_git_port)"/cgi-bin/git-receive-pack/submissions
popd
popd
popd

pushd "$WORKDIR"
mkdir certs
pushd certs
${PODMAN} volume export singularity_ssl-certs > certs.tar
tar xf certs.tar
popd
git clone http://localhost:"$(get_git_port)"/submissions
popd
}

create_lighting_assignment() {
test -n "$1"
test -n "$2"
test -n "$3"
test -n "$4"

local asn="$1"
local i_s="$2"
local p_s="$3"
local f_s="$4"
set +u
local rub="$5"
set -u

RUBRIC=
if [ -n "$rub" ]
then
RUBRIC="-r $rub"
fi

pushd "$SCRIPT_DIR"
# create or recreate setup assignment
if denis/configure.sh dump | grep -q "^$asn:"; then
denis/configure.sh remove -a "$asn"
fi
denis/configure.sh create -a "$asn" -i "$(date -d "$i_s secs" +%s)" -p "$(date -d "$p_s secs" +%s)" -f "$(date -d "$f_s secs" +%s)" ${RUBRIC}
denis/configure.sh reload
popd
}

# preconditions:
# - called after setup_submissions_and_grading_repo
setup_submissions_for() {
test -n "$1"
local user="$1"

pushd "$SCRIPT_DIR"
orbit/warpdrive.sh -u "$user" -p builder -n || orbit/warpdrive.sh -u "$user" -p builder -m
popd

pushd "$WORKDIR"/submissions
git config user.name "$user"
git config user.email "$user"@localhost.localdomain
git config sendemail.smtpUser "$user"
git config sendemail.smtpPass builder
git config sendemail.smtpserver localhost.localdomain
git config sendemail.smtpserverport 1465
git config sendemail.smtpencryption ssl
popd
}

# preconditions:
# - no non-tracked files in submissions repo
# - called after setup_submissions_for
enter_and_checkout() {
test -n "$1"
local branch="$1"

pushd "$WORKDIR"/submissions
git checkout --orphan "$1"
if [ -n "$(ls)" ]
then
git rm -rf ./*
fi
}

# preconditions:
# - called after a call to enter_and_checkout
exit_after_sending() {
test -n "$1"
local asn="$1"

git send-email \
--confirm=never \
--smtp-ssl-cert-path="$WORKDIR"/certs/fullchain.pem \
--to "$asn"@localhost.localdomain \
./*.patch
rm ./*.patch
popd
sleep 1
}

# preconditions:
# - called after a call to enter_and_checkout
write_commit_to() {
test -n "$1" && test -n "$2"
local content="$1"
local file="$2"
set +u # necessary since $3 is unbound in 2 arg case
local opt="$3"
set -x

mkdir -p $(dirname "$file")

if [ "$opt" == "append" ]; then
echo "$content" >> "$file"
else
echo "$content" > "$file"
fi

git add "$file"
git commit -sm "add $content to $file"
}

# preconditions:
# - called after a call to write_commit_to
fixup_cover() {
test -n "$1"
sed -i "s/\*\*\* SUBJECT HERE \*\*\*/$1/g" *0000-cover-letter.patch
sed -i "s/\*\*\* BLURB HERE \*\*\*/$1/g" *0000-cover-letter.patch
sed -i "\$a\\Signed-off-by: $(git config user.name) <$(git config user.email)>" *0000-cover-letter.patch
}

95 changes: 95 additions & 0 deletions test-sub-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash

source test-lib

setup_testdir

# login as bob
curl --url "https://$SINGULARITY_HOSTNAME/login" \
--unix-socket ./socks/https.sock \
"${CURL_OPTS[@]}" \
-c test/cookies \
--data "username=bob&password=builder" \
| tee test/login_success \
| grep "msg = bob authenticated by password"


# check for setup assignment and save dashboard
curl --url "https://$SINGULARITY_HOSTNAME/dashboard" \
--unix-socket ./socks/https.sock \
-b test/cookies \
"${CURL_OPTS[@]}" \
| tee test/dashboard \
| grep "setup"

grep "Total Score: 64.9" test/dashboard

grep "missing cover letter and first patch failed to apply!" test/dashboard

grep "bib Peer Review" test/dashboard

grep "bab Peer Review" test/dashboard

grep "patchset applies." test/dashboard

grep "Good effort but try harder next time." test/dashboard

# login as bab
curl --url "https://$SINGULARITY_HOSTNAME/login" \
--unix-socket ./socks/https.sock \
"${CURL_OPTS[@]}" \
-c test/cookies_bab \
--data "username=bab&password=builder" \
| tee test/login_success_bab \
| grep "msg = bab authenticated by password"


# check for setup assignment and save dashboard
curl --url "https://$SINGULARITY_HOSTNAME/dashboard" \
--unix-socket ./socks/https.sock \
-b test/cookies_bab \
"${CURL_OPTS[@]}" \
| tee test/dashboard_bab \
| grep "setup"

grep "Total Score: 0.0" test/dashboard_bab

grep "bib Peer Review" test/dashboard_bab

grep "bob Peer Review" test/dashboard_bab

grep "patchset applies." test/dashboard_bab

grep "illegal patch 1: permission denied for path work!" test/dashboard_bab

grep 'Please review git' test/dashboard_bab

# login as bib
curl --url "https://$SINGULARITY_HOSTNAME/login" \
--unix-socket ./socks/https.sock \
"${CURL_OPTS[@]}" \
-c test/cookies_bib \
--data "username=bib&password=builder" \
| tee test/login_success_bib \
| grep "msg = bib authenticated by password"


# check for setup assignment and save dashboard
curl --url "https://$SINGULARITY_HOSTNAME/dashboard" \
--unix-socket ./socks/https.sock \
-b test/cookies_bib \
"${CURL_OPTS[@]}" \
| tee test/dashboard_bib \
| grep "setup"

grep "Total Score: 80.0" test/dashboard_bib

grep "bob Peer Review" test/dashboard_bib

grep "bab Peer Review" test/dashboard_bib

grep "patchset applies." test/dashboard_bib

grep 'Perfect. But no peer review!' test/dashboard_bib

echo "ALL SUBMISSION TESTS PASS"
Loading