have lint target run shellcheck over tests (closes #373)

* have lint target run shellcheck over tests

* lint and fix tests/ since shellcheck knows bats

* lint and fix tests/ since shellcheck knows bats

* revert debug output

* changes for shellcheck

* revert unintended change

  [tests/_test_base.bash]

* use 'local' for user/filename vars, not 'export'

* add note about Shellcheck and tests/

* local can only be used in functions - use export

* restore shbang edited in error
pull/353/head
Josh Rabinowitz 5 years ago committed by Nikita Sobolev
parent ae465c0142
commit 505cb1fe42

@ -16,6 +16,7 @@
- Add text explaining git-secret Style Guide and Development Philosophy
- Upgrade bats-core to v1.1.0
- Spelling fixes
- Use Shellcheck on tests/ files, changes for Shellcheck in tests/ (#368)
## Version 0.2.5

@ -84,6 +84,7 @@ develop: clean build install-hooks
.PHONY: lint
lint:
@find src utils -type f -name '*.sh' -print0 | xargs -0 -I {} shellcheck {}
@find tests -type f -name '*.bats' -o -name '*.bash' -print0 | xargs -0 -I {} shellcheck {}
#
# Packaging:

@ -3,9 +3,9 @@
# This file is following a name convention defined in:
# https://github.com/bats-core/bats-core
# shellcheck disable=1090
# shellcheck disable=SC1090
source "$SECRET_PROJECT_ROOT/src/version.sh"
# shellcheck disable=1090
# shellcheck disable=SC1090
source "$SECRET_PROJECT_ROOT/src/_utils/_git_secret_tools.sh"
# Constants:
@ -13,6 +13,7 @@ FIXTURES_DIR="$BATS_TEST_DIRNAME/fixtures"
TEST_GPG_HOMEDIR="$BATS_TMPDIR"
# shellcheck disable=SC2016
AWK_GPG_GET_FP='
BEGIN { OFS=":"; FS=":"; }
{
@ -34,29 +35,27 @@ GPGTEST="$SECRETS_GPG_COMMAND --homedir=$TEST_GPG_HOMEDIR --no-permission-warnin
# Personal data:
# these two are 'normal' keys
TEST_DEFAULT_USER="user1@gitsecret.io"
TEST_SECOND_USER="user2@gitsecret.io"
export TEST_DEFAULT_USER="user1@gitsecret.io"
export TEST_SECOND_USER="user2@gitsecret.io"
# TEST_NONAME_USER (user3) created with '--quick-key-generate' and has only an email, no username.
TEST_NONAME_USER="user3@gitsecret.io"
export TEST_NONAME_USER="user3@gitsecret.io"
# TEST_EXPIRED_USER (user4) has expired
TEST_EXPIRED_USER="user4@gitsecret.io" # this key expires 2018-09-24
export TEST_EXPIRED_USER="user4@gitsecret.io" # this key expires 2018-09-24
TEST_ATTACKER_USER="attacker1@gitsecret.io"
export TEST_ATTACKER_USER="attacker1@gitsecret.io"
#TEST_DEFAULT_FILENAME="file_one" # no spaces
#TEST_SECOND_FILENAME="file_two" # no spaces
#TEST_THIRD_FILENAME="file_three" # no spaces
TEST_DEFAULT_FILENAME="space file" # has spaces
TEST_SECOND_FILENAME="space file two" # has spaces
TEST_THIRD_FILENAME="space file three" # has spaces
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
function test_user_password {
# Password for 'user3@gitsecret.io' is 'user3pass'
# As it was set on key creation.
# shellcheck disable=SC2001
echo "$1" | sed -e 's/@.*/pass/'
}
@ -65,7 +64,8 @@ function test_user_password {
# GPG:
function stop_gpg_agent {
local username=$(id -u -n)
local username
username=$(id -u -n)
ps -wx -U "$username" | gawk \
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill -9 "$1) } }' \
> /dev/null 2>&1
@ -74,6 +74,7 @@ function stop_gpg_agent {
function get_gpgtest_prefix {
if [[ $GPG_VER_21 -eq 1 ]]; then
# shellcheck disable=SC2086
echo "echo \"$(test_user_password $1)\" | "
else
echo ""
@ -87,7 +88,7 @@ function get_gpg_fingerprint_by_email {
fingerprint=$($GPGTEST --with-fingerprint \
--with-colon \
--list-secret-key $email | gawk "$AWK_GPG_GET_FP")
--list-secret-key "$email" | gawk "$AWK_GPG_GET_FP")
echo "$fingerprint"
}
@ -95,7 +96,7 @@ function get_gpg_fingerprint_by_email {
function install_fixture_key {
local public_key="$BATS_TMPDIR/public-${1}.key"
\cp "$FIXTURES_DIR/gpg/${1}/public.key" "$public_key"
cp "$FIXTURES_DIR/gpg/${1}/public.key" "$public_key"
$GPGTEST --import "$public_key" > /dev/null 2>&1
rm -f "$public_key"
}
@ -103,21 +104,21 @@ function install_fixture_key {
function install_fixture_full_key {
local private_key="$BATS_TMPDIR/private-${1}.key"
local gpgtest_prefix="$(get_gpgtest_prefix $1)"
local gpgtest_prefix
gpgtest_prefix=$(get_gpgtest_prefix "$1")
local gpgtest_import="$gpgtest_prefix $GPGTEST"
local email
local fp
local fingerprint
email="$1"
\cp "$FIXTURES_DIR/gpg/${1}/private.key" "$private_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
# since 0.1.2 fingerprint is returned:
fingerprint=$(get_gpg_fingerprint_by_email $email)
fingerprint=$(get_gpg_fingerprint_by_email "$email")
install_fixture_key "$1"

Loading…
Cancel
Save