Update the test-suite with GPG-related entries
[stgit.git] / t / lib-gpg.sh
blob032cb0cff953e7d74501544b7e138205bd300f09
1 # Extracted from the test framework for git, adapted for StGit.
3 # We always set GNUPGHOME, even if no usable GPG was found, as
5 # - It does not hurt, and
7 # - we cannot set global environment variables in lazy prereqs because they are
8 # executed in an eval'ed subshell that changes the working directory to a
9 # temporary one.
11 GNUPGHOME="$PWD/gpghome"
12 export GNUPGHOME
14 test_lazy_prereq GPG '
15 gpg_version=$(gpg --version 2>&1)
16 test $? != 127 || exit 1
18 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
19 # the gpg version 1.0.6 did not parse trust packets correctly, so for
20 # that version, creation of signed tags using the generated key fails.
21 case "$gpg_version" in
22 "gpg (GnuPG) 1.0.6"*)
23 say "Your version of gpg (1.0.6) is too buggy for testing"
24 exit 1
27 # Available key info:
28 # * Type DSA and Elgamal, size 2048 bits, no expiration date,
29 # name and email: C O Mitter <committer@example.com>
30 # * Type RSA, size 2048 bits, no expiration date,
31 # name and email: Eris Discordia <discord@example.net>
32 # No password given, to enable non-interactive operation.
33 # To generate new key:
34 # gpg --homedir /tmp/gpghome --gen-key
35 # To write armored exported key to keyring:
36 # gpg --homedir /tmp/gpghome --export-secret-keys \
37 # --armor 0xDEADBEEF >> lib-gpg/keyring.gpg
38 # gpg --homedir /tmp/gpghome --export \
39 # --armor 0xDEADBEEF >> lib-gpg/keyring.gpg
40 # To export ownertrust:
41 # gpg --homedir /tmp/gpghome --export-ownertrust \
42 # > lib-gpg/ownertrust
43 mkdir "$GNUPGHOME" &&
44 chmod 0700 "$GNUPGHOME" &&
45 (gpgconf --kill gpg-agent || : ) &&
46 gpg --homedir "${GNUPGHOME}" --import \
47 "$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
48 gpg --homedir "${GNUPGHOME}" --import-ownertrust \
49 "$TEST_DIRECTORY"/lib-gpg/ownertrust &&
50 gpg --homedir "${GNUPGHOME}" </dev/null >/dev/null \
51 --sign -u committer@example.com
53 esac
56 sanitize_pgp() {
57 perl -ne '
58 /^-----END PGP/ and $in_pgp = 0;
59 print unless $in_pgp;
60 /^-----BEGIN PGP/ and $in_pgp = 1;