2010-09-13 12:23:39 -06:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
die () {
|
2010-09-13 17:34:54 -06:00
|
|
|
echo "ERROR ERROR: $*"
|
2010-09-13 12:23:39 -06:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
CTF_BASE=/tmp/ctf-test.$$ export CTF_BASE
|
|
|
|
trap "rm -rf $CTF_BASE" 0
|
|
|
|
mkdir $CTF_BASE
|
|
|
|
|
|
|
|
# Some skeletal structure
|
|
|
|
mkdir -p $CTF_BASE/points.new
|
2010-09-23 23:27:14 -06:00
|
|
|
mkdir -p $CTF_BASE/points.tmp
|
2010-09-13 12:23:39 -06:00
|
|
|
|
|
|
|
# Set up some packages
|
|
|
|
for cat in cat1 cat2 cat3; do
|
2010-09-23 18:23:00 -06:00
|
|
|
mkdir -p $CTF_BASE/$cat
|
|
|
|
cat >$CTF_BASE/$cat/answers.txt <<EOF
|
2010-09-13 12:23:39 -06:00
|
|
|
10 ${cat}answer10
|
|
|
|
20 ${cat}answer20
|
|
|
|
30 ${cat}answer30
|
|
|
|
EOF
|
|
|
|
for i in 10 20 30; do
|
2010-09-23 18:23:00 -06:00
|
|
|
mkdir -p $CTF_BASE/$cat/puzzles/$i
|
2010-09-13 12:23:39 -06:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# Set up some teams
|
|
|
|
mkdir -p $CTF_BASE/teams/names
|
|
|
|
mkdir -p $CTF_BASE/teams/colors
|
|
|
|
for team in team1 team2 team3; do
|
2010-09-13 17:32:51 -06:00
|
|
|
hash=$(bin/register $team | awk '{print $NF;}')
|
2010-09-13 12:23:39 -06:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
## Puzzler tests
|
|
|
|
##
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzles.cgi | grep 20; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "20 points puzzles shouldn't show up here"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzler.cgi t=$hash c=cat1 p=10 a=cat1answer20 | grep -q 'awarded'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Awarded points with wrong answer"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzler.cgi t=$hash c=cat2 p=10 a=cat1answer10 | grep -q 'awarded'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Awarded points with wrong category"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzler.cgi t=$hash c=cat1 p=20 a=cat1answer10 | grep -q 'awarded'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Awarded points with wrong point value"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzler.cgi t=merfmerfmerfmerf c=cat2 p=10 a=cat1answer10 | grep -q 'awarded'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Awarded points with bad team"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if ! src/puzzler.cgi t=$hash c=cat1 p=10 a=cat1answer10 | grep -q 'awarded 10'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Didn't award points for correct answer"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if ! src/puzzles.cgi | grep -q 20; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "20 point answer didn't show up"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/puzzler.cgi t=$hash c=cat1 p=10 a=cat1answer10 | grep -q 'awarded 10'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Awarded same points twice"
|
|
|
|
fi
|
|
|
|
|
|
|
|
##
|
|
|
|
## Scoreboard tests
|
|
|
|
##
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if ! cat $CTF_BASE/points.new/* | bin/scoreboard | grep -q 'total.*team3: 1'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Scoreboard total incorrect"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if ! cat $CTF_BASE/points.new/* | bin/scoreboard | grep -q 'cat1.*team3: 10'; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "Scoreboard cat1 points incorrect"
|
|
|
|
fi
|
|
|
|
|
|
|
|
##
|
|
|
|
## Token tests
|
|
|
|
##
|
|
|
|
|
|
|
|
mkdir -p $CTF_BASE/token.keys
|
|
|
|
echo -n '0123456789abcdef' > $CTF_BASE/token.keys/tokencat
|
|
|
|
|
2010-09-18 21:56:57 -06:00
|
|
|
mkfifo $CTF_BASE/nancy
|
|
|
|
src/tokencli tokencat $CTF_BASE/token.keys/tokencat < $CTF_BASE/nancy 3>$CTF_BASE/t | src/in.tokend > $CTF_BASE/nancy
|
2010-09-13 12:23:39 -06:00
|
|
|
|
|
|
|
if ! grep -q 'tokencat:x....-....x' $CTF_BASE/tokens.db; then
|
|
|
|
die "in.tokend didn't write to database"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/claim.cgi t=lalalala k=$(cat $CTF_BASE/tokens.db) | grep -q success; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "claim.cgi gave points to a bogus team"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
if src/claim.cgi t=$hash k=tokencat:xanax-xanax | grep -q success; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "claim.cgi gave points for a bogus token"
|
|
|
|
fi
|
|
|
|
|
2010-09-18 21:56:57 -06:00
|
|
|
if ! src/claim.cgi t=$hash k=$(cat $CTF_BASE/t) | grep -q success; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "claim.cgi didn't give me any points"
|
|
|
|
fi
|
|
|
|
|
2010-09-18 21:56:57 -06:00
|
|
|
if src/claim.cgi t=$hash k=$(cat $CTF_BASE/t) | grep -q success; then
|
2010-09-13 12:23:39 -06:00
|
|
|
die "claim.cgi gave me points twice for the same token"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -f $CTF_BASE/points.new/*.$hash.tokencat.1 ]; then
|
|
|
|
die "claim.cgi didn't actually record any points"
|
|
|
|
fi
|
|
|
|
|
2010-09-13 17:32:51 -06:00
|
|
|
echo "All tests passed! You're the best programmer ever!"
|