]>
Commit | Line | Data |
---|---|---|
446c6fae RJ |
1 | #!/bin/sh |
2 | # | |
3 | # | |
4 | ||
0cb0e143 | 5 | test_description='git mktag: tag object verify test' |
446c6fae RJ |
6 | |
7 | . ./test-lib.sh | |
8 | ||
9 | ########################################################### | |
10 | # check the tag.sig file, expecting verify_tag() to fail, | |
11 | # and checking that the error message matches the pattern | |
12 | # given in the expect.pat file. | |
13 | ||
14 | check_verify_failure () { | |
e9b20943 JH |
15 | expect="$2" |
16 | test_expect_success "$1" ' | |
aba5377f | 17 | test_must_fail git mktag <tag.sig 2>message && |
525d4615 | 18 | grep "$expect" message |
e9b20943 | 19 | ' |
446c6fae RJ |
20 | } |
21 | ||
ca9a1ed9 ÆAB |
22 | test_expect_mktag_success() { |
23 | test_expect_success "$1" ' | |
24 | git hash-object -t tag -w --stdin <tag.sig >expected && | |
25 | git fsck --strict && | |
26 | ||
27 | git mktag <tag.sig >hash && | |
28 | test_cmp expected hash && | |
29 | test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" && | |
30 | git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) && | |
31 | git fsck --strict | |
32 | ' | |
33 | } | |
34 | ||
446c6fae RJ |
35 | ########################################################### |
36 | # first create a commit, so we have a valid object/type | |
37 | # for the tag. | |
4a45f7dd | 38 | test_expect_success 'setup' ' |
b5ca549c | 39 | test_commit A && |
4a45f7dd BG |
40 | head=$(git rev-parse --verify HEAD) |
41 | ' | |
446c6fae RJ |
42 | |
43 | ############################################################ | |
44 | # 1. length check | |
45 | ||
46 | cat >tag.sig <<EOF | |
47 | too short for a tag | |
48 | EOF | |
49 | ||
e9b20943 JH |
50 | check_verify_failure 'Tag object length check' \ |
51 | '^error: .*size wrong.*$' | |
446c6fae RJ |
52 | |
53 | ############################################################ | |
54 | # 2. object line label check | |
55 | ||
56 | cat >tag.sig <<EOF | |
0d35ccb5 | 57 | xxxxxx $head |
446c6fae RJ |
58 | type tag |
59 | tag mytag | |
e0aaf781 BC |
60 | tagger . <> 0 +0000 |
61 | ||
446c6fae RJ |
62 | EOF |
63 | ||
e9b20943 | 64 | check_verify_failure '"object" line label check' '^error: char0: .*"object "$' |
446c6fae RJ |
65 | |
66 | ############################################################ | |
0d35ccb5 | 67 | # 3. object line hash check |
446c6fae RJ |
68 | |
69 | cat >tag.sig <<EOF | |
0d35ccb5 | 70 | object $(echo $head | tr 0-9a-f z) |
446c6fae RJ |
71 | type tag |
72 | tag mytag | |
e0aaf781 BC |
73 | tagger . <> 0 +0000 |
74 | ||
446c6fae RJ |
75 | EOF |
76 | ||
e9b20943 | 77 | check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$' |
446c6fae RJ |
78 | |
79 | ############################################################ | |
80 | # 4. type line label check | |
81 | ||
82 | cat >tag.sig <<EOF | |
acb49d1c | 83 | object $head |
446c6fae RJ |
84 | xxxx tag |
85 | tag mytag | |
e0aaf781 BC |
86 | tagger . <> 0 +0000 |
87 | ||
446c6fae RJ |
88 | EOF |
89 | ||
acb49d1c | 90 | check_verify_failure '"type" line label check' '^error: char.*: .*"\\ntype "$' |
446c6fae RJ |
91 | |
92 | ############################################################ | |
93 | # 5. type line eol check | |
94 | ||
acb49d1c | 95 | echo "object $head" >tag.sig |
2aad957a | 96 | printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig |
446c6fae | 97 | |
acb49d1c | 98 | check_verify_failure '"type" line eol check' '^error: char.*: .*"\\n"$' |
446c6fae RJ |
99 | |
100 | ############################################################ | |
101 | # 6. tag line label check #1 | |
102 | ||
103 | cat >tag.sig <<EOF | |
acb49d1c | 104 | object $head |
446c6fae RJ |
105 | type tag |
106 | xxx mytag | |
e0aaf781 BC |
107 | tagger . <> 0 +0000 |
108 | ||
446c6fae RJ |
109 | EOF |
110 | ||
e9b20943 | 111 | check_verify_failure '"tag" line label check #1' \ |
acb49d1c | 112 | '^error: char.*: no "tag " found$' |
446c6fae RJ |
113 | |
114 | ############################################################ | |
115 | # 7. tag line label check #2 | |
116 | ||
117 | cat >tag.sig <<EOF | |
acb49d1c | 118 | object $head |
446c6fae RJ |
119 | type taggggggggggggggggggggggggggggggg |
120 | tag | |
121 | EOF | |
122 | ||
e9b20943 | 123 | check_verify_failure '"tag" line label check #2' \ |
acb49d1c | 124 | '^error: char.*: no "tag " found$' |
446c6fae RJ |
125 | |
126 | ############################################################ | |
127 | # 8. type line type-name length check | |
128 | ||
129 | cat >tag.sig <<EOF | |
acb49d1c | 130 | object $head |
446c6fae RJ |
131 | type taggggggggggggggggggggggggggggggg |
132 | tag mytag | |
133 | EOF | |
134 | ||
e9b20943 | 135 | check_verify_failure '"type" line type-name length check' \ |
acb49d1c | 136 | '^error: char.*: type too long$' |
446c6fae RJ |
137 | |
138 | ############################################################ | |
139 | # 9. verify object (SHA1/type) check | |
140 | ||
141 | cat >tag.sig <<EOF | |
acb49d1c | 142 | object $(test_oid deadbeef) |
446c6fae RJ |
143 | type tagggg |
144 | tag mytag | |
e0aaf781 BC |
145 | tagger . <> 0 +0000 |
146 | ||
446c6fae RJ |
147 | EOF |
148 | ||
e9b20943 JH |
149 | check_verify_failure 'verify object (SHA1/type) check' \ |
150 | '^error: char7: could not verify object.*$' | |
446c6fae RJ |
151 | |
152 | ############################################################ | |
153 | # 10. verify tag-name check | |
154 | ||
155 | cat >tag.sig <<EOF | |
156 | object $head | |
157 | type commit | |
158 | tag my tag | |
e0aaf781 BC |
159 | tagger . <> 0 +0000 |
160 | ||
446c6fae RJ |
161 | EOF |
162 | ||
e9b20943 | 163 | check_verify_failure 'verify tag-name check' \ |
acb49d1c | 164 | '^error: char.*: could not verify tag name$' |
446c6fae RJ |
165 | |
166 | ############################################################ | |
3dff5379 | 167 | # 11. tagger line label check #1 |
446c6fae RJ |
168 | |
169 | cat >tag.sig <<EOF | |
170 | object $head | |
171 | type commit | |
172 | tag mytag | |
e0aaf781 BC |
173 | |
174 | This is filler | |
446c6fae RJ |
175 | EOF |
176 | ||
e9b20943 | 177 | check_verify_failure '"tagger" line label check #1' \ |
acb49d1c | 178 | '^error: char.*: could not find "tagger "$' |
446c6fae RJ |
179 | |
180 | ############################################################ | |
3dff5379 | 181 | # 12. tagger line label check #2 |
446c6fae RJ |
182 | |
183 | cat >tag.sig <<EOF | |
184 | object $head | |
185 | type commit | |
186 | tag mytag | |
187 | tagger | |
e0aaf781 BC |
188 | |
189 | This is filler | |
446c6fae RJ |
190 | EOF |
191 | ||
e9b20943 | 192 | check_verify_failure '"tagger" line label check #2' \ |
acb49d1c | 193 | '^error: char.*: could not find "tagger "$' |
446c6fae RJ |
194 | |
195 | ############################################################ | |
ba26ab99 | 196 | # 13. disallow missing tag author name |
446c6fae RJ |
197 | |
198 | cat >tag.sig <<EOF | |
199 | object $head | |
200 | type commit | |
201 | tag mytag | |
e0aaf781 BC |
202 | tagger <> 0 +0000 |
203 | ||
204 | This is filler | |
205 | EOF | |
206 | ||
ba26ab99 | 207 | check_verify_failure 'disallow missing tag author name' \ |
acb49d1c | 208 | '^error: char.*: missing tagger name$' |
e0aaf781 BC |
209 | |
210 | ############################################################ | |
ba26ab99 | 211 | # 14. disallow missing tag author name |
e0aaf781 BC |
212 | |
213 | cat >tag.sig <<EOF | |
214 | object $head | |
215 | type commit | |
216 | tag mytag | |
217 | tagger T A Gger < | |
218 | > 0 +0000 | |
219 | ||
220 | EOF | |
221 | ||
ba26ab99 | 222 | check_verify_failure 'disallow malformed tagger' \ |
acb49d1c | 223 | '^error: char.*: malformed tagger field$' |
e0aaf781 BC |
224 | |
225 | ############################################################ | |
226 | # 15. allow empty tag email | |
227 | ||
228 | cat >tag.sig <<EOF | |
229 | object $head | |
230 | type commit | |
231 | tag mytag | |
232 | tagger T A Gger <> 0 +0000 | |
233 | ||
234 | EOF | |
235 | ||
ca9a1ed9 | 236 | test_expect_mktag_success 'allow empty tag email' |
e0aaf781 BC |
237 | |
238 | ############################################################ | |
ba26ab99 BC |
239 | # 16. disallow spaces in tag email |
240 | ||
241 | cat >tag.sig <<EOF | |
242 | object $head | |
243 | type commit | |
244 | tag mytag | |
245 | tagger T A Gger <tag ger@example.com> 0 +0000 | |
246 | ||
247 | EOF | |
248 | ||
249 | check_verify_failure 'disallow spaces in tag email' \ | |
acb49d1c | 250 | '^error: char.*: malformed tagger field$' |
ba26ab99 BC |
251 | |
252 | ############################################################ | |
253 | # 17. disallow missing tag timestamp | |
e0aaf781 | 254 | |
74f16b0c | 255 | tr '_' ' ' >tag.sig <<EOF |
e0aaf781 BC |
256 | object $head |
257 | type commit | |
258 | tag mytag | |
74f16b0c | 259 | tagger T A Gger <tagger@example.com>__ |
e0aaf781 BC |
260 | |
261 | EOF | |
262 | ||
ba26ab99 | 263 | check_verify_failure 'disallow missing tag timestamp' \ |
acb49d1c | 264 | '^error: char.*: missing tag timestamp$' |
e0aaf781 BC |
265 | |
266 | ############################################################ | |
ba26ab99 | 267 | # 18. detect invalid tag timestamp1 |
e0aaf781 BC |
268 | |
269 | cat >tag.sig <<EOF | |
270 | object $head | |
271 | type commit | |
272 | tag mytag | |
273 | tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008 | |
274 | ||
275 | EOF | |
276 | ||
ba26ab99 | 277 | check_verify_failure 'detect invalid tag timestamp1' \ |
acb49d1c | 278 | '^error: char.*: missing tag timestamp$' |
e0aaf781 BC |
279 | |
280 | ############################################################ | |
ba26ab99 BC |
281 | # 19. detect invalid tag timestamp2 |
282 | ||
283 | cat >tag.sig <<EOF | |
284 | object $head | |
285 | type commit | |
286 | tag mytag | |
287 | tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500 | |
288 | ||
289 | EOF | |
290 | ||
291 | check_verify_failure 'detect invalid tag timestamp2' \ | |
acb49d1c | 292 | '^error: char.*: malformed tag timestamp$' |
ba26ab99 BC |
293 | |
294 | ############################################################ | |
295 | # 20. detect invalid tag timezone1 | |
e0aaf781 BC |
296 | |
297 | cat >tag.sig <<EOF | |
298 | object $head | |
299 | type commit | |
300 | tag mytag | |
301 | tagger T A Gger <tagger@example.com> 1206478233 GMT | |
302 | ||
303 | EOF | |
304 | ||
ba26ab99 | 305 | check_verify_failure 'detect invalid tag timezone1' \ |
acb49d1c | 306 | '^error: char.*: malformed tag timezone$' |
ba26ab99 BC |
307 | |
308 | ############################################################ | |
309 | # 21. detect invalid tag timezone2 | |
310 | ||
311 | cat >tag.sig <<EOF | |
312 | object $head | |
313 | type commit | |
314 | tag mytag | |
315 | tagger T A Gger <tagger@example.com> 1206478233 + 30 | |
316 | ||
317 | EOF | |
318 | ||
319 | check_verify_failure 'detect invalid tag timezone2' \ | |
acb49d1c | 320 | '^error: char.*: malformed tag timezone$' |
ba26ab99 BC |
321 | |
322 | ############################################################ | |
323 | # 22. detect invalid tag timezone3 | |
324 | ||
325 | cat >tag.sig <<EOF | |
326 | object $head | |
327 | type commit | |
328 | tag mytag | |
329 | tagger T A Gger <tagger@example.com> 1206478233 -1430 | |
330 | ||
331 | EOF | |
332 | ||
333 | check_verify_failure 'detect invalid tag timezone3' \ | |
acb49d1c | 334 | '^error: char.*: malformed tag timezone$' |
e0aaf781 BC |
335 | |
336 | ############################################################ | |
ba26ab99 | 337 | # 23. detect invalid header entry |
e0aaf781 BC |
338 | |
339 | cat >tag.sig <<EOF | |
340 | object $head | |
341 | type commit | |
342 | tag mytag | |
343 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
344 | this line should not be here | |
345 | ||
346 | EOF | |
347 | ||
348 | check_verify_failure 'detect invalid header entry' \ | |
acb49d1c | 349 | '^error: char.*: trailing garbage in tag header$' |
e0aaf781 | 350 | |
47c95e77 ÆAB |
351 | cat >tag.sig <<EOF |
352 | object $head | |
353 | type commit | |
354 | tag mytag | |
355 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
356 | ||
357 | ||
358 | this line comes after an extra newline | |
359 | EOF | |
360 | ||
ca9a1ed9 | 361 | test_expect_mktag_success 'allow extra newlines at start of body' |
47c95e77 ÆAB |
362 | |
363 | cat >tag.sig <<EOF | |
364 | object $head | |
365 | type commit | |
366 | tag mytag | |
367 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
368 | ||
369 | EOF | |
370 | ||
ca9a1ed9 | 371 | test_expect_mktag_success 'require a blank line before an empty body (1)' |
47c95e77 ÆAB |
372 | |
373 | cat >tag.sig <<EOF | |
374 | object $head | |
375 | type commit | |
376 | tag mytag | |
377 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
378 | EOF | |
379 | ||
380 | check_verify_failure 'require a blank line before an empty body (2)' \ | |
381 | '^error: char.*: trailing garbage in tag header$' | |
382 | ||
e0aaf781 | 383 | ############################################################ |
ba26ab99 | 384 | # 24. create valid tag |
e0aaf781 BC |
385 | |
386 | cat >tag.sig <<EOF | |
387 | object $head | |
388 | type commit | |
389 | tag mytag | |
390 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
391 | ||
446c6fae RJ |
392 | EOF |
393 | ||
ca9a1ed9 | 394 | test_expect_mktag_success 'create valid tag object' |
446c6fae RJ |
395 | |
396 | test_done |