tomb

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

setup (3315B)


      1 #!/usr/bin/env zsh
      2 #
      3 # Copyright (C) 2007-2016 Dyne.org Foundation
      4 #
      5 # Tomb test units by Denis Roio <jaromil@dyne.org>
      6 #
      7 # This source code is free software; you can redistribute it and/or
      8 # modify it under the terms of the GNU Public License as published by
      9 # the Free Software Foundation; either version 3 of the License, or
     10 # (at your option) any later version.
     11 #
     12 # This source code is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Please refer
     15 # to the GNU Public License for more details.
     16 #
     17 # You should have received a copy of the GNU Public License along with
     18 # this source code; if not, write to: Free Software Foundation, Inc.,
     19 # 675 Mass Ave, Cambridge, MA 02139, USA.
     20 #
     21 
     22 #
     23 # This file should be sourced by all test-scripts
     24 #
     25 
     26 # Project directory
     27 TEST_HOME="$(pwd)"
     28 EXT_HOME="$(dirname "$TEST_HOME")"
     29 PROJECT_HOME="$(dirname "$EXT_HOME")"
     30 
     31 
     32 # Sharness config
     33 export SHARNESS_TEST_EXTENSION="sh"
     34 source ./sharness
     35 TMP="/tmp/tomb"
     36 
     37 
     38 # Check Tomb sources
     39 T="$PROJECT_HOME/tomb" 	# Can link to old tomb version
     40 TOMB_BIN="${T}"			# Always to the dev version
     41 if [[ ! -e "${T}" ]]; then
     42 	echo "Could not find tomb command"
     43 	exit 1
     44 fi
     45 
     46 MEDIA="/media"
     47 [[ -d "/media" ]] || MEDIA="/run/media/$USER"
     48 
     49 # Check for auxiliary programs
     50 command -v steghide > /dev/null && test_set_prereq STEGHIDE
     51 command -v e2fsck resize2fs > /dev/null && test_set_prereq RESIZER
     52 command -v tomb-kdb-pbkdf2 > /dev/null && test_set_prereq KDF
     53 command -v qrencode > /dev/null && test_set_prereq QRENCODE
     54 command -v lsof > /dev/null && test_set_prereq LSOF
     55 
     56 
     57 # GnuPG config
     58 unset GNUPGHOME
     59 unset GPG_AGENT_INFO
     60 export GNUPGHOME="$TEST_HOME/gnupg/"
     61 export KEY1="A4857CD176B31435F9709D25F0E573B8289439CD"
     62 export KEY2="0B2235E660753AB0475FB3E23DC836481F44B31E"
     63 chmod 700 "$GNUPGHOME"
     64 
     65 
     66 # Dummy passwords used in the tests suite
     67 export DUMMYPASS=test
     68 export DUMMYPASSNEW=changetest
     69 
     70 
     71 # Test helpers
     72 
     73 test_cleanup() {
     74 	"${T}" slam all &> /dev/null
     75 	rm -f "/home/$USER/dyne-tomb-bind-test-"*
     76 	sudo rm -rf "$TMP"
     77 	mkdir -p "$TMP"
     78 }
     79 
     80 test_export() {
     81 	export testname="$1"
     82 	export tomb="$TMP/$testname.tomb"
     83 	export tomb_key="$TMP/$testname.tomb.key"
     84 	export tomb_key_new="$TMP/$testname.new.tomb.key"
     85 	export tomb_key_steg="$TMP/$testname.steg.tomb.key"
     86 	export tomb_img="$TMP/$testname.jpg"
     87 }
     88 
     89 tt() {
     90 	start_loops=(`sudo losetup -a |cut -d: -f1`)
     91 	start_temps=(`find /dev/shm -name 'tomb*'`)
     92 	"${T}" -D ${=@}
     93 	res=$?
     94 	loops=(`sudo losetup -a |cut -d: -f1`)
     95 	temps=(`find /dev/shm -name 'tomb*'`)
     96 
     97 	{ test "${#start_loops}" = "${#loops}" } || {
     98 	    print "loop device usage change to ${#loops}" }
     99 	{ test "${#start_temps}" = "${#temps}" } || {
    100 	    print "temp files usage change to ${#temps}" }
    101 	print "     Tomb command returns $res"
    102 	return $res
    103 }
    104 
    105 tt_dig() { tt dig "$tomb" "${@}"; }
    106 tt_forge() { tt forge "$tomb_key" --ignore-swap --unsafe --use-urandom "${@}"; }
    107 tt_lock() { tt lock "$tomb" -k "$tomb_key" --ignore-swap --unsafe "${@}"; }
    108 tt_open() { tt open "$tomb" -k "$tomb_key" --ignore-swap --unsafe "${@}"; }
    109 tt_close() { tt close "$testname" "${@}"; }
    110 
    111 tt_set_ownership() {
    112 	local dir="$1"
    113 	local uid=$(id -u $USERNAME)
    114 	local gid=$(id -g $USERNAME)
    115 	sudo chown -R "$uid:$gid" "$dir"
    116 	sudo chmod 0711 "$dir"
    117 }