2016-02-21 13:26:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This file is following a name convention defined in:
|
2018-06-20 13:56:25 +00:00
|
|
|
# https://github.com/bats-core/bats-core
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2019-03-04 14:40:35 +00:00
|
|
|
# shellcheck disable=SC1090
|
2021-05-05 12:59:28 +00:00
|
|
|
source "$SECRETS_PROJECT_ROOT/src/version.sh"
|
2019-03-04 14:40:35 +00:00
|
|
|
# shellcheck disable=SC1090
|
2021-05-05 12:59:28 +00:00
|
|
|
source "$SECRETS_PROJECT_ROOT/src/_utils/_git_secret_tools.sh"
|
|
|
|
source "$SECRETS_PROJECT_ROOT/src/_utils/_git_secret_tools_freebsd.sh"
|
|
|
|
source "$SECRETS_PROJECT_ROOT/src/_utils/_git_secret_tools_linux.sh"
|
|
|
|
source "$SECRETS_PROJECT_ROOT/src/_utils/_git_secret_tools_osx.sh"
|
2016-02-21 13:26:17 +00:00
|
|
|
|
|
|
|
# Constants:
|
|
|
|
FIXTURES_DIR="$BATS_TEST_DIRNAME/fixtures"
|
|
|
|
|
2017-09-13 22:06:16 +00:00
|
|
|
TEST_GPG_HOMEDIR="$BATS_TMPDIR"
|
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# TODO: factor out tempdir creation.
|
|
|
|
# On osx TEST_GPG_OUTPUT_FILE, still has 'XXXXXX's, like
|
2019-05-21 16:06:51 +00:00
|
|
|
# /var/folders/mm/_f0j67x10l92b4zznyx4ylzh00017w/T/gitsecret_output.XXXXXX.RaqyGYqL
|
2021-05-03 11:43:02 +00:00
|
|
|
TEST_GPG_OUTPUT_FILE=$(
|
|
|
|
TMPDIR="$BATS_TMPDIR" mktemp -t 'gitsecret_output.XXXXXX'
|
|
|
|
)
|
|
|
|
|
2019-03-28 11:41:07 +00:00
|
|
|
|
2019-03-04 14:40:35 +00:00
|
|
|
# shellcheck disable=SC2016
|
2017-09-13 22:06:16 +00:00
|
|
|
AWK_GPG_GET_FP='
|
|
|
|
BEGIN { OFS=":"; FS=":"; }
|
|
|
|
{
|
|
|
|
if ( $1 == "fpr" )
|
2017-09-12 16:49:24 +00:00
|
|
|
{
|
2017-09-13 22:06:16 +00:00
|
|
|
print $10
|
|
|
|
exit
|
2017-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
# GPG-based stuff:
|
2021-05-03 11:43:02 +00:00
|
|
|
: "${SECRETS_GPG_COMMAND:='gpg'}"
|
2017-03-05 21:46:49 +00:00
|
|
|
|
|
|
|
# This command is used with absolute homedir set and disabled warnings:
|
2017-09-13 22:06:16 +00:00
|
|
|
GPGTEST="$SECRETS_GPG_COMMAND --homedir=$TEST_GPG_HOMEDIR --no-permission-warning --batch"
|
2017-09-12 16:49:24 +00:00
|
|
|
|
2019-09-07 00:21:50 +00:00
|
|
|
# Test key fixture data. Fixtures are at tests/fixtures/gpg/$email
|
2016-05-29 10:56:48 +00:00
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# See tests/fixtures/gpg/README.md for more
|
|
|
|
# on key fixtures 'user[1-5]@gitsecret.io'
|
|
|
|
# these two are 'normal' keys.
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_DEFAULT_USER='user1@gitsecret.io'
|
|
|
|
export TEST_SECOND_USER='user2@gitsecret.io'
|
2018-12-01 13:48:09 +00:00
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# TEST_NONAME_USER (user3) created with '--quick-key-generate'
|
|
|
|
# and has only an email, no username.
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_NONAME_USER='user3@gitsecret.io'
|
2018-12-01 13:48:09 +00:00
|
|
|
|
|
|
|
# TEST_EXPIRED_USER (user4) has expired
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_EXPIRED_USER='user4@gitsecret.io' # this key expires 2018-09-24
|
2018-12-01 13:48:09 +00:00
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# fixture filename is named this,
|
|
|
|
# but key has no email and a comment, as per #527
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_NOEMAIL_COMMENT_USER='user5@gitsecret.io'
|
2019-09-07 00:21:50 +00:00
|
|
|
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_ATTACKER_USER='attacker1@gitsecret.io'
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2018-07-14 19:23:17 +00:00
|
|
|
|
2021-05-05 12:59:28 +00:00
|
|
|
export TEST_DEFAULT_FILENAME='space file' # has spaces
|
|
|
|
export TEST_SECOND_FILENAME='space file two' # has spaces
|
|
|
|
export TEST_THIRD_FILENAME='space file three' # has spaces
|
|
|
|
export TEST_FOURTH_FILENAME='space file three [] * $' # has spaces and special chars
|
2018-07-14 19:23:17 +00:00
|
|
|
|
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
function test_user_password {
|
2018-09-25 21:08:44 +00:00
|
|
|
# Password for 'user3@gitsecret.io' is 'user3pass'
|
2021-05-03 11:43:02 +00:00
|
|
|
# As it was set on key creation.
|
2019-03-04 14:40:35 +00:00
|
|
|
# shellcheck disable=SC2001
|
2021-05-03 11:43:02 +00:00
|
|
|
echo "$1" | sed -e 's/@.*/pass/'
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# GPG:
|
|
|
|
|
2017-09-12 16:49:24 +00:00
|
|
|
function stop_gpg_agent {
|
2019-03-04 14:40:35 +00:00
|
|
|
local username
|
|
|
|
username=$(id -u -n)
|
2021-05-05 12:59:28 +00:00
|
|
|
if [[ "$SECRETS_DOCKER_ENV" == 'windows' ]]; then
|
2019-03-09 23:49:45 +00:00
|
|
|
ps -l -u "$username" | gawk \
|
2019-03-28 11:41:07 +00:00
|
|
|
'/gpg-agent/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2019-03-09 23:49:45 +00:00
|
|
|
else
|
2019-08-30 13:35:47 +00:00
|
|
|
local ps_is_busybox
|
2021-05-05 12:59:28 +00:00
|
|
|
ps_is_busybox=_exe_is_busybox 'ps'
|
|
|
|
if [[ $ps_is_busybox -eq '1' ]]; then
|
|
|
|
echo '# git-secret: tests: not stopping gpg-agent on busybox' >&3
|
2019-08-30 13:35:47 +00:00
|
|
|
else
|
|
|
|
ps -wx -U "$username" | gawk \
|
|
|
|
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
|
|
|
fi
|
2019-03-09 23:49:45 +00:00
|
|
|
fi
|
2017-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 22:06:16 +00:00
|
|
|
|
2017-09-12 16:49:24 +00:00
|
|
|
function get_gpgtest_prefix {
|
|
|
|
if [[ $GPG_VER_21 -eq 1 ]]; then
|
2019-03-04 14:40:35 +00:00
|
|
|
# shellcheck disable=SC2086
|
2017-09-12 16:49:24 +00:00
|
|
|
echo "echo \"$(test_user_password $1)\" | "
|
|
|
|
else
|
2021-05-05 12:59:28 +00:00
|
|
|
echo ''
|
2017-09-12 16:49:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:06:16 +00:00
|
|
|
|
2016-06-16 19:34:25 +00:00
|
|
|
function get_gpg_fingerprint_by_email {
|
2016-02-21 13:26:17 +00:00
|
|
|
local email="$1"
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local fingerprint
|
|
|
|
|
2017-09-27 19:48:35 +00:00
|
|
|
fingerprint=$($GPGTEST --with-fingerprint \
|
|
|
|
--with-colon \
|
2019-03-04 14:40:35 +00:00
|
|
|
--list-secret-key "$email" | gawk "$AWK_GPG_GET_FP")
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
echo "$fingerprint"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function install_fixture_key {
|
|
|
|
local public_key="$BATS_TMPDIR/public-${1}.key"
|
|
|
|
|
2019-03-04 14:40:35 +00:00
|
|
|
cp "$FIXTURES_DIR/gpg/${1}/public.key" "$public_key"
|
2019-03-28 11:41:07 +00:00
|
|
|
$GPGTEST --import "$public_key" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2019-05-21 16:06:51 +00:00
|
|
|
rm -f "$public_key" || _abort "Couldn't delete public key: $public_key"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function install_fixture_full_key {
|
|
|
|
local private_key="$BATS_TMPDIR/private-${1}.key"
|
2019-03-04 14:40:35 +00:00
|
|
|
local gpgtest_prefix
|
2021-05-03 11:43:02 +00:00
|
|
|
gpgtest_prefix=$(get_gpgtest_prefix "$1")
|
2017-09-12 16:49:24 +00:00
|
|
|
local gpgtest_import="$gpgtest_prefix $GPGTEST"
|
2017-09-13 22:06:16 +00:00
|
|
|
local email
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local fingerprint
|
|
|
|
|
2018-09-25 21:08:44 +00:00
|
|
|
email="$1"
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2019-03-04 14:40:35 +00:00
|
|
|
cp "$FIXTURES_DIR/gpg/${1}/private.key" "$private_key"
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2017-09-13 22:06:16 +00:00
|
|
|
bash -c "$gpgtest_import --allow-secret-key-import \
|
2019-03-28 11:41:07 +00:00
|
|
|
--import \"$private_key\"" >> "${TEST_GPG_OUTPUT_FILE}" 2>&1
|
2016-04-10 11:14:41 +00:00
|
|
|
|
|
|
|
# since 0.1.2 fingerprint is returned:
|
2019-03-04 14:40:35 +00:00
|
|
|
fingerprint=$(get_gpg_fingerprint_by_email "$email")
|
2016-04-10 11:14:41 +00:00
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
install_fixture_key "$1"
|
2016-04-10 11:14:41 +00:00
|
|
|
|
2019-05-21 16:06:51 +00:00
|
|
|
rm -f "$private_key" || _abort "Couldn't delete private key: $private_key"
|
2016-04-10 11:14:41 +00:00
|
|
|
# return fingerprint to delete it later:
|
|
|
|
echo "$fingerprint"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uninstall_fixture_key {
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local email
|
|
|
|
|
2018-09-25 21:08:44 +00:00
|
|
|
email="$1"
|
2019-03-28 11:41:07 +00:00
|
|
|
$GPGTEST --yes --delete-key "$email" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uninstall_fixture_full_key {
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local email
|
2018-09-25 21:08:44 +00:00
|
|
|
email="$1"
|
2016-04-10 11:14:41 +00:00
|
|
|
|
|
|
|
local fingerprint="$2"
|
|
|
|
if [[ -z "$fingerprint" ]]; then
|
|
|
|
# see issue_12, fingerprint on `gpg2` has different format:
|
2016-10-03 15:44:37 +00:00
|
|
|
fingerprint=$(get_gpg_fingerprint_by_email "$email")
|
2016-04-10 11:14:41 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-28 11:41:07 +00:00
|
|
|
$GPGTEST --yes --delete-secret-keys "$fingerprint" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
|
|
|
|
uninstall_fixture_key "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Git:
|
2016-05-29 10:56:48 +00:00
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
function git_set_config_email {
|
|
|
|
git config --local user.email "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-29 10:56:48 +00:00
|
|
|
function git_commit {
|
|
|
|
git_set_config_email "$1"
|
2016-06-16 19:34:25 +00:00
|
|
|
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local user_name
|
|
|
|
local commit_gpgsign
|
|
|
|
|
|
|
|
user_name=$(git config user.name)
|
|
|
|
|
|
|
|
commit_gpgsign=$(git config commit.gpgsign)
|
2016-06-16 19:34:25 +00:00
|
|
|
|
|
|
|
git config --local user.name "$TEST_DEFAULT_USER"
|
|
|
|
git config --local commit.gpgsign false
|
2016-05-29 10:56:48 +00:00
|
|
|
|
|
|
|
git add --all
|
|
|
|
git commit -m "$2"
|
2016-06-16 19:34:25 +00:00
|
|
|
|
|
|
|
git config --local user.name "$user_name"
|
|
|
|
git config --local commit.gpgsign "$commit_gpgsign"
|
2016-05-29 10:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
function remove_git_repository {
|
|
|
|
rm -rf ".git"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Git Secret:
|
2016-05-29 10:56:48 +00:00
|
|
|
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
function set_state_initial {
|
|
|
|
cd "$BATS_TMPDIR" || exit 1
|
2017-03-05 21:46:49 +00:00
|
|
|
rm -rf "${BATS_TMPDIR:?}/*"
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
function set_state_git {
|
2019-10-09 18:05:31 +00:00
|
|
|
git init >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function set_state_secret_init {
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret init >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function set_state_secret_tell {
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
local email
|
|
|
|
|
2018-09-25 21:08:44 +00:00
|
|
|
email="$1"
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret tell -d "$TEST_GPG_HOMEDIR" "$email" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function set_state_secret_add {
|
|
|
|
local filename="$1"
|
|
|
|
local content="$2"
|
2019-01-01 14:37:11 +00:00
|
|
|
echo "$content" > "$filename" # we add a newline
|
2021-05-05 12:59:28 +00:00
|
|
|
echo "$filename" >> '.gitignore'
|
2019-01-01 14:37:11 +00:00
|
|
|
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret add "$filename" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2019-01-01 14:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_state_secret_add_without_newline {
|
|
|
|
local filename="$1"
|
|
|
|
local content="$2"
|
|
|
|
echo -n "$content" > "$filename" # we do not add a newline
|
2021-05-05 12:59:28 +00:00
|
|
|
echo "$filename" >> '.gitignore'
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret add "$filename" >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function set_state_secret_hide {
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret hide >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function unset_current_state {
|
|
|
|
# states order:
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
# initial, git, secret_init, secret_tell, secret_add, secret_hide
|
2016-02-21 13:26:17 +00:00
|
|
|
|
|
|
|
# unsets `secret_hide`
|
|
|
|
# removes .secret files:
|
2019-03-28 11:41:07 +00:00
|
|
|
git secret clean >> "$TEST_GPG_OUTPUT_FILE" 2>&1
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
# unsets `secret_add`, `secret_tell` and `secret_init` by removing $_SECRETS_DIR
|
|
|
|
local secrets_dir
|
|
|
|
secrets_dir=$(_get_secrets_dir)
|
|
|
|
|
|
|
|
rm -rf "$secrets_dir"
|
2021-05-05 12:59:28 +00:00
|
|
|
rm -rf '.gitignore'
|
2016-02-21 13:26:17 +00:00
|
|
|
|
|
|
|
# unsets `git` state
|
|
|
|
remove_git_repository
|
|
|
|
|
2017-09-13 22:06:16 +00:00
|
|
|
# stop gpg-agent
|
|
|
|
stop_gpg_agent
|
|
|
|
|
2019-03-28 11:41:07 +00:00
|
|
|
# SECRETS_TEST_VERBOSE is experimental
|
2021-05-03 11:43:02 +00:00
|
|
|
if [[ -n "$SECRETS_TEST_VERBOSE" ]]; then
|
2019-03-28 11:41:07 +00:00
|
|
|
# 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
|
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
rm -f "$TEST_GPG_OUTPUT_FILE"
|
2019-05-21 16:06:51 +00:00
|
|
|
|
2021-05-03 11:43:02 +00:00
|
|
|
# new code to remove temporary gpg homedir artifacts.
|
2019-05-21 16:06:51 +00:00
|
|
|
# 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 /'
|
2021-05-03 11:43:02 +00:00
|
|
|
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 /'
|
|
|
|
rm -vrf "${TEST_GPG_HOMEDIR:?}/${TEST_FOURTH_FILENAME}" 2>&1 | sed 's/^/# unset_current_state: rm /'
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
|
|
|
|
# return to the base dir:
|
2021-05-05 12:59:28 +00:00
|
|
|
cd "$SECRETS_PROJECT_ROOT" || exit 1
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
2019-05-21 16:06:51 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|