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