Skip to content

Commit

Permalink
Use gpg1 (if available) for automated tests
Browse files Browse the repository at this point in the history
gnupg2 does not support agent-less password input (breaking the
expect-driven tests).
  • Loading branch information
TheLocehiliosan committed Sep 8, 2016
1 parent 13a1395 commit e40c054
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions test/109_accept_encryption.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ T_RECIPIENT_GOOD="[yadm]\n\tgpg-recipient = yadm-test1"
T_RECIPIENT_BAD="[yadm]\n\tgpg-recipient = invalid"
T_RECIPIENT_ASK="[yadm]\n\tgpg-recipient = ASK"

#; use gpg1 if it's available
T_GPG_PROGRAM="gpg"
if command -v gpg1 >/dev/null 2>&1; then
T_GPG_PROGRAM="gpg1"
fi

function import_keys() {
gpg --import "test/test_key" >/dev/null 2>&1 || true
gpg --import-ownertrust < "test/ownertrust.txt" >/dev/null 2>&1
"$T_GPG_PROGRAM" --import "test/test_key" >/dev/null 2>&1 || true
"$T_GPG_PROGRAM" --import-ownertrust < "test/ownertrust.txt" >/dev/null 2>&1
}

function remove_keys() {
gpg --batch --yes --delete-secret-keys "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
gpg --batch --yes --delete-key "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
"$T_GPG_PROGRAM" --batch --yes --delete-secret-keys "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
"$T_GPG_PROGRAM" --batch --yes --delete-key "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
}

setup() {
Expand Down Expand Up @@ -50,15 +56,18 @@ setup() {
#; encrypt YADM_ARCHIVE (symmetric)
expect <<EOF >/dev/null
set timeout 2;
spawn gpg --yes -c --output "$T_ARCHIVE_SYMMETRIC" "$T_TMP/build_archive.tar"
spawn "$T_GPG_PROGRAM" --yes -c --output "$T_ARCHIVE_SYMMETRIC" "$T_TMP/build_archive.tar"
expect "passphrase:" {send "$T_PASSWD\n"}
expect "passphrase:" {send "$T_PASSWD\n"}
expect "$"
foreach {pid spawnid os_error_flag value} [wait] break
EOF

#; encrypt YADM_ARCHIVE (asymmetric)
gpg --yes --batch -e -r "$T_KEY_NAME" --output "$T_ARCHIVE_ASYMMETRIC" "$T_TMP/build_archive.tar"
"$T_GPG_PROGRAM" --yes --batch -e -r "$T_KEY_NAME" --output "$T_ARCHIVE_ASYMMETRIC" "$T_TMP/build_archive.tar"

#; configure yadm to use T_GPG_PROGRAM
git config --file="$T_YADM_CONFIG" yadm.gpg-program "$T_GPG_PROGRAM"
}

teardown() {
Expand All @@ -70,13 +79,13 @@ function validate_archive() {
if [ "$1" = "symmetric" ]; then
expect <<EOF >/dev/null
set timeout 2;
spawn bash -c "(gpg -q -d '$T_YADM_ARCHIVE' || echo 1) | tar t | sort > $T_TMP/archive_list"
spawn bash -c "($T_GPG_PROGRAM -q -d '$T_YADM_ARCHIVE' || echo 1) | tar t | sort > $T_TMP/archive_list"
expect "passphrase:" {send "$T_PASSWD\n"}
expect "$"
foreach {pid spawnid os_error_flag value} [wait] break
EOF
else
gpg -q -d "$T_YADM_ARCHIVE" | tar t | sort > "$T_TMP/archive_list"
"$T_GPG_PROGRAM" -q -d "$T_YADM_ARCHIVE" | tar t | sort > "$T_TMP/archive_list"
fi

#; inventory what is expected in the archive
Expand Down

0 comments on commit e40c054

Please sign in to comment.