Skip to content

Commit e204a16

Browse files
chriscoolgitster
authored andcommitted
lib-gpg: allow tests with GPGSM or GPGSSH prereq first
When the 'GPG' prereq is lazily tested, `mkdir "$GNUPGHOME"` could fail if the "$GNUPGHOME" directory already exists. This can happen if the 'GPGSM' or the 'GPGSSH' prereq has been lazily tested before as they already create "$GNUPGHOME". To allow the GPGSM or the GPGSSH prereq to appear before the GPG prereq in some test scripts, let's refactor the creation and setup of the "$GNUPGHOME"` directory in a new prepare_gnupghome() function that uses `mkdir -p "$GNUPGHOME"`. This will be useful in a following commit. Unfortunately the new prepare_gnupghome() function cannot be used when lazily testing the GPG2 prereq, because that would expose existing, hidden bugs in "t1016-compatObjectFormat.sh", so let's just document that with a NEEDSWORK comment. Helped-by: Todd Zullinger <[email protected]> Helped-by: Collin Funk <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db67409 commit e204a16

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

t/lib-gpg.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
GNUPGHOME="$(pwd)/gpghome"
1010
export GNUPGHOME
1111

12+
# All the "test_lazy_prereq GPG*" below should use
13+
# `prepare_gnupghome()` either directly or through a call to
14+
# `test_have_prereq GPG*`. That's because `gpg` and `gpgsm`
15+
# only create the directory specified using "$GNUPGHOME" or
16+
# `--homedir` if it's the default (usually "~/.gnupg").
17+
prepare_gnupghome() {
18+
mkdir -p "$GNUPGHOME" &&
19+
chmod 0700 "$GNUPGHOME"
20+
}
21+
1222
test_lazy_prereq GPG '
1323
gpg_version=$(gpg --version 2>&1)
1424
test $? != 127 || exit 1
@@ -38,8 +48,7 @@ test_lazy_prereq GPG '
3848
# To export ownertrust:
3949
# gpg --homedir /tmp/gpghome --export-ownertrust \
4050
# > lib-gpg/ownertrust
41-
mkdir "$GNUPGHOME" &&
42-
chmod 0700 "$GNUPGHOME" &&
51+
prepare_gnupghome &&
4352
(gpgconf --kill all || : ) &&
4453
gpg --homedir "${GNUPGHOME}" --import \
4554
"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
@@ -63,6 +72,14 @@ test_lazy_prereq GPG2 '
6372
;;
6473
*)
6574
(gpgconf --kill all || : ) &&
75+
76+
# NEEDSWORK: prepare_gnupghome() should definitely be
77+
# called here, but it looks like it exposes a
78+
# pre-existing, hidden bug by allowing some tests in
79+
# t1016-compatObjectFormat.sh to run instead of being
80+
# skipped. See:
81+
# https://lore.kernel.org/git/[email protected]/
82+
6683
gpg --homedir "${GNUPGHOME}" --import \
6784
"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
6885
gpg --homedir "${GNUPGHOME}" --import-ownertrust \
@@ -132,8 +149,7 @@ test_lazy_prereq GPGSSH '
132149
test $? = 0 || exit 1;
133150
134151
# Setup some keys and an allowed signers file
135-
mkdir -p "${GNUPGHOME}" &&
136-
chmod 0700 "${GNUPGHOME}" &&
152+
prepare_gnupghome &&
137153
(setfacl -k "${GNUPGHOME}" 2>/dev/null || true) &&
138154
ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null &&
139155
ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null &&

0 commit comments

Comments
 (0)