]>
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 () { | |
06ce7915 | 15 | test_expect_success "$1" " |
30f882c1 ÆAB |
16 | test_must_fail env GIT_TEST_GETTEXT_POISON=false \ |
17 | git mktag <tag.sig 2>message && | |
06ce7915 ÆAB |
18 | grep '$2' message && |
19 | if test '$3' != '--no-strict' | |
20 | then | |
21 | test_must_fail env GIT_TEST_GETTEXT_POISON=false \ | |
22 | git mktag --no-strict <tag.sig 2>message.no-strict && | |
23 | grep '$2' message.no-strict | |
24 | fi | |
25 | " | |
446c6fae RJ |
26 | } |
27 | ||
ca9a1ed9 ÆAB |
28 | test_expect_mktag_success() { |
29 | test_expect_success "$1" ' | |
30 | git hash-object -t tag -w --stdin <tag.sig >expected && | |
31 | git fsck --strict && | |
32 | ||
33 | git mktag <tag.sig >hash && | |
34 | test_cmp expected hash && | |
35 | test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" && | |
36 | git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) && | |
37 | git fsck --strict | |
38 | ' | |
39 | } | |
40 | ||
446c6fae RJ |
41 | ########################################################### |
42 | # first create a commit, so we have a valid object/type | |
43 | # for the tag. | |
4a45f7dd | 44 | test_expect_success 'setup' ' |
b5ca549c | 45 | test_commit A && |
692654dc ÆAB |
46 | test_commit B && |
47 | head=$(git rev-parse --verify HEAD) && | |
48 | head_parent=$(git rev-parse --verify HEAD~) && | |
49 | tree=$(git rev-parse HEAD^{tree}) && | |
50 | blob=$(git rev-parse --verify HEAD:B.t) | |
4a45f7dd | 51 | ' |
446c6fae | 52 | |
3f390a36 ÆAB |
53 | test_expect_success 'basic usage' ' |
54 | cat >tag.sig <<-EOF && | |
55 | object $head | |
56 | type commit | |
57 | tag mytag | |
58 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
59 | EOF | |
60 | git mktag <tag.sig && | |
61 | git mktag --end-of-options <tag.sig && | |
62 | test_expect_code 129 git mktag --unknown-option | |
63 | ' | |
64 | ||
446c6fae RJ |
65 | ############################################################ |
66 | # 1. length check | |
67 | ||
68 | cat >tag.sig <<EOF | |
69 | too short for a tag | |
70 | EOF | |
71 | ||
e9b20943 | 72 | check_verify_failure 'Tag object length check' \ |
06ce7915 | 73 | '^error:.* missingObject:' 'strict' |
446c6fae RJ |
74 | |
75 | ############################################################ | |
76 | # 2. object line label check | |
77 | ||
78 | cat >tag.sig <<EOF | |
0d35ccb5 | 79 | xxxxxx $head |
446c6fae RJ |
80 | type tag |
81 | tag mytag | |
e0aaf781 BC |
82 | tagger . <> 0 +0000 |
83 | ||
446c6fae RJ |
84 | EOF |
85 | ||
acf9de4c | 86 | check_verify_failure '"object" line label check' '^error:.* missingObject:' |
446c6fae RJ |
87 | |
88 | ############################################################ | |
0d35ccb5 | 89 | # 3. object line hash check |
446c6fae RJ |
90 | |
91 | cat >tag.sig <<EOF | |
0d35ccb5 | 92 | object $(echo $head | tr 0-9a-f z) |
446c6fae RJ |
93 | type tag |
94 | tag mytag | |
e0aaf781 BC |
95 | tagger . <> 0 +0000 |
96 | ||
446c6fae RJ |
97 | EOF |
98 | ||
acf9de4c | 99 | check_verify_failure '"object" line check' '^error:.* badObjectSha1:' |
446c6fae RJ |
100 | |
101 | ############################################################ | |
102 | # 4. type line label check | |
103 | ||
104 | cat >tag.sig <<EOF | |
acb49d1c | 105 | object $head |
446c6fae RJ |
106 | xxxx tag |
107 | tag mytag | |
e0aaf781 BC |
108 | tagger . <> 0 +0000 |
109 | ||
446c6fae RJ |
110 | EOF |
111 | ||
acf9de4c | 112 | check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:' |
446c6fae RJ |
113 | |
114 | ############################################################ | |
115 | # 5. type line eol check | |
116 | ||
acb49d1c | 117 | echo "object $head" >tag.sig |
2aad957a | 118 | printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig |
446c6fae | 119 | |
acf9de4c | 120 | check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:' |
446c6fae RJ |
121 | |
122 | ############################################################ | |
123 | # 6. tag line label check #1 | |
124 | ||
125 | cat >tag.sig <<EOF | |
acb49d1c | 126 | object $head |
446c6fae RJ |
127 | type tag |
128 | xxx mytag | |
e0aaf781 BC |
129 | tagger . <> 0 +0000 |
130 | ||
446c6fae RJ |
131 | EOF |
132 | ||
e9b20943 | 133 | check_verify_failure '"tag" line label check #1' \ |
acf9de4c | 134 | '^error:.* missingTagEntry:' |
446c6fae RJ |
135 | |
136 | ############################################################ | |
137 | # 7. tag line label check #2 | |
138 | ||
139 | cat >tag.sig <<EOF | |
acb49d1c | 140 | object $head |
446c6fae RJ |
141 | type taggggggggggggggggggggggggggggggg |
142 | tag | |
143 | EOF | |
144 | ||
e9b20943 | 145 | check_verify_failure '"tag" line label check #2' \ |
acf9de4c | 146 | '^error:.* badType:' |
446c6fae RJ |
147 | |
148 | ############################################################ | |
149 | # 8. type line type-name length check | |
150 | ||
151 | cat >tag.sig <<EOF | |
acb49d1c | 152 | object $head |
446c6fae RJ |
153 | type taggggggggggggggggggggggggggggggg |
154 | tag mytag | |
155 | EOF | |
156 | ||
e9b20943 | 157 | check_verify_failure '"type" line type-name length check' \ |
acf9de4c | 158 | '^error:.* badType:' |
446c6fae RJ |
159 | |
160 | ############################################################ | |
30f882c1 | 161 | # 9. verify object (hash/type) check |
446c6fae RJ |
162 | |
163 | cat >tag.sig <<EOF | |
acb49d1c | 164 | object $(test_oid deadbeef) |
30f882c1 ÆAB |
165 | type tag |
166 | tag mytag | |
167 | tagger . <> 0 +0000 | |
168 | ||
169 | EOF | |
170 | ||
171 | check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \ | |
acf9de4c | 172 | '^fatal: could not read tagged object' |
30f882c1 ÆAB |
173 | |
174 | cat >tag.sig <<EOF | |
175 | object $head | |
446c6fae RJ |
176 | type tagggg |
177 | tag mytag | |
e0aaf781 BC |
178 | tagger . <> 0 +0000 |
179 | ||
446c6fae RJ |
180 | EOF |
181 | ||
30f882c1 | 182 | check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \ |
acf9de4c | 183 | '^error:.* badType:' |
30f882c1 ÆAB |
184 | |
185 | cat >tag.sig <<EOF | |
186 | object $(test_oid deadbeef) | |
187 | type tagggg | |
188 | tag mytag | |
189 | tagger . <> 0 +0000 | |
190 | ||
191 | EOF | |
192 | ||
193 | check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \ | |
acf9de4c | 194 | '^error:.* badType:' |
446c6fae | 195 | |
30f882c1 ÆAB |
196 | cat >tag.sig <<EOF |
197 | object $head | |
198 | type tree | |
199 | tag mytag | |
200 | tagger . <> 0 +0000 | |
201 | ||
202 | EOF | |
203 | ||
692654dc | 204 | check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ |
acf9de4c | 205 | '^fatal: object.*tagged as.*tree.*but is.*commit' |
692654dc ÆAB |
206 | |
207 | ############################################################ | |
208 | # 9.5. verify object (hash/type) check -- replacement | |
209 | ||
210 | test_expect_success 'setup replacement of commit -> commit and tree -> blob' ' | |
211 | git replace $head_parent $head && | |
212 | git replace -f $tree $blob | |
213 | ' | |
214 | ||
215 | cat >tag.sig <<EOF | |
216 | object $head_parent | |
217 | type commit | |
218 | tag mytag | |
219 | tagger . <> 0 +0000 | |
220 | ||
221 | EOF | |
222 | ||
223 | test_expect_mktag_success 'tag to a commit replaced by another commit' | |
224 | ||
225 | cat >tag.sig <<EOF | |
226 | object $tree | |
227 | type tree | |
228 | tag mytag | |
229 | tagger . <> 0 +0000 | |
230 | ||
231 | EOF | |
232 | ||
30f882c1 | 233 | check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ |
acf9de4c | 234 | '^fatal: object.*tagged as.*tree.*but is.*blob' |
30f882c1 | 235 | |
446c6fae RJ |
236 | ############################################################ |
237 | # 10. verify tag-name check | |
238 | ||
239 | cat >tag.sig <<EOF | |
240 | object $head | |
241 | type commit | |
242 | tag my tag | |
e0aaf781 BC |
243 | tagger . <> 0 +0000 |
244 | ||
446c6fae RJ |
245 | EOF |
246 | ||
e9b20943 | 247 | check_verify_failure 'verify tag-name check' \ |
06ce7915 | 248 | '^error:.* badTagName:' '--no-strict' |
446c6fae RJ |
249 | |
250 | ############################################################ | |
3dff5379 | 251 | # 11. tagger line label check #1 |
446c6fae RJ |
252 | |
253 | cat >tag.sig <<EOF | |
254 | object $head | |
255 | type commit | |
256 | tag mytag | |
e0aaf781 BC |
257 | |
258 | This is filler | |
446c6fae RJ |
259 | EOF |
260 | ||
e9b20943 | 261 | check_verify_failure '"tagger" line label check #1' \ |
06ce7915 | 262 | '^error:.* missingTaggerEntry:' '--no-strict' |
446c6fae RJ |
263 | |
264 | ############################################################ | |
3dff5379 | 265 | # 12. tagger line label check #2 |
446c6fae RJ |
266 | |
267 | cat >tag.sig <<EOF | |
268 | object $head | |
269 | type commit | |
270 | tag mytag | |
271 | tagger | |
e0aaf781 BC |
272 | |
273 | This is filler | |
446c6fae RJ |
274 | EOF |
275 | ||
e9b20943 | 276 | check_verify_failure '"tagger" line label check #2' \ |
06ce7915 | 277 | '^error:.* missingTaggerEntry:' '--no-strict' |
446c6fae RJ |
278 | |
279 | ############################################################ | |
acf9de4c | 280 | # 13. allow missing tag author name like fsck |
446c6fae RJ |
281 | |
282 | cat >tag.sig <<EOF | |
283 | object $head | |
284 | type commit | |
285 | tag mytag | |
e0aaf781 BC |
286 | tagger <> 0 +0000 |
287 | ||
288 | This is filler | |
289 | EOF | |
290 | ||
acf9de4c | 291 | test_expect_mktag_success 'allow missing tag author name' |
e0aaf781 BC |
292 | |
293 | ############################################################ | |
ba26ab99 | 294 | # 14. disallow missing tag author name |
e0aaf781 BC |
295 | |
296 | cat >tag.sig <<EOF | |
297 | object $head | |
298 | type commit | |
299 | tag mytag | |
300 | tagger T A Gger < | |
301 | > 0 +0000 | |
302 | ||
303 | EOF | |
304 | ||
ba26ab99 | 305 | check_verify_failure 'disallow malformed tagger' \ |
06ce7915 | 306 | '^error:.* badEmail:' '--no-strict' |
e0aaf781 BC |
307 | |
308 | ############################################################ | |
309 | # 15. allow empty tag email | |
310 | ||
311 | cat >tag.sig <<EOF | |
312 | object $head | |
313 | type commit | |
314 | tag mytag | |
315 | tagger T A Gger <> 0 +0000 | |
316 | ||
317 | EOF | |
318 | ||
ca9a1ed9 | 319 | test_expect_mktag_success 'allow empty tag email' |
e0aaf781 BC |
320 | |
321 | ############################################################ | |
acf9de4c | 322 | # 16. allow spaces in tag email like fsck |
ba26ab99 BC |
323 | |
324 | cat >tag.sig <<EOF | |
325 | object $head | |
326 | type commit | |
327 | tag mytag | |
328 | tagger T A Gger <tag ger@example.com> 0 +0000 | |
329 | ||
330 | EOF | |
331 | ||
acf9de4c | 332 | test_expect_mktag_success 'allow spaces in tag email like fsck' |
ba26ab99 BC |
333 | |
334 | ############################################################ | |
335 | # 17. disallow missing tag timestamp | |
e0aaf781 | 336 | |
74f16b0c | 337 | tr '_' ' ' >tag.sig <<EOF |
e0aaf781 BC |
338 | object $head |
339 | type commit | |
340 | tag mytag | |
74f16b0c | 341 | tagger T A Gger <tagger@example.com>__ |
e0aaf781 BC |
342 | |
343 | EOF | |
344 | ||
ba26ab99 | 345 | check_verify_failure 'disallow missing tag timestamp' \ |
acf9de4c | 346 | '^error:.* badDate:' |
e0aaf781 BC |
347 | |
348 | ############################################################ | |
ba26ab99 | 349 | # 18. detect invalid tag timestamp1 |
e0aaf781 BC |
350 | |
351 | cat >tag.sig <<EOF | |
352 | object $head | |
353 | type commit | |
354 | tag mytag | |
355 | tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008 | |
356 | ||
357 | EOF | |
358 | ||
ba26ab99 | 359 | check_verify_failure 'detect invalid tag timestamp1' \ |
acf9de4c | 360 | '^error:.* badDate:' |
e0aaf781 BC |
361 | |
362 | ############################################################ | |
ba26ab99 BC |
363 | # 19. detect invalid tag timestamp2 |
364 | ||
365 | cat >tag.sig <<EOF | |
366 | object $head | |
367 | type commit | |
368 | tag mytag | |
369 | tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500 | |
370 | ||
371 | EOF | |
372 | ||
373 | check_verify_failure 'detect invalid tag timestamp2' \ | |
acf9de4c | 374 | '^error:.* badDate:' |
ba26ab99 BC |
375 | |
376 | ############################################################ | |
377 | # 20. detect invalid tag timezone1 | |
e0aaf781 BC |
378 | |
379 | cat >tag.sig <<EOF | |
380 | object $head | |
381 | type commit | |
382 | tag mytag | |
383 | tagger T A Gger <tagger@example.com> 1206478233 GMT | |
384 | ||
385 | EOF | |
386 | ||
ba26ab99 | 387 | check_verify_failure 'detect invalid tag timezone1' \ |
acf9de4c | 388 | '^error:.* badTimezone:' |
ba26ab99 BC |
389 | |
390 | ############################################################ | |
391 | # 21. detect invalid tag timezone2 | |
392 | ||
393 | cat >tag.sig <<EOF | |
394 | object $head | |
395 | type commit | |
396 | tag mytag | |
397 | tagger T A Gger <tagger@example.com> 1206478233 + 30 | |
398 | ||
399 | EOF | |
400 | ||
401 | check_verify_failure 'detect invalid tag timezone2' \ | |
acf9de4c | 402 | '^error:.* badTimezone:' |
ba26ab99 BC |
403 | |
404 | ############################################################ | |
acf9de4c | 405 | # 22. allow invalid tag timezone3 (the maximum is -1200/+1400) |
ba26ab99 BC |
406 | |
407 | cat >tag.sig <<EOF | |
408 | object $head | |
409 | type commit | |
410 | tag mytag | |
411 | tagger T A Gger <tagger@example.com> 1206478233 -1430 | |
412 | ||
413 | EOF | |
414 | ||
acf9de4c | 415 | test_expect_mktag_success 'allow invalid tag timezone' |
e0aaf781 BC |
416 | |
417 | ############################################################ | |
ba26ab99 | 418 | # 23. detect invalid header entry |
e0aaf781 BC |
419 | |
420 | cat >tag.sig <<EOF | |
421 | object $head | |
422 | type commit | |
423 | tag mytag | |
424 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
425 | this line should not be here | |
426 | ||
427 | EOF | |
428 | ||
429 | check_verify_failure 'detect invalid header entry' \ | |
06ce7915 | 430 | '^error:.* extraHeaderEntry:' '--no-strict' |
e0aaf781 | 431 | |
acfc0133 ÆAB |
432 | test_expect_success 'invalid header entry config & fsck' ' |
433 | test_must_fail git mktag <tag.sig && | |
06ce7915 ÆAB |
434 | git mktag --no-strict <tag.sig && |
435 | ||
acfc0133 | 436 | test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig && |
06ce7915 ÆAB |
437 | test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig && |
438 | ||
acfc0133 | 439 | test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig && |
06ce7915 ÆAB |
440 | git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig && |
441 | ||
acfc0133 | 442 | git -c fsck.extraHeaderEntry=ignore mktag <tag.sig && |
06ce7915 ÆAB |
443 | git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig && |
444 | ||
acfc0133 ÆAB |
445 | git fsck && |
446 | env GIT_TEST_GETTEXT_POISON=false \ | |
447 | git -c fsck.extraHeaderEntry=warn fsck 2>err && | |
448 | grep "warning .*extraHeaderEntry:" err && | |
449 | test_must_fail env GIT_TEST_GETTEXT_POISON=false \ | |
450 | git -c fsck.extraHeaderEntry=error 2>err fsck && | |
451 | grep "error .* extraHeaderEntry:" err | |
452 | ' | |
453 | ||
47c95e77 ÆAB |
454 | cat >tag.sig <<EOF |
455 | object $head | |
456 | type commit | |
457 | tag mytag | |
458 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
459 | ||
460 | ||
461 | this line comes after an extra newline | |
462 | EOF | |
463 | ||
ca9a1ed9 | 464 | test_expect_mktag_success 'allow extra newlines at start of body' |
47c95e77 ÆAB |
465 | |
466 | cat >tag.sig <<EOF | |
467 | object $head | |
468 | type commit | |
469 | tag mytag | |
470 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
471 | ||
472 | EOF | |
473 | ||
9a1a3a4d | 474 | test_expect_mktag_success 'allow a blank line before an empty body (1)' |
47c95e77 ÆAB |
475 | |
476 | cat >tag.sig <<EOF | |
477 | object $head | |
478 | type commit | |
479 | tag mytag | |
480 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
481 | EOF | |
482 | ||
9a1a3a4d | 483 | test_expect_mktag_success 'allow no blank line before an empty body (2)' |
47c95e77 | 484 | |
e0aaf781 | 485 | ############################################################ |
ba26ab99 | 486 | # 24. create valid tag |
e0aaf781 BC |
487 | |
488 | cat >tag.sig <<EOF | |
489 | object $head | |
490 | type commit | |
491 | tag mytag | |
492 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
446c6fae RJ |
493 | EOF |
494 | ||
ca9a1ed9 | 495 | test_expect_mktag_success 'create valid tag object' |
446c6fae RJ |
496 | |
497 | test_done |