diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/setup.sh | 75 | ||||
-rwxr-xr-x | tests/t0001-sanity-checks.sh | 4 | ||||
-rwxr-xr-x | tests/t0010-generate-tests.sh | 10 | ||||
-rwxr-xr-x | tests/t0020-show-tests.sh | 2 | ||||
-rwxr-xr-x | tests/t0050-mv-tests.sh | 12 | ||||
-rwxr-xr-x | tests/t0060-rm-tests.sh | 8 | ||||
-rwxr-xr-x | tests/t0100-insert-tests.sh | 4 | ||||
-rwxr-xr-x | tests/t0200-edit-tests.sh | 4 |
8 files changed, 54 insertions, 65 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" diff --git a/tests/t0001-sanity-checks.sh b/tests/t0001-sanity-checks.sh index c052533..989ca2f 100755 --- a/tests/t0001-sanity-checks.sh +++ b/tests/t0001-sanity-checks.sh @@ -9,8 +9,8 @@ test_expect_success 'Make sure we can run pass' ' test_expect_success 'Make sure we can initialize our test store' ' pass_init && - ls -ld "${PASSWORD_STORE_DIR}" && - [[ -d "${PASSWORD_STORE_DIR}" ]] + ls -ld "$PASSWORD_STORE_DIR" && + [[ -d "$PASSWORD_STORE_DIR" ]] ' test_done diff --git a/tests/t0010-generate-tests.sh b/tests/t0010-generate-tests.sh index 5f37397..71a7f68 100755 --- a/tests/t0010-generate-tests.sh +++ b/tests/t0010-generate-tests.sh @@ -3,14 +3,14 @@ test_description='Test generate' . ./setup.sh -export TEST_CRED="test_cred" -export TEST_CRED_LEN=24 +TEST_CRED="test_cred" +TEST_CRED_LEN=24 test_expect_success 'Test "generate" command' ' pass_init && - echo Generating credential "${TEST_CRED}" with length ${TEST_CRED_LEN} && - $PASS generate "${TEST_CRED}" ${TEST_CRED_LEN} && - check_cred "${TEST_CRED}" + echo Generating credential "$TEST_CRED" with length $TEST_CRED_LEN && + $PASS generate "$TEST_CRED" $TEST_CRED_LEN && + check_cred "$TEST_CRED" ' test_done diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh index 81ffb07..98108f5 100755 --- a/tests/t0020-show-tests.sh +++ b/tests/t0020-show-tests.sh @@ -3,7 +3,7 @@ test_description='Test show' . ./setup.sh -export TEST_CRED="test_cred" +TEST_CRED="test_cred" test_expect_success 'Test "show" command' ' pass_init && diff --git a/tests/t0050-mv-tests.sh b/tests/t0050-mv-tests.sh index d9d4b77..cbc1919 100755 --- a/tests/t0050-mv-tests.sh +++ b/tests/t0050-mv-tests.sh @@ -3,16 +3,16 @@ test_description='Test mv' . ./setup.sh -export TEST_CRED="test_cred" -export TEST_CRED_NEW="test_cred_new" +TEST_CRED="test_cred" +TEST_CRED_NEW="test_cred_new" test_expect_success 'Test "mv" command' ' pass_init && - create_cred "${TEST_CRED}" && + create_cred "$TEST_CRED" && echo "Moving $TEST_CRED to $TEST_CRED_NEW" && - $PASS mv "${TEST_CRED}" "${TEST_CRED_NEW}" && - check_cred "${TEST_CRED_NEW}" && - check_no_cred "${TEST_CRED}" + $PASS mv "$TEST_CRED" "$TEST_CRED_NEW" && + check_cred "$TEST_CRED_NEW" && + check_no_cred "$TEST_CRED" ' test_done diff --git a/tests/t0060-rm-tests.sh b/tests/t0060-rm-tests.sh index 126caa5..25c9e52 100755 --- a/tests/t0060-rm-tests.sh +++ b/tests/t0060-rm-tests.sh @@ -3,14 +3,14 @@ test_description='Test rm' . ./setup.sh -export TEST_CRED="test_cred" +TEST_CRED="test_cred" test_expect_success 'Test "rm" command' ' pass_init && - create_cred "${TEST_CRED}" && + create_cred "$TEST_CRED" && echo "Removing $TEST_CRED" && - echo "y" | $PASS rm "${TEST_CRED}" && - check_no_cred "${TEST_CRED}" + echo "y" | $PASS rm "$TEST_CRED" && + check_no_cred "$TEST_CRED" ' test_expect_success 'Test "rm" of non-existent password' ' diff --git a/tests/t0100-insert-tests.sh b/tests/t0100-insert-tests.sh index b83df32..7cc5d5f 100755 --- a/tests/t0100-insert-tests.sh +++ b/tests/t0100-insert-tests.sh @@ -3,8 +3,8 @@ test_description='Test insert' . ./setup.sh -export TEST_CRED="test_cred" -export TEST_PASSWORD="Hello world" +TEST_CRED="test_cred" +TEST_PASSWORD="Hello world" test_expect_success 'Test "insert" command' ' pass_init && diff --git a/tests/t0200-edit-tests.sh b/tests/t0200-edit-tests.sh index 44dc406..288446e 100755 --- a/tests/t0200-edit-tests.sh +++ b/tests/t0200-edit-tests.sh @@ -3,13 +3,13 @@ test_description='Test edit' . ./setup.sh -export TEST_CRED="test_cred" +TEST_CRED="test_cred" test_expect_success 'Test "edit" command' ' pass_init && create_cred "$TEST_CRED" && export FAKE_EDITOR_PASSWORD="big fat fake password" && - export EDITOR="$PASSWORD_STORE_TEST_HOME/fake-editor-change-password.sh" && + export EDITOR="$TEST_HOME/fake-editor-change-password.sh" && $PASS edit "$TEST_CRED" && verify_password "$TEST_CRED" "$FAKE_EDITOR_PASSWORD" ' |