diff --git a/.travis.yml b/.travis.yml index 57879b35..ebe541c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,16 @@ language: c -sudo: false - +env: + - SECRETS_GPG_COMMAND=gpg + - SECRETS_GPG_COMMAND=gpg2 + branches: only: - master - develop install: + - test $SECRETS_GPG_COMMAND = gpg2 && sudo apt-get install gnupg2 || echo 0 - make install-test script: diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..ba5bff49 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +## Version 0.1.1 + +- Added `--dry-run` option to the `git secret` command, which prevents any actions. +- Now `install_full_fixture()` returns a fingerprint +- Now `uninstall_full_fixture()` receives two args +- Fixed bug, when tests were failing with `gpg2` +- New travis strategy: testing both `gpg` and `gpg2` +- Removed animation from docs, now using `asciinema.org` + +## Version 0.1.0 + +- Initial release diff --git a/README.md b/README.md index 8697ae20..1890b3cf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Preview -![git-secret terminal preview](https://raw.githubusercontent.com/sobolevn/git-secret/gh-pages/images/gitsecret_terminal.gif) +[![git-secret terminal preview](https://asciinema.org/a/41811.png)](https://asciinema.org/a/41811?autoplay=1) ## Usage @@ -25,7 +25,6 @@ This project is still under development. Current objectives: - integrate [`shellcheck`](https://github.com/koalaman/shellcheck) for code style tests - create `CONTRIBUTING.md` with development process explained - сygwin support (?) -- add `CHANGELOG.md` with semantic versioning ## Testing @@ -35,6 +34,4 @@ To run tests call: `make test`. It will download and install `bats` into `vendor ## Changelog -### Version 0.1.0 - -- Initial release +See [CHANGELOG.md](CHANGELOG.md) diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index d1a1adf8..175fb782 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GITSECRET_VERSION="0.1.0" +GITSECRET_VERSION="0.1.1" # Global variables: diff --git a/src/commands/git_secret_tell.sh b/src/commands/git_secret_tell.sh index 2ff6c3ad..0bbfc151 100644 --- a/src/commands/git_secret_tell.sh +++ b/src/commands/git_secret_tell.sh @@ -16,7 +16,7 @@ function tell { h) _show_manual_for "tell";; m) # Set email of the git current user: - email=$(git config user.email) || _abort "'git congig user.email' is not set." + email=$(git config user.email) || _abort "'git config user.email' is not set." ;; d) homedir=$OPTARG;; diff --git a/src/main.sh b/src/main.sh index 011c88b4..7c7964eb 100755 --- a/src/main.sh +++ b/src/main.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +set -e function _check_setup { # Checking git and secret-plugin setup: @@ -40,23 +41,39 @@ function _init_script { _incorrect_usage "no input parameters provided." 126 fi - if [[ $1 == "--version" ]]; then - _show_version - fi + # Parse plugin-level options: + local dry_run=0 + + while [[ $# > 0 ]]; do + local opt="$1" + + case "$opt" in + # options for quick-exit strategy: + --dry-run) + dry_run=1 + shift;; - # checking for proper set-up: - _check_setup + --version) _show_version;; - # load dependencies: - # for f in ${0%/*}/src/*/*; do [[ -f "$f" ]] && . "$f"; done + *) break;; # do nothing + esac + done - # routing the input command: - if [[ $(_function_exists $1) == 0 ]] && [[ ! $1 == _* ]]; then - $1 "${@:2}" - else - _incorrect_usage "command $1 not found." 126 + if [[ "$dry_run" == 0 ]]; then + # checking for proper set-up: + _check_setup + + # load dependencies: + # for f in ${0%/*}/src/*/*; do [[ -f "$f" ]] && . "$f"; done + + # routing the input command: + if [[ $(_function_exists $1) == 0 ]] && [[ ! $1 == _* ]]; then + $1 "${@:2}" + else # TODO: elif [[ $(_plugin_exists $1) == 0 ]]; then + _incorrect_usage "command $1 not found." 126 + fi fi } -set -e + _init_script $@ diff --git a/tests/_test_base.bash b/tests/_test_base.bash index 22c7d15f..ddf1a052 100644 --- a/tests/_test_base.bash +++ b/tests/_test_base.bash @@ -63,14 +63,21 @@ function install_fixture_full_key { local private_key="$BATS_TMPDIR/private-${1}.key" local email=$(test_user_email "$1") - # local fingerprint=`_get_gpg_fingerprint_by_email "$email"` $SECRETS_GPG_COMMAND --homedir="$FIXTURES_DIR/gpg/${1}" \ --no-permission-warning --output "$private_key" --armor \ --yes --export-secret-key "$email" > /dev/null 2>&1 $GPGTEST --allow-secret-key-import --import "$private_key" > /dev/null 2>&1 + local fp=$($GPGTEST --with-fingerprint "$private_key") + + # since 0.1.2 fingerprint is returned: + local fingerprint=$(echo "$fp" | tr -d ' ' | sed -n '2p' | sed -e 's/.*=//g') + install_fixture_key "$1" + + # return fingerprint to delete it later: + echo "$fingerprint" } @@ -82,7 +89,13 @@ function uninstall_fixture_key { function uninstall_fixture_full_key { local email=$(test_user_email "$1") - local fingerprint=$(_get_gpg_fingerprint_by_email "$email") + + local fingerprint="$2" + if [[ -z "$fingerprint" ]]; then + # see issue_12, fingerprint on `gpg2` has different format: + fingerprint=$(_get_gpg_fingerprint_by_email "$email") + fi + $GPGTEST --batch --yes --delete-secret-keys "$fingerprint" > /dev/null 2>&1 uninstall_fixture_key "$1" diff --git a/tests/test_reveal.bats b/tests/test_reveal.bats index 574e4aea..c04b0034 100644 --- a/tests/test_reveal.bats +++ b/tests/test_reveal.bats @@ -5,9 +5,11 @@ load _test_base FILE_TO_HIDE="file_to_hide" FILE_CONTENTS="hidden content юникод" +FINGERPRINT="" + function setup { - install_fixture_full_key "$TEST_DEFAULT_USER" + FINGERPRINT=$(install_fixture_full_key "$TEST_DEFAULT_USER") set_state_git set_state_secret_init @@ -18,7 +20,7 @@ function setup { function teardown { - uninstall_fixture_full_key "$TEST_DEFAULT_USER" + uninstall_fixture_full_key "$TEST_DEFAULT_USER" "$FINGERPRINT" unset_current_state rm -f "$FILE_TO_HIDE" } @@ -53,7 +55,7 @@ function teardown { rm -f "$FILE_TO_HIDE" local attacker="attacker1" - install_fixture_full_key "$attacker" + local atacker_fingerprint=$(install_fixture_full_key "$attacker") local password=$(test_user_password "$attacker") run git secret reveal -d "$TEST_GPG_HOMEDIR" -p "$password" @@ -61,7 +63,7 @@ function teardown { [ "$status" -eq 2 ] [ ! -f "$FILE_TO_HIDE" ] - uninstall_fixture_full_key "$attacker" + uninstall_fixture_full_key "$attacker" "$atacker_fingerprint" } @@ -71,7 +73,7 @@ function teardown { set_state_secret_tell "$new_user" set_state_secret_hide - uninstall_fixture_full_key "$TEST_DEFAULT_USER" + uninstall_fixture_full_key "$TEST_DEFAULT_USER" "$FINGERPRINT" local password=$(test_user_password "$new_user") run git secret reveal -d "$TEST_GPG_HOMEDIR" -p "$password"