tomb

the crypto undertaker
git clone git://parazyd.org/tomb.git
Log | Files | Refs | README | LICENSE

commit 4d6c0bf5cc0502357bfe59c7282a73662909a172
parent bc3177141d93e0d87ebd3a144f32b5c64acd7407
Author: Jaromil <jaromil@dyne.org>
Date:   Wed, 12 Jun 2013 11:12:33 +0200

Cleaner test environment

now available as 'make test'

Diffstat:
MMakefile | 3+++
Aextras/test/Makefile | 2++
Dextras/test/dig_forge_lock_open_close.sh | 46----------------------------------------------
Aextras/test/runtests | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 129 insertions(+), 46 deletions(-)

diff --git a/Makefile b/Makefile @@ -9,3 +9,6 @@ all: install: @install -Dm755 ${PROG} ${DESTDIR}${PREFIX}/bin/${PROG} @install -Dm666 doc/${PROG}.1 ${DESTDIR}${MANDIR}/man1/${PROG}.1 + +test: + make -C extras/test diff --git a/extras/test/Makefile b/extras/test/Makefile @@ -0,0 +1,2 @@ +all: + @./runtests diff --git a/extras/test/dig_forge_lock_open_close.sh b/extras/test/dig_forge_lock_open_close.sh @@ -1,46 +0,0 @@ -#!/usr/bin/zsh - -T="../../tomb" -source utils.sh -source ${T} source - -notice() { print; yes "${@}"; print; } -error() { _warning " ${@}"; } -tt() { - start_loops=(`sudo losetup -a |cut -d: -f1`) - ${T} ${=@} - res=$? - loops=(`sudo losetup -a |cut -d: -f1`) - { test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" } - print " Tomb command returns $res" - return $res -} - - - -rm /tmp/test.tomb{,.key} -f || exit 1 - -notice "Testing creation" - -tt dig -s 10 /tmp/test.tomb - -tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key - - -tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key - -# sanity_tomb /tmp/asd.tomb -notice "Testing open with wrong password" - -tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb - -notice "Testing open with good password" - -tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb - -tt --unsecure-dev-mode close test - -notice "Testing resize to 20MiB" -tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 20 - -# rm /tmp/test.tomb{,.key} -f || exit 1 diff --git a/extras/test/runtests b/extras/test/runtests @@ -0,0 +1,124 @@ +#!/usr/bin/zsh +# +# Iterates through various tests on the tomb script + +T="../../tomb" +source ${T} source + +notice() { print; yes "${@}"; print; } +error() { _warning " ${@}"; } +tt() { + start_loops=(`sudo losetup -a |cut -d: -f1`) + ${T} ${=@} + res=$? + loops=(`sudo losetup -a |cut -d: -f1`) + { test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" } + print " Tomb command returns $res" + return $res +} + +typeset -A results +tests=(dig forge lock badpass open close resize chksum bind) + + +rm /tmp/test.tomb{,.key} -f || exit 1 + +startloops=(`sudo losetup -a |cut -d: -f1`) + + + + +notice "Testing creation" + +tt dig -s 20 /tmp/test.tomb + +{ test $? = 0 } && { results+=(dig SUCCESS) } + +tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key + +{ test $? = 0 } && { results+=(forge SUCCESS) } + +tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key + +{ test $? = 0 } && { results+=(lock SUCCESS) } + + + +notice "Testing open with wrong password" + +tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb + +{ test $? = 0 } || { results+=(badpass SUCCESS) } + + + +notice "Testing open with good password" + +tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb + +{ test $? = 0 } && { results+=(open SUCCESS) } + + + +notice "Generating content for file integrity test" + +${T} dig -s 10 /media/test.tomb/datacheck.raw + +crc="sha256 /media/test.tomb/datacheck.raw" +echo "$crc" > /media/test.tomb/datacheck.sha + +tt --unsecure-dev-mode close test + +{ test $? = 0 } && { results+=(close SUCCESS) } + + + +notice "Testing resize to 30 MiB" + +tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 30 + +{ test $? = 0 } && { results+=(resize SUCCESS) } + +${T} --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb + +crc2="sha256 /media/test.tomb/datacheck.raw" + +{ test "$crc" = "$crc2" } && { results+=(chksum SUCCESS) } + + + +notice "Testing bind hooks" + +rnd=$RANDOM +echo $rnd > /media/test.tomb/test-$rnd +echo "test-$rnd test-$rnd" > /media/test.tomb/bind-hooks +touch $HOME/test-$rnd +tt close test +tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb +rnd2=`cat $HOME/test-$rnd` +if [ "$rnd" = "$rnd2" ]; then + notice "Bind hook on file matches" + results+=(bind SUCCESS) + tt list test +else + error "Bind hook on file reports incongruence" +fi +sudo umount $HOME/test-$rnd +rm /media/test.tomb/bind-hooks +rm /media/test.tomb/test-$rnd +tt close test + +# rm /tmp/test.tomb{,.key} -f || exit 1 + +endloops=(`sudo losetup -a |cut -d: -f1`) + +notice "Test results summary" + +print "${#startloops} loop devices busy at start" + +for t in $tests; do + echo "$t\t${results[$t]:-FAIL}" +done + +print "${#endloops} loop devices busy at end" +