summaryrefslogtreecommitdiff
path: root/tests/setup.sh
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-04-23 06:08:46 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2014-04-23 06:08:46 +0200
commit292d7259fea98db3fb9ba4c9db2cd96639f754fe (patch)
treec27a7b36b10519c818da9d67fd3428506d684e31 /tests/setup.sh
parent5d48eae5c3c8155a4f12ba443bec03deeb687c73 (diff)
downloadpass-292d7259fea98db3fb9ba4c9db2cd96639f754fe.tar.gz
pass-292d7259fea98db3fb9ba4c9db2cd96639f754fe.tar.bz2
pass-292d7259fea98db3fb9ba4c9db2cd96639f754fe.zip
tests: make variables sane
Diffstat (limited to '')
-rwxr-xr-xtests/setup.sh75
1 files changed, 32 insertions, 43 deletions
diff --git a/tests/setup.sh b/tests/setup.sh
index 930ec99..130589d 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -1,21 +1,20 @@
# This file should be sourced by all test-scripts
#
# This scripts sets the following:
-# $GNUPGHOME Full path to test GPG directory
-# $PASS Full path to password-store script to test
-# $GPG Name of gpg executable
-# $PASSWORD_STORE_KEY{1..5} GPG key ids of testing keys
-# $PASSWORD_STORE_TEST_HOME This folder
+# $PASS Full path to password-store script to test
+# $GPG Name of gpg executable
+# $KEY{1..5} GPG key ids of testing keys
+# $TEST_HOME This folder
#
# Constants
-PASSWORD_STORE_TEST_HOME="$(cd "$(dirname "$BASH_SOURCE")"; pwd)"
+TEST_HOME="$(cd "$(dirname "$BASH_SOURCE")"; pwd)"
#
# Find the pass script
-PASS="${PASSWORD_STORE_TEST_HOME}/../src/password-store.sh"
+PASS="$TEST_HOME/../src/password-store.sh"
if [[ ! -e $PASS ]]; then
echo "Could not find password-store.sh"
@@ -27,7 +26,7 @@ fi
# Where the test keyring and test key id
# Note: the assumption is the test key is unencrypted.
-export GNUPGHOME="${PASSWORD_STORE_TEST_HOME}/gnupg/"
+export GNUPGHOME="$TEST_HOME/gnupg/"
chmod 700 "$GNUPGHOME"
GPG="gpg"
which gpg2 &>/dev/null && GPG="gpg2"
@@ -37,11 +36,11 @@ which gpg2 &>/dev/null && GPG="gpg2"
# We don't need a real agent. Hence:
export GPG_AGENT_INFO=" "
-export PASSWORD_STORE_KEY1="CF90C77B" # pass test key 1
-export PASSWORD_STORE_KEY2="D774A374" # pass test key 2
-export PASSWORD_STORE_KEY3="EB7D54A8" # pass test key 3
-export PASSWORD_STORE_KEY4="E4691410" # pass test key 4
-export PASSWORD_STORE_KEY5="39E5020C" # pass test key 5
+KEY1="CF90C77B" # pass test key 1
+KEY2="D774A374" # pass test key 2
+KEY3="EB7D54A8" # pass test key 3
+KEY4="E4691410" # pass test key 4
+KEY5="39E5020C" # pass test key 5
# pass_init()
#
@@ -50,21 +49,18 @@ export PASSWORD_STORE_KEY5="39E5020C" # pass test key 5
# Arguments: None
# Returns: Nothing, sets PASSWORD_STORE_DIR
pass_init() {
- export PASSWORD_STORE_DIR="${SHARNESS_TRASH_DIRECTORY}/test-store/"
- echo "Initializing test password store (${PASSWORD_STORE_DIR}) with key ${PASSWORD_STORE_KEY1}"
-
- if [[ -d "${PASSWORD_STORE_DIR}" ]] ; then
- echo "Removing old store"
- rm -rf "${PASSWORD_STORE_DIR}"
- if [[ -d "${PASSWORD_STORE_DIR}" ]] ; then
- echo "Removal failed."
+ export PASSWORD_STORE_DIR="$SHARNESS_TRASH_DIRECTORY/test-store/"
+ echo "Initializing test password store ($PASSWORD_STORE_DIR) with key $KEY1"
+
+ if [[ -d $PASSWORD_STORE_DIR ]] ; then
+ rm -rf "$PASSWORD_STORE_DIR"
+ if [[ -d $PASSWORD_STORE_DIR ]] ; then
+ echo "Removal of old store failed."
return 1
fi
fi
- $PASS init ${PASSWORD_STORE_KEY1} || return 1
-
- echo "Initialization of ${PASSWORD_STORE_DIR} complete."
+ $PASS init $KEY1 || return 1
}
# check_cred()
@@ -80,14 +76,13 @@ check_cred() {
return 1
fi
local cred="$1"
- shift
- echo "Checking credential ${cred}"
+ echo "Checking credential $cred"
if ! $PASS show "$cred"; then
- echo "Credential ${cred} does not exist"
+ echo "Credential $cred does not exist"
return 1
fi
if [[ -z "$($PASS show "$cred")" ]]; then
- echo "Credential ${cred} empty"
+ echo "Credential $cred empty"
return 1
fi
}
@@ -105,10 +100,9 @@ check_no_cred() {
return 1
fi
local cred="$1"
- shift
- echo "Checking for lack of credential ${cred}"
+ echo "Checking for lack of credential $cred"
$PASS show "$cred" || return 0
- echo "Credential ${cred} exists."
+ echo "Credential $cred exists."
return 1
}
@@ -125,21 +119,19 @@ create_cred() {
return 1
fi
local cred="$1"
- shift
- echo "Creating credential ${cred}"
+ echo "Creating credential $cred"
if ! check_no_cred "$cred"; then
echo "Credential already exists"
return 1
fi
if [[ "$#" -eq 1 ]]; then
local password="$1"
- shift
echo "Using password \"$password\" for $cred"
$PASS insert -f -e "$cred" <<<"$password" || return 1
else
echo "Generating random password for $cred"
- if ! $PASS generate -f "${cred}" 24 > /dev/null; then
- echo "Failed to create credential ${cred}"
+ if ! $PASS generate -f "$cred" 24 > /dev/null; then
+ echo "Failed to create credential $cred"
return 1
fi
fi
@@ -157,14 +149,11 @@ verify_password() {
echo "$0: Bad arguments"
return 1
fi
- local cred="$1"
- shift
- local expected="$1"
- shift
- echo "Verifing credential ${cred} has password \"${expected}\""
+ local cred="$1" expected="$2"
+ echo "Verifing credential $cred has password \"$expected\""
check_cred "$cred" || return 1
- local actualfile="${SHARNESS_TRASH_DIRECTORY}/verify-password-actual.$RANDOM.$RANDOM.$RANDOM.$RANDOM"
- local expectedfile="${SHARNESS_TRASH_DIRECTORY}/verify-password-expected.$RANDOM.$RANDOM.$RANDOM.$RANDOM"
+ local actualfile="$SHARNESS_TRASH_DIRECTORY/verify-password-actual.$RANDOM.$RANDOM.$RANDOM.$RANDOM"
+ local expectedfile="$SHARNESS_TRASH_DIRECTORY/verify-password-expected.$RANDOM.$RANDOM.$RANDOM.$RANDOM"
$PASS show "$TEST_CRED" | sed -n 1p > "$actualfile" &&
echo "$expected" > "$expectedfile" &&
test_cmp "$expectedfile" "$actualfile"