Raw
1 #!/bin/sh
2
3 test_description='signed tag tests'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY/lib-gpg.sh"
9
10 test_expect_success GPG 'verify-tag does not crash with -h' '
11 git verify-tag -h >usage &&
12 test_grep "[Uu]sage: git verify-tag " usage &&
13 nongit git verify-tag -h >usage &&
14 test_grep "[Uu]sage: git verify-tag " usage
15 '
16
17 test_expect_success GPG 'create signed tags' '
18 echo 1 >file && git add file &&
19 test_tick && git commit -m initial &&
20 git tag -s -m initial initial &&
21 git branch side &&
22
23 echo 2 >file && test_tick && git commit -a -m second &&
24 git tag -s -m second second &&
25
26 git checkout side &&
27 echo 3 >elif && git add elif &&
28 test_tick && git commit -m "third on side" &&
29
30 git checkout main &&
31 test_tick && git merge -S side &&
32 git tag -s -m merge merge &&
33
34 echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
35 git tag -a -m fourth-unsigned fourth-unsigned &&
36
37 test_tick && git commit --amend -S -m "fourth signed" &&
38 git tag -s -m fourth fourth-signed &&
39
40 echo 5 >file && test_tick && git commit -a -m "fifth" &&
41 git tag fifth-unsigned &&
42
43 git config commit.gpgsign true &&
44 echo 6 >file && test_tick && git commit -a -m "sixth" &&
45 git tag -a -m sixth sixth-unsigned &&
46
47 test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
48 git tag -m seventh -s seventh-signed &&
49
50 echo 8 >file && test_tick && git commit -a -m eighth &&
51 git tag -uB7227189 -m eighth eighth-signed-alt
52 '
53
54 test_expect_success GPGSM 'create signed tags x509 ' '
55 test_config gpg.format x509 &&
56 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
57 echo 9 >file && test_tick && git commit -a -m "ninth gpgsm-signed" &&
58 git tag -s -m ninth ninth-signed-x509
59 '
60
61 test_expect_success GPG 'verify and show signatures' '
62 (
63 for tag in initial second merge fourth-signed sixth-signed seventh-signed
64 do
65 git verify-tag $tag 2>actual &&
66 test_grep "Good signature from" actual &&
67 test_grep ! "BAD signature from" actual &&
68 echo $tag OK || exit 1
69 done
70 ) &&
71 (
72 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
73 do
74 test_must_fail git verify-tag $tag 2>actual &&
75 test_grep ! "Good signature from" actual &&
76 test_grep ! "BAD signature from" actual &&
77 echo $tag OK || exit 1
78 done
79 ) &&
80 (
81 for tag in eighth-signed-alt
82 do
83 git verify-tag $tag 2>actual &&
84 test_grep "Good signature from" actual &&
85 test_grep ! "BAD signature from" actual &&
86 test_grep "not certified" actual &&
87 echo $tag OK || exit 1
88 done
89 )
90 '
91
92 test_expect_success GPGSM 'verify and show signatures x509' '
93 git verify-tag ninth-signed-x509 2>actual &&
94 test_grep "Good signature from" actual &&
95 test_grep ! "BAD signature from" actual &&
96 echo ninth-signed-x509 OK
97 '
98
99 test_expect_success GPGSM 'verify and show signatures x509 with low minTrustLevel' '
100 test_config gpg.minTrustLevel undefined &&
101 git verify-tag ninth-signed-x509 2>actual &&
102 test_grep "Good signature from" actual &&
103 test_grep ! "BAD signature from" actual &&
104 echo ninth-signed-x509 OK
105 '
106
107 test_expect_success GPGSM 'verify and show signatures x509 with matching minTrustLevel' '
108 test_config gpg.minTrustLevel fully &&
109 git verify-tag ninth-signed-x509 2>actual &&
110 test_grep "Good signature from" actual &&
111 test_grep ! "BAD signature from" actual &&
112 echo ninth-signed-x509 OK
113 '
114
115 test_expect_success GPGSM 'verify and show signatures x509 with high minTrustLevel' '
116 test_config gpg.minTrustLevel ultimate &&
117 test_must_fail git verify-tag ninth-signed-x509 2>actual &&
118 test_grep "Good signature from" actual &&
119 test_grep ! "BAD signature from" actual &&
120 echo ninth-signed-x509 OK
121 '
122
123 test_expect_success GPG 'detect fudged signature' '
124 git cat-file tag seventh-signed >raw &&
125 sed -e "/^tag / s/seventh/7th-forged/" raw >forged1 &&
126 git hash-object -w -t tag forged1 >forged1.tag &&
127 test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
128 test_grep "BAD signature from" actual1 &&
129 test_grep ! "Good signature from" actual1
130 '
131
132 test_expect_success GPG 'verify signatures with --raw' '
133 (
134 for tag in initial second merge fourth-signed sixth-signed seventh-signed
135 do
136 git verify-tag --raw $tag 2>actual &&
137 test_grep "GOODSIG" actual &&
138 test_grep ! "BADSIG" actual &&
139 echo $tag OK || exit 1
140 done
141 ) &&
142 (
143 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
144 do
145 test_must_fail git verify-tag --raw $tag 2>actual &&
146 test_grep ! "GOODSIG" actual &&
147 test_grep ! "BADSIG" actual &&
148 echo $tag OK || exit 1
149 done
150 ) &&
151 (
152 for tag in eighth-signed-alt
153 do
154 git verify-tag --raw $tag 2>actual &&
155 test_grep "GOODSIG" actual &&
156 test_grep ! "BADSIG" actual &&
157 test_grep "TRUST_UNDEFINED" actual &&
158 echo $tag OK || exit 1
159 done
160 )
161 '
162
163 test_expect_success GPGSM 'verify signatures with --raw x509' '
164 git verify-tag --raw ninth-signed-x509 2>actual &&
165 test_grep "GOODSIG" actual &&
166 test_grep ! "BADSIG" actual &&
167 echo ninth-signed-x509 OK
168 '
169
170 test_expect_success GPG 'verify multiple tags' '
171 tags="fourth-signed sixth-signed seventh-signed" &&
172 for i in $tags
173 do
174 git verify-tag -v --raw $i || return 1
175 done >expect.stdout 2>expect.stderr.1 &&
176 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
177 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
178 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
179 test_cmp expect.stdout actual.stdout &&
180 test_cmp expect.stderr actual.stderr
181 '
182
183 test_expect_success GPGSM 'verify multiple tags x509' '
184 tags="seventh-signed ninth-signed-x509" &&
185 for i in $tags
186 do
187 git verify-tag -v --raw $i || return 1
188 done >expect.stdout 2>expect.stderr.1 &&
189 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
190 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
191 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
192 test_cmp expect.stdout actual.stdout &&
193 test_cmp expect.stderr actual.stderr
194 '
195
196 test_expect_success GPG 'verifying tag with --format' '
197 cat >expect <<-\EOF &&
198 tagname : fourth-signed
199 EOF
200 git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
201 test_cmp expect actual
202 '
203
204 test_expect_success GPG 'verifying tag with --format="%(rest)" must fail' '
205 test_must_fail git verify-tag --format="%(rest)" "fourth-signed"
206 '
207
208 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
209 test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
210 test_must_be_empty actual-forged
211 '
212
213 test_done