2018-04-14 12:33:57 +00:00
|
|
|
#!/usr/bin/env bats
|
2022-02-20 15:39:37 +00:00
|
|
|
# shellcheck disable=SC2030,SC2031
|
|
|
|
# above is to avoid shellcheck info warnings that we don't understand
|
2018-04-14 12:33:57 +00:00
|
|
|
|
|
|
|
load _test_base
|
|
|
|
|
2018-07-14 19:23:17 +00:00
|
|
|
FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
|
2018-04-14 12:33:57 +00:00
|
|
|
FILE_CONTENTS="hidden content юникод"
|
|
|
|
|
|
|
|
FINGERPRINT=""
|
|
|
|
|
|
|
|
|
|
|
|
function setup {
|
|
|
|
FINGERPRINT=$(install_fixture_full_key "$TEST_DEFAULT_USER")
|
|
|
|
|
|
|
|
set_state_initial
|
|
|
|
set_state_git
|
|
|
|
set_state_secret_init
|
|
|
|
set_state_secret_tell "$TEST_DEFAULT_USER"
|
|
|
|
set_state_secret_add "$FILE_TO_HIDE" "$FILE_CONTENTS"
|
|
|
|
set_state_secret_hide
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function teardown {
|
|
|
|
uninstall_fixture_full_key "$TEST_DEFAULT_USER" "$FINGERPRINT"
|
|
|
|
unset_current_state
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "run 'cat' with password argument" {
|
2021-05-03 16:21:33 +00:00
|
|
|
local password
|
|
|
|
password=$(test_user_password "$TEST_DEFAULT_USER")
|
2021-05-03 11:43:02 +00:00
|
|
|
run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE"
|
2018-04-14 12:33:57 +00:00
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# $output is the output from 'git secret cat' above
|
|
|
|
[ "$FILE_CONTENTS" == "$output" ]
|
|
|
|
}
|
|
|
|
|
2021-05-03 16:21:33 +00:00
|
|
|
|
2019-03-07 22:46:51 +00:00
|
|
|
@test "run 'cat' with password argument and SECRETS_VERBOSE=1" {
|
2021-05-03 16:21:33 +00:00
|
|
|
local password
|
|
|
|
password=$(test_user_password "$TEST_DEFAULT_USER")
|
2021-05-03 11:43:02 +00:00
|
|
|
SECRETS_VERBOSE=1 run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE"
|
2019-03-07 22:46:51 +00:00
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# $output _contains_ the output from 'git secret cat',
|
|
|
|
# may have extra output from gpg
|
2019-03-07 22:46:51 +00:00
|
|
|
[[ "$output" == *"$FILE_CONTENTS"* ]]
|
|
|
|
}
|
|
|
|
|
2021-05-03 16:21:33 +00:00
|
|
|
|
2022-06-12 17:56:02 +00:00
|
|
|
@test "run 'cat' with bad filename" {
|
2018-04-16 15:05:50 +00:00
|
|
|
run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" NO_SUCH_FILE
|
2022-04-19 21:14:55 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2018-04-14 13:28:05 +00:00
|
|
|
}
|
2021-05-03 16:21:33 +00:00
|
|
|
|
|
|
|
|
2019-03-31 00:13:54 +00:00
|
|
|
@test "run 'cat' with bad arg" {
|
2021-05-03 16:21:33 +00:00
|
|
|
local password
|
|
|
|
password=$(test_user_password "$TEST_DEFAULT_USER")
|
2021-05-03 11:43:02 +00:00
|
|
|
run git secret cat -Z -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE"
|
2019-03-31 00:13:54 +00:00
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
}
|
2022-01-15 19:54:22 +00:00
|
|
|
|
|
|
|
@test "run 'cat' from subdir" {
|
|
|
|
local password
|
|
|
|
password=$(test_user_password "$TEST_DEFAULT_USER")
|
|
|
|
|
|
|
|
mkdir subdir
|
|
|
|
echo "content2" > subdir/new_filename.txt
|
|
|
|
|
2022-02-20 15:39:37 +00:00
|
|
|
( # start subshell for subdir tests
|
|
|
|
cd subdir
|
|
|
|
run git secret add new_filename.txt
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
run git secret hide
|
|
|
|
[ "$status" -eq 0 ]
|
2022-01-15 19:54:22 +00:00
|
|
|
|
2022-02-20 15:39:37 +00:00
|
|
|
run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" new_filename.txt
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
) # end subshell, cd back up
|
2022-01-15 19:54:22 +00:00
|
|
|
|
|
|
|
# clean up
|
|
|
|
rm -rf subdir
|
|
|
|
}
|