Skip to content

Commit f1e3df3

Browse files
illikainengitster
authored andcommitted
t: increase test coverage of signature verification output
There weren't any tests for unsuccessful signature verification of signed merge tags shown in 'git log'. There also weren't any tests for the GPG output from 'git fmt-merge-msg'. This was noticed while investigating a buggy refactor that slipped through the test suite; see commit 72b006f. This commit adds signature verification tests to the 'log' and 'fmt-merge-msg' builtins. Thanks to Linus Torvalds for reporting and finding the (now reverted) commit that introduced the regression. Note that the "log --show-signature for merged tag with GPG failure" test case is really hacky. It relies on an implementation detail of verify_signed_buffer() -- namely, it assumes that the signature is written to a temporary file whose path is under TMPDIR. The rationale for that test case is to check whether the code path that yields the "No signature" message is reachable on failure. The functionality in log-tree.c that may show this message does some pre-parsing of a possible signature that prevents the GPG interface from being invoked if a signature is actually missing. And I haven't been able to construct a signature that both 1. satisfies that pre-processing, and 2. causes GPG to fail without any sort of output on stderr along the lines of "this is a bogus/corrupt/... signature" (the "No signature" message should only be shown if GPG produce no output). Signed-off-by: Hans Jerry Illikainen <[email protected]> [jc: fixed missing test title noticed by Dscho] Signed-off-by: Junio C Hamano <[email protected]>
1 parent e63cefb commit f1e3df3

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

t/t4202-log.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,66 @@ test_expect_success GPG 'log --graph --show-signature for merged tag' '
16071607
grep "^| | gpg: Good signature" actual
16081608
'
16091609

1610+
test_expect_success GPG 'log --graph --show-signature for merged tag with missing key' '
1611+
test_when_finished "git reset --hard && git checkout master" &&
1612+
git checkout -b plain-nokey master &&
1613+
echo aaa >bar &&
1614+
git add bar &&
1615+
git commit -m bar_commit &&
1616+
git checkout -b tagged-nokey master &&
1617+
echo bbb >baz &&
1618+
git add baz &&
1619+
git commit -m baz_commit &&
1620+
git tag -s -m signed_tag_msg signed_tag_nokey &&
1621+
git checkout plain-nokey &&
1622+
git merge --no-ff -m msg signed_tag_nokey &&
1623+
GNUPGHOME=. git log --graph --show-signature -n1 plain-nokey >actual &&
1624+
grep "^|\\\ merged tag" actual &&
1625+
grep "^| | gpg: Signature made" actual &&
1626+
grep "^| | gpg: Can'"'"'t check signature: \(public key not found\|No public key\)" actual
1627+
'
1628+
1629+
test_expect_success GPG 'log --graph --show-signature for merged tag with bad signature' '
1630+
test_when_finished "git reset --hard && git checkout master" &&
1631+
git checkout -b plain-bad master &&
1632+
echo aaa >bar &&
1633+
git add bar &&
1634+
git commit -m bar_commit &&
1635+
git checkout -b tagged-bad master &&
1636+
echo bbb >baz &&
1637+
git add baz &&
1638+
git commit -m baz_commit &&
1639+
git tag -s -m signed_tag_msg signed_tag_bad &&
1640+
git cat-file tag signed_tag_bad >raw &&
1641+
sed -e "s/signed_tag_msg/forged/" raw >forged &&
1642+
git hash-object -w -t tag forged >forged.tag &&
1643+
git checkout plain-bad &&
1644+
git merge --no-ff -m msg "$(cat forged.tag)" &&
1645+
git log --graph --show-signature -n1 plain-bad >actual &&
1646+
grep "^|\\\ merged tag" actual &&
1647+
grep "^| | gpg: Signature made" actual &&
1648+
grep "^| | gpg: BAD signature from" actual
1649+
'
1650+
1651+
test_expect_success GPG 'log --show-signature for merged tag with GPG failure' '
1652+
test_when_finished "git reset --hard && git checkout master" &&
1653+
git checkout -b plain-fail master &&
1654+
echo aaa >bar &&
1655+
git add bar &&
1656+
git commit -m bar_commit &&
1657+
git checkout -b tagged-fail master &&
1658+
echo bbb >baz &&
1659+
git add baz &&
1660+
git commit -m baz_commit &&
1661+
git tag -s -m signed_tag_msg signed_tag_fail &&
1662+
git checkout plain-fail &&
1663+
git merge --no-ff -m msg signed_tag_fail &&
1664+
TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1665+
grep "^merged tag" actual &&
1666+
grep "^No signature" actual &&
1667+
! grep "^gpg: Signature made" actual
1668+
'
1669+
16101670
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '
16111671
test_when_finished "git reset --hard && git checkout master" &&
16121672
test_config gpg.format x509 &&
@@ -1628,6 +1688,51 @@ test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '
16281688
grep "^| | gpgsm: Good signature" actual
16291689
'
16301690

1691+
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 missing key' '
1692+
test_when_finished "git reset --hard && git checkout master" &&
1693+
test_config gpg.format x509 &&
1694+
test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1695+
git checkout -b plain-x509-nokey master &&
1696+
echo aaa >bar &&
1697+
git add bar &&
1698+
git commit -m bar_commit &&
1699+
git checkout -b tagged-x509-nokey master &&
1700+
echo bbb >baz &&
1701+
git add baz &&
1702+
git commit -m baz_commit &&
1703+
git tag -s -m signed_tag_msg signed_tag_x509_nokey &&
1704+
git checkout plain-x509-nokey &&
1705+
git merge --no-ff -m msg signed_tag_x509_nokey &&
1706+
GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey >actual &&
1707+
grep "^|\\\ merged tag" actual &&
1708+
grep "^| | gpgsm: certificate not found" actual
1709+
'
1710+
1711+
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 bad signature' '
1712+
test_when_finished "git reset --hard && git checkout master" &&
1713+
test_config gpg.format x509 &&
1714+
test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1715+
git checkout -b plain-x509-bad master &&
1716+
echo aaa >bar &&
1717+
git add bar &&
1718+
git commit -m bar_commit &&
1719+
git checkout -b tagged-x509-bad master &&
1720+
echo bbb >baz &&
1721+
git add baz &&
1722+
git commit -m baz_commit &&
1723+
git tag -s -m signed_tag_msg signed_tag_x509_bad &&
1724+
git cat-file tag signed_tag_x509_bad >raw &&
1725+
sed -e "s/signed_tag_msg/forged/" raw >forged &&
1726+
git hash-object -w -t tag forged >forged.tag &&
1727+
git checkout plain-x509-bad &&
1728+
git merge --no-ff -m msg "$(cat forged.tag)" &&
1729+
git log --graph --show-signature -n1 plain-x509-bad >actual &&
1730+
grep "^|\\\ merged tag" actual &&
1731+
grep "^| | gpgsm: Signature made" actual &&
1732+
grep "^| | gpgsm: invalid signature" actual
1733+
'
1734+
1735+
16311736
test_expect_success GPG '--no-show-signature overrides --show-signature' '
16321737
git log -1 --show-signature --no-show-signature signed >actual &&
16331738
! grep "^gpg:" actual

t/t6200-fmt-merge-msg.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
test_description='fmt-merge-msg test'
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY/lib-gpg.sh"
910

1011
test_expect_success setup '
1112
echo one >one &&
@@ -73,6 +74,10 @@ test_expect_success setup '
7374
apos="'\''"
7475
'
7576

77+
test_expect_success GPG 'set up a signed tag' '
78+
git tag -s -m signed-tag-msg signed-good-tag left
79+
'
80+
7681
test_expect_success 'message for merging local branch' '
7782
echo "Merge branch ${apos}left${apos}" >expected &&
7883
@@ -83,6 +88,24 @@ test_expect_success 'message for merging local branch' '
8388
test_cmp expected actual
8489
'
8590

91+
test_expect_success GPG 'message for merging local tag signed by good key' '
92+
git checkout master &&
93+
git fetch . signed-good-tag &&
94+
git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
95+
grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
96+
grep "^# gpg: Signature made" actual &&
97+
grep "^# gpg: Good signature from" actual
98+
'
99+
100+
test_expect_success GPG 'message for merging local tag signed by unknown key' '
101+
git checkout master &&
102+
git fetch . signed-good-tag &&
103+
GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
104+
grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
105+
grep "^# gpg: Signature made" actual &&
106+
grep "^# gpg: Can${apos}t check signature: \(public key not found\|No public key\)" actual
107+
'
108+
86109
test_expect_success 'message for merging external branch' '
87110
echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
88111

0 commit comments

Comments
 (0)