@ -13,6 +13,8 @@ FIXTURES_DIR="$BATS_TEST_DIRNAME/fixtures"
TEST_GPG_HOMEDIR = " $BATS_TMPDIR "
TEST_GPG_OUTPUT_FILE = $( TMPDIR = " $BATS_TMP_DIR " mktemp -t '_git_secret_test_output_XXX' )
# shellcheck disable=SC2016
AWK_GPG_GET_FP = '
BEGIN { OFS = ":" ; FS = ":" ; }
@ -67,12 +69,10 @@ function stop_gpg_agent {
username = $( id -u -n)
if [ [ " $GITSECRET_DIST " = = "windows" ] ] ; then
ps -l -u " $username " | gawk \
'/gpg-agent/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' \
> /dev/null 2>& 1
'/gpg-agent/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
else
ps -wx -U " $username " | gawk \
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' \
> /dev/null 2>& 1
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
fi
}
@ -102,7 +102,7 @@ function install_fixture_key {
local public_key = " $BATS_TMPDIR /public- ${ 1 } .key "
cp " $FIXTURES_DIR /gpg/ ${ 1 } /public.key " " $public_key "
$GPGTEST --import " $public_key " > /dev/null 2>& 1
$GPGTEST --import " $public_key " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
rm -f " $public_key "
}
@ -120,7 +120,7 @@ function install_fixture_full_key {
cp " $FIXTURES_DIR /gpg/ ${ 1 } /private.key " " $private_key "
bash -c " $gpgtest_import --allow-secret-key-import \
--import \" $private_key \" " > /dev/null 2>&1
--import \" $private_key \" " >> "${ TEST_GPG_OUTPUT_FILE } " 2>&1
# since 0.1.2 fingerprint is returned:
fingerprint = $( get_gpg_fingerprint_by_email " $email " )
@ -137,7 +137,7 @@ function uninstall_fixture_key {
local email
email = " $1 "
$GPGTEST --yes --delete-key " $email " > /dev/null 2>& 1
$GPGTEST --yes --delete-key " $email " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
@ -151,8 +151,7 @@ function uninstall_fixture_full_key {
fingerprint = $( get_gpg_fingerprint_by_email " $email " )
fi
$GPGTEST --yes \
--delete-secret-keys " $fingerprint " > /dev/null 2>& 1
$GPGTEST --yes --delete-secret-keys " $fingerprint " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
uninstall_fixture_key " $1 "
}
@ -200,12 +199,12 @@ function set_state_initial {
function set_state_git {
git init > /dev/null 2>& 1
git init >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
function set_state_secret_init {
git secret init > /dev/null 2>& 1
git secret init >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
@ -213,7 +212,7 @@ function set_state_secret_tell {
local email
email = " $1 "
git secret tell -d " $TEST_GPG_HOMEDIR " " $email " > /dev/null 2>& 1
git secret tell -d " $TEST_GPG_HOMEDIR " " $email " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
@ -223,7 +222,7 @@ function set_state_secret_add {
echo " $content " > " $filename " # we add a newline
echo " $filename " >> ".gitignore"
git secret add " $filename " > /dev/null 2>& 1
git secret add " $filename " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
function set_state_secret_add_without_newline {
@ -232,12 +231,12 @@ function set_state_secret_add_without_newline {
echo -n " $content " > " $filename " # we do not add a newline
echo " $filename " >> ".gitignore"
git secret add " $filename " > /dev/null 2>& 1
git secret add " $filename " >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
function set_state_secret_hide {
git secret hide > /dev/null 2>& 1
git secret hide >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
}
@ -247,7 +246,7 @@ function unset_current_state {
# unsets `secret_hide`
# removes .secret files:
git secret clean > /dev/null 2>& 1
git secret clean >> " $TEST_GPG_OUTPUT_FILE " 2>& 1
# unsets `secret_add`, `secret_tell` and `secret_init` by removing $_SECRETS_DIR
local secrets_dir
@ -262,6 +261,18 @@ function unset_current_state {
# stop gpg-agent
stop_gpg_agent
# SECRETS_TEST_VERBOSE is experimental
if [ [ -n " $SECRETS_TEST_VERBOSE " ] ] ; then
# display the captured output as bats diagnostic (fd3, preceded by '# ')
sed " s/^/# $BATS_TEST_DESCRIPTION : / " < " $TEST_GPG_OUTPUT_FILE " >& 3
# display the last $output
# shellcheck disable=SC2001,SC2154
echo " $output " | sed " s/^/# ' $BATS_TEST_DESCRIPTION ' final output: / " >& 3
fi
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.*" \