blob: 6f526c37c2776e6288a1abe5860b6a9efed25183 [file] [log] [blame]
brian m. carlsond66aeff2015-06-21 23:14:37 +00001#!/bin/sh
2
3test_description='signed tag tests'
Johannes Schindelin01dc8132020-11-18 23:44:39 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
brian m. carlsond66aeff2015-06-21 23:14:37 +00007. ./test-lib.sh
8. "$TEST_DIRECTORY/lib-gpg.sh"
9
10test_expect_success GPG 'create signed tags' '
11 echo 1 >file && git add file &&
12 test_tick && git commit -m initial &&
13 git tag -s -m initial initial &&
14 git branch side &&
15
16 echo 2 >file && test_tick && git commit -a -m second &&
17 git tag -s -m second second &&
18
19 git checkout side &&
20 echo 3 >elif && git add elif &&
21 test_tick && git commit -m "third on side" &&
22
Johannes Schindelin01dc8132020-11-18 23:44:39 +000023 git checkout main &&
brian m. carlsond66aeff2015-06-21 23:14:37 +000024 test_tick && git merge -S side &&
25 git tag -s -m merge merge &&
26
27 echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
28 git tag -a -m fourth-unsigned fourth-unsigned &&
29
30 test_tick && git commit --amend -S -m "fourth signed" &&
31 git tag -s -m fourth fourth-signed &&
32
33 echo 5 >file && test_tick && git commit -a -m "fifth" &&
34 git tag fifth-unsigned &&
35
36 git config commit.gpgsign true &&
37 echo 6 >file && test_tick && git commit -a -m "sixth" &&
38 git tag -a -m sixth sixth-unsigned &&
39
40 test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
41 git tag -m seventh -s seventh-signed &&
42
43 echo 8 >file && test_tick && git commit -a -m eighth &&
44 git tag -uB7227189 -m eighth eighth-signed-alt
45'
46
Henning Schild53fc9992018-07-20 10:28:07 +020047test_expect_success GPGSM 'create signed tags x509 ' '
48 test_config gpg.format x509 &&
49 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
Elijah Newrenaa74be32019-11-05 17:07:27 +000050 echo 9 >file && test_tick && git commit -a -m "ninth gpgsm-signed" &&
51 git tag -s -m ninth ninth-signed-x509
Henning Schild53fc9992018-07-20 10:28:07 +020052'
53
brian m. carlsond66aeff2015-06-21 23:14:37 +000054test_expect_success GPG 'verify and show signatures' '
55 (
56 for tag in initial second merge fourth-signed sixth-signed seventh-signed
57 do
58 git verify-tag $tag 2>actual &&
59 grep "Good signature from" actual &&
60 ! grep "BAD signature from" actual &&
61 echo $tag OK || exit 1
62 done
63 ) &&
64 (
65 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
66 do
67 test_must_fail git verify-tag $tag 2>actual &&
68 ! grep "Good signature from" actual &&
69 ! grep "BAD signature from" actual &&
70 echo $tag OK || exit 1
71 done
72 ) &&
73 (
74 for tag in eighth-signed-alt
75 do
76 git verify-tag $tag 2>actual &&
77 grep "Good signature from" actual &&
78 ! grep "BAD signature from" actual &&
79 grep "not certified" actual &&
80 echo $tag OK || exit 1
81 done
82 )
83'
84
Henning Schild53fc9992018-07-20 10:28:07 +020085test_expect_success GPGSM 'verify and show signatures x509' '
Elijah Newrenaa74be32019-11-05 17:07:27 +000086 git verify-tag ninth-signed-x509 2>actual &&
Henning Schild53fc9992018-07-20 10:28:07 +020087 grep "Good signature from" actual &&
88 ! grep "BAD signature from" actual &&
Elijah Newrenaa74be32019-11-05 17:07:27 +000089 echo ninth-signed-x509 OK
Henning Schild53fc9992018-07-20 10:28:07 +020090'
91
Hans Jerry Illikainen54887b42019-12-27 13:55:57 +000092test_expect_success GPGSM 'verify and show signatures x509 with low minTrustLevel' '
93 test_config gpg.minTrustLevel undefined &&
94 git verify-tag ninth-signed-x509 2>actual &&
95 grep "Good signature from" actual &&
96 ! grep "BAD signature from" actual &&
97 echo ninth-signed-x509 OK
98'
99
100test_expect_success GPGSM 'verify and show signatures x509 with matching minTrustLevel' '
101 test_config gpg.minTrustLevel fully &&
102 git verify-tag ninth-signed-x509 2>actual &&
103 grep "Good signature from" actual &&
104 ! grep "BAD signature from" actual &&
105 echo ninth-signed-x509 OK
106'
107
108test_expect_success GPGSM 'verify and show signatures x509 with high minTrustLevel' '
109 test_config gpg.minTrustLevel ultimate &&
110 test_must_fail git verify-tag ninth-signed-x509 2>actual &&
111 grep "Good signature from" actual &&
112 ! grep "BAD signature from" actual &&
113 echo ninth-signed-x509 OK
114'
115
brian m. carlsond66aeff2015-06-21 23:14:37 +0000116test_expect_success GPG 'detect fudged signature' '
117 git cat-file tag seventh-signed >raw &&
Jeff Kingad5dfea2023-01-18 15:36:22 -0500118 sed -e "/^tag / s/seventh/7th-forged/" raw >forged1 &&
brian m. carlsond66aeff2015-06-21 23:14:37 +0000119 git hash-object -w -t tag forged1 >forged1.tag &&
120 test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
121 grep "BAD signature from" actual1 &&
122 ! grep "Good signature from" actual1
123'
124
brian m. carlsone18443e2015-06-21 23:14:43 +0000125test_expect_success GPG 'verify signatures with --raw' '
126 (
127 for tag in initial second merge fourth-signed sixth-signed seventh-signed
128 do
129 git verify-tag --raw $tag 2>actual &&
130 grep "GOODSIG" actual &&
131 ! grep "BADSIG" actual &&
132 echo $tag OK || exit 1
133 done
134 ) &&
135 (
136 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
137 do
138 test_must_fail git verify-tag --raw $tag 2>actual &&
139 ! grep "GOODSIG" actual &&
140 ! grep "BADSIG" actual &&
141 echo $tag OK || exit 1
142 done
143 ) &&
144 (
145 for tag in eighth-signed-alt
146 do
147 git verify-tag --raw $tag 2>actual &&
148 grep "GOODSIG" actual &&
149 ! grep "BADSIG" actual &&
150 grep "TRUST_UNDEFINED" actual &&
151 echo $tag OK || exit 1
152 done
153 )
154'
155
Henning Schild53fc9992018-07-20 10:28:07 +0200156test_expect_success GPGSM 'verify signatures with --raw x509' '
Elijah Newrenaa74be32019-11-05 17:07:27 +0000157 git verify-tag --raw ninth-signed-x509 2>actual &&
Henning Schild53fc9992018-07-20 10:28:07 +0200158 grep "GOODSIG" actual &&
159 ! grep "BADSIG" actual &&
Elijah Newrenaa74be32019-11-05 17:07:27 +0000160 echo ninth-signed-x509 OK
Henning Schild53fc9992018-07-20 10:28:07 +0200161'
162
Santiago Torres3e1e7452016-04-17 18:26:57 -0400163test_expect_success GPG 'verify multiple tags' '
164 tags="fourth-signed sixth-signed seventh-signed" &&
165 for i in $tags
166 do
167 git verify-tag -v --raw $i || return 1
168 done >expect.stdout 2>expect.stderr.1 &&
169 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
170 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
171 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
172 test_cmp expect.stdout actual.stdout &&
173 test_cmp expect.stderr actual.stderr
174'
175
Henning Schild53fc9992018-07-20 10:28:07 +0200176test_expect_success GPGSM 'verify multiple tags x509' '
Elijah Newrenaa74be32019-11-05 17:07:27 +0000177 tags="seventh-signed ninth-signed-x509" &&
Henning Schild53fc9992018-07-20 10:28:07 +0200178 for i in $tags
179 do
180 git verify-tag -v --raw $i || return 1
181 done >expect.stdout 2>expect.stderr.1 &&
182 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
183 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
184 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
185 test_cmp expect.stdout actual.stdout &&
186 test_cmp expect.stderr actual.stderr
187'
188
Santiago Torresb42ca352017-03-23 18:28:47 -0400189test_expect_success GPG 'verifying tag with --format' '
190 cat >expect <<-\EOF &&
Santiago Torres02c54332017-01-17 18:37:22 -0500191 tagname : fourth-signed
Santiago Torresb42ca352017-03-23 18:28:47 -0400192 EOF
Santiago Torres02c54332017-01-17 18:37:22 -0500193 git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
194 test_cmp expect actual
195'
196
ZheNing Hub9dee072021-07-26 03:26:50 +0000197test_expect_success GPG 'verifying tag with --format="%(rest)" must fail' '
198 test_must_fail git verify-tag --format="%(rest)" "fourth-signed"
199'
200
Santiago Torresb42ca352017-03-23 18:28:47 -0400201test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
Santiago Torres02c54332017-01-17 18:37:22 -0500202 test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000203 test_must_be_empty actual-forged
Santiago Torres02c54332017-01-17 18:37:22 -0500204'
205
brian m. carlsond66aeff2015-06-21 23:14:37 +0000206test_done