gpg-interface/gpgsm: fix for v2.3

Checking if signing was successful will now accept '[GNUPG]: SIG_CREATED' on the beginning of the first or any subsequent line. Not just explictly the second one anymore. Gpgsm v2.3 changed its output when listing keys from `fingerprint` to `sha1/2 fpr`. This leads to the gpgsm tests silently not being executed because of a failed prerequisite. Switch to gpg's `--with-colons` output format when evaluating test prerequisites to make parsing more robust. This also allows us to combine the existing grep/cut/tr/echo pipe for writing the trustlist.txt into a single awk expression. Adjust error message checking in test for v2.3 specific output changes. Helped-By: Junio C Hamano <gitster@pobox.com> Helped-By: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Fabian Stelzer committed Mar 4, 2022 at 11:25 UTC a075e79d2c036e8e41900cfcb2177d75b92758c8
3 files changed +13 -7
gpg-interface.c
+8 -1
@@ -920,6 +920,7 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
920 struct child_process gpg = CHILD_PROCESS_INIT;
921 int ret;
922 size_t bottom;
923 + const char *cp;
924 struct strbuf gpg_status = STRBUF_INIT;
925
926 strvec_pushl(&gpg.args,
@@ -939,7 +940,13 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
940 signature, 1024, &gpg_status, 0);
941 sigchain_pop(SIGPIPE);
942
942 - ret |= !strstr(gpg_status.buf, "\n[GNUPG:] SIG_CREATED ");
943 + for (cp = gpg_status.buf;
944 + cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
945 + cp++) {
946 + if (cp == gpg_status.buf || cp[-1] == '\n')
947 + break; /* found */
948 + }
949 + ret |= !cp;
950 strbuf_release(&gpg_status);
951 if (ret)
952 return error(_("gpg failed to sign the data"));
t/lib-gpg.sh
+3 -5
@@ -72,12 +72,10 @@ test_lazy_prereq GPGSM '
72 --passphrase-fd 0 --pinentry-mode loopback \
73 --import "$TEST_DIRECTORY"/lib-gpg/gpgsm_cert.p12 &&
74
75 - gpgsm --homedir "${GNUPGHOME}" -K |
76 - grep fingerprint: |
77 - cut -d" " -f4 |
78 - tr -d "\\n" >"${GNUPGHOME}/trustlist.txt" &&
75 + gpgsm --homedir "${GNUPGHOME}" -K --with-colons |
76 + awk -F ":" "/^fpr:/ {printf \"%s S relax\\n\", \$10}" \
77 + >"${GNUPGHOME}/trustlist.txt" &&
78
80 - echo " S relax" >>"${GNUPGHOME}/trustlist.txt" &&
79 echo hello | gpgsm --homedir "${GNUPGHOME}" >/dev/null \
80 -u committer@example.com -o /dev/null --sign -
81 '
t/t4202-log.sh
+2 -1
@@ -1931,7 +1931,8 @@ test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 miss
1931 git merge --no-ff -m msg signed_tag_x509_nokey &&
1932 GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey >actual &&
1933 grep "^|\\\ merged tag" actual &&
1934 - grep "^| | gpgsm: certificate not found" actual
1934 + grep -e "^| | gpgsm: certificate not found" \
1935 + -e "^| | gpgsm: failed to find the certificate: Not found" actual
1936 '
1937
1938 test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 bad signature' '