@ -13,7 +13,10 @@ FIXTURES_DIR="$BATS_TEST_DIRNAME/fixtures"
TEST_GPG_HOMEDIR = " $BATS_TMPDIR "
TEST_GPG_OUTPUT_FILE = $( TMPDIR = " $BATS_TMPDIR " mktemp -t '_git_secret_test_output_XXX' )
# TODO: factor out tempdir creation. On osx TEST_GPG_OUTPUT_FILE, still has 'XXXXXX's, like
# /var/folders/mm/_f0j67x10l92b4zznyx4ylzh00017w/T/gitsecret_output.XXXXXX.RaqyGYqL
TEST_GPG_OUTPUT_FILE = $( TMPDIR = " $BATS_TMPDIR " mktemp -t 'gitsecret_output.XXXXXX' )
#echo "# TEST_GPG_OUTPUT_FILE=$TEST_GPG_OUTPUT_FILE" >&3
# shellcheck disable=SC2016
AWK_GPG_GET_FP = '
@ -103,7 +106,7 @@ function install_fixture_key {
cp " $FIXTURES_DIR /gpg/ ${ 1 } /public.key " " $public_key "
$GPGTEST --import " $public_key " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
rm -f " $public_key "
rm -f " $public_key " || _abort " Couldn't delete public key: $public_key "
}
@ -127,7 +130,7 @@ function install_fixture_full_key {
install_fixture_key " $1 "
rm -f " $private_key "
rm -f " $private_key " || _abort " Couldn't delete private key: $private_key "
# return fingerprint to delete it later:
echo " $fingerprint "
}
@ -273,11 +276,26 @@ function unset_current_state {
rm " $TEST_GPG_OUTPUT_FILE "
# removes gpg homedir:
find " $TEST_GPG_HOMEDIR " \
-regex ".*\/random_seed\|.*\.gpg\|.*\.kbx.?\|.*private-keys.*\|.*test_sub_dir\|.*S.gpg-agent\|.*file_to_hide.*" \
-exec rm -rf { } +
## old code to remove tmp gpg homedir: TODO: remove.
#find "$TEST_GPG_HOMEDIR" \
# -regex ".*\/random_seed\|.*\.gpg\|.*\.kbx.?\|.*private-keys.*\|.*test_sub_dir\|.*S.gpg-agent\|.*file_to_hide.*" \
# -exec rm -rf {} +
# new code to remove temporary gpg homedir artifacts.
# For #360, 'find and rm only relevant files when test fails'.
# ${VAR:?} will cause command to fail if VAR is 0 length, as per shellcheck SC2115
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } /private-keys* " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } /*.kbx " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } /*.kbx~ " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } /*.gpg " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } / ${ TEST_DEFAULT_FILENAME } " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } / ${ TEST_SECOND_FILENAME } " 2>& 1 | sed 's/^/# unset_current_state: rm /'
rm -vrf " ${ TEST_GPG_HOMEDIR : ? } / ${ TEST_THIRD_FILENAME } " 2>& 1 | sed 's/^/# unset_current_state: rm /'
# return to the base dir:
cd " $SECRET_PROJECT_ROOT " || exit 1
}
# show output if we wind up manually removing the test output file in a trap
trap 'if [[ -f "$TEST_GPG_OUTPUT_FILE" ]]; then if [[ -n "$SECRETS_TEST_VERBOSE" ]]; then echo "git-secret: test: cleaning up: $TEST_GPG_OUTPUT_FILE"; fi; rm -f "$TEST_GPG_OUTPUT_FILE"; fi;' EXIT