2017-05-01 20:08:08 +00:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007-2016 Dyne.org Foundation
|
|
|
|
#
|
|
|
|
# Tomb test units by Denis Roio <jaromil@dyne.org>
|
|
|
|
#
|
|
|
|
# This source code is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This source code is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
|
|
|
|
# to the GNU Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Public License along with
|
|
|
|
# this source code; if not, write to: Free Software Foundation, Inc.,
|
|
|
|
# 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file should be sourced by all test-scripts
|
|
|
|
#
|
|
|
|
|
|
|
|
# Project directory
|
|
|
|
TEST_HOME="$(pwd)"
|
|
|
|
EXT_HOME="$(dirname "$TEST_HOME")"
|
|
|
|
PROJECT_HOME="$(dirname "$EXT_HOME")"
|
|
|
|
|
|
|
|
|
|
|
|
# Sharness config
|
|
|
|
export SHARNESS_TEST_EXTENSION="sh"
|
|
|
|
source ./sharness
|
|
|
|
TMP="/tmp/tomb"
|
|
|
|
|
|
|
|
|
|
|
|
# Check Tomb sources
|
|
|
|
T="$PROJECT_HOME/tomb" # Can link to old tomb version
|
|
|
|
TOMB_BIN="${T}" # Always to the dev version
|
|
|
|
if [[ ! -e "${T}" ]]; then
|
|
|
|
echo "Could not find tomb command"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-05-01 22:26:17 +00:00
|
|
|
MEDIA="/media"
|
2017-05-03 18:51:36 +00:00
|
|
|
[[ -d "/media" ]] || MEDIA="/run/media/$USER"
|
2017-05-01 22:26:17 +00:00
|
|
|
|
2017-05-01 20:08:08 +00:00
|
|
|
# Check for auxiliary programs
|
|
|
|
command -v steghide > /dev/null && test_set_prereq STEGHIDE
|
|
|
|
command -v e2fsck resize2fs > /dev/null && test_set_prereq RESIZER
|
|
|
|
command -v tomb-kdb-pbkdf2 > /dev/null && test_set_prereq KDF
|
|
|
|
command -v qrencode > /dev/null && test_set_prereq QRENCODE
|
2017-05-12 18:24:49 +00:00
|
|
|
command -v lsof > /dev/null && test_set_prereq LSOF
|
2019-02-21 09:28:21 +00:00
|
|
|
command -v python2 > /dev/null && test_set_prereq PYTHON2
|
|
|
|
command -v cloakify > /dev/null && test_set_prereq CLOAKIFY
|
|
|
|
command -v decloakify > /dev/null && test_set_prereq DECLOAKIFY
|
2019-03-03 16:56:26 +00:00
|
|
|
command -v sphinx > /dev/null && test_set_prereq SPHINX
|
|
|
|
command -v oracle > /dev/null && test_set_prereq ORACLE
|
2021-04-07 17:20:12 +00:00
|
|
|
command -v doas > /dev/null && test_set_prereq DOAS
|
2017-05-01 20:08:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
# GnuPG config
|
|
|
|
unset GNUPGHOME
|
|
|
|
unset GPG_AGENT_INFO
|
|
|
|
export GNUPGHOME="$TEST_HOME/gnupg/"
|
|
|
|
export KEY1="A4857CD176B31435F9709D25F0E573B8289439CD"
|
|
|
|
export KEY2="0B2235E660753AB0475FB3E23DC836481F44B31E"
|
2018-08-19 21:53:21 +00:00
|
|
|
export SUBKEY1="D89BE71A935779961C130E50D9D7ACED39D3991C!"
|
|
|
|
export SUBKEY2="843077BF7FD4A9C7BBFC3A69F065568B4F7D6CA9!"
|
2019-06-27 18:54:46 +00:00
|
|
|
export KEY_UNTRUSTED="E6195F61F5EBA81FE4B1565AAC844B92004240CD"
|
2018-08-19 21:53:21 +00:00
|
|
|
|
2017-05-01 20:08:08 +00:00
|
|
|
chmod 700 "$GNUPGHOME"
|
|
|
|
|
|
|
|
|
|
|
|
# Dummy passwords used in the tests suite
|
|
|
|
export DUMMYPASS=test
|
|
|
|
export DUMMYPASSNEW=changetest
|
|
|
|
|
2019-03-03 16:56:26 +00:00
|
|
|
# Dummy host and username for sphinx
|
|
|
|
export DUMMYHOST=example.com
|
|
|
|
export DUMMYUSER=user
|
|
|
|
|
2017-05-01 20:08:08 +00:00
|
|
|
|
|
|
|
# Test helpers
|
|
|
|
|
|
|
|
test_cleanup() {
|
|
|
|
"${T}" slam all &> /dev/null
|
|
|
|
sudo rm -rf "$TMP"
|
|
|
|
mkdir -p "$TMP"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_export() {
|
|
|
|
export testname="$1"
|
|
|
|
export tomb="$TMP/$testname.tomb"
|
|
|
|
export tomb_key="$TMP/$testname.tomb.key"
|
|
|
|
export tomb_key_new="$TMP/$testname.new.tomb.key"
|
|
|
|
export tomb_key_steg="$TMP/$testname.steg.tomb.key"
|
|
|
|
export tomb_img="$TMP/$testname.jpg"
|
2019-02-21 09:28:21 +00:00
|
|
|
export tomb_text="$TMP/$testname.txt"
|
|
|
|
export tomb_key_cloak="$TMP/$testname.cloak.tomb.key"
|
2017-05-01 20:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tt() {
|
|
|
|
start_loops=(`sudo losetup -a |cut -d: -f1`)
|
|
|
|
start_temps=(`find /dev/shm -name 'tomb*'`)
|
|
|
|
"${T}" -D ${=@}
|
|
|
|
res=$?
|
|
|
|
loops=(`sudo losetup -a |cut -d: -f1`)
|
|
|
|
temps=(`find /dev/shm -name 'tomb*'`)
|
|
|
|
|
|
|
|
{ test "${#start_loops}" = "${#loops}" } || {
|
|
|
|
print "loop device usage change to ${#loops}" }
|
|
|
|
{ test "${#start_temps}" = "${#temps}" } || {
|
|
|
|
print "temp files usage change to ${#temps}" }
|
|
|
|
print " Tomb command returns $res"
|
|
|
|
return $res
|
|
|
|
}
|
|
|
|
|
|
|
|
tt_dig() { tt dig "$tomb" "${@}"; }
|
2019-05-22 07:55:02 +00:00
|
|
|
tt_forge() { tt forge "$tomb_key" --ignore-swap --unsafe "${@}"; }
|
2017-05-01 20:08:08 +00:00
|
|
|
tt_lock() { tt lock "$tomb" -k "$tomb_key" --ignore-swap --unsafe "${@}"; }
|
|
|
|
tt_open() { tt open "$tomb" -k "$tomb_key" --ignore-swap --unsafe "${@}"; }
|
|
|
|
tt_close() { tt close "$testname" "${@}"; }
|
2017-05-01 22:02:49 +00:00
|
|
|
|
2017-05-03 18:51:36 +00:00
|
|
|
tt_set_ownership() {
|
2017-05-01 22:02:49 +00:00
|
|
|
local dir="$1"
|
|
|
|
local uid=$(id -u $USERNAME)
|
|
|
|
local gid=$(id -g $USERNAME)
|
|
|
|
sudo chown -R "$uid:$gid" "$dir"
|
|
|
|
sudo chmod 0711 "$dir"
|
|
|
|
}
|