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