5 test_description
='git mktag: tag object verify test'
7 TEST_PASSES_SANITIZE_LEAK
=true
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.
15 check_verify_failure
() {
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"
40 test_must_fail git mktag <tag.sig 2>err2 &&
43 git mktag --no-strict <tag.sig
47 test_expect_success
"setup: $subject" '
48 tag_ref=refs/tags/bad_tag &&
50 # Reset any leftover state from the last $subject
53 git init --bare bad-tag &&
54 bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
57 test_expect_success
"hash-object & fsck unreachable: $subject" '
58 if test -n "$fsck_obj_ok"
62 test_must_fail git -C bad-tag fsck
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" &&
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" &&
74 # Manually create the broken, we cannot do it with
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 &&
79 # Unlike fsck-ing unreachable content above, this
81 test_must_fail git -C bad-tag fsck
84 test_expect_success
"for-each-ref: $subject" '
85 # Make sure the earlier test created it for us
86 git rev-parse "$bad_tag" &&
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 &&
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 &&
95 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
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" &&
102 test_must_fail git -C bad-tag fast-export --all &&
103 test_must_fail git -C bad-tag fast-export "$bad_tag"
107 test_expect_mktag_success
() {
108 test_expect_success
"$1" '
109 git hash-object -t tag -w --stdin <tag.sig >expected &&
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) &&
120 ###########################################################
121 # first create a commit, so we have a valid object/type
123 test_expect_success
'setup' '
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)
132 test_expect_success
'basic usage' '
133 cat >tag.sig <<-EOF &&
137 tagger T A Gger <tagger@example.com> 1206478233 -0500
139 git mktag <tag.sig &&
140 git mktag --end-of-options <tag.sig &&
141 test_expect_code 129 git mktag --unknown-option
144 ############################################################
151 check_verify_failure
'Tag object length check' \
152 '^error:.* missingObject:' 'strict'
154 ############################################################
155 # 2. object line label check
165 check_verify_failure
'"object" line label check' '^error:.* missingObject:'
167 ############################################################
168 # 3. object line hash check
171 object $(echo $head | tr 0-9a-f z)
178 check_verify_failure
'"object" line check' '^error:.* badObjectSha1:'
180 ############################################################
181 # 4. type line label check
191 check_verify_failure
'"type" line label check' '^error:.* missingTypeEntry:'
193 ############################################################
194 # 5. type line eol check
196 echo "object $head" >tag.sig
197 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
199 check_verify_failure
'"type" line eol check' '^error:.* unterminatedHeader:'
201 ############################################################
202 # 6. tag line label check #1
212 check_verify_failure
'"tag" line label check #1' \
213 '^error:.* missingTagEntry:'
215 ############################################################
216 # 7. tag line label check #2
220 type taggggggggggggggggggggggggggggggg
224 check_verify_failure
'"tag" line label check #2' \
227 ############################################################
228 # 8. type line type-name length check
232 type taggggggggggggggggggggggggggggggg
236 check_verify_failure
'"type" line type-name length check' \
239 ############################################################
240 # 9. verify object (hash/type) check
243 object $(test_oid deadbeef)
250 check_verify_failure
'verify object (hash/type) check -- correct type, nonexisting object' \
251 '^fatal: could not read tagged object' \
262 check_verify_failure
'verify object (hash/type) check -- made-up type, valid object' \
266 object $(test_oid deadbeef)
273 check_verify_failure
'verify object (hash/type) check -- made-up type, nonexisting object' \
284 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
285 '^fatal: object.*tagged as.*tree.*but is.*commit' \
288 ############################################################
289 # 9.5. verify object (hash/type) check -- replacement
291 test_expect_success
'setup replacement of commit -> commit and tree -> blob' '
292 git replace $head_parent $head &&
293 git replace -f $tree $blob
304 test_expect_mktag_success
'tag to a commit replaced by another commit'
314 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
315 '^fatal: object.*tagged as.*tree.*but is.*blob' \
318 ############################################################
319 # 10. verify tag-name check
329 check_verify_failure
'verify tag-name check' \
330 '^error:.* badTagName:' \
334 ############################################################
335 # 11. tagger line label check #1
345 check_verify_failure
'"tagger" line label check #1' \
346 '^error:.* missingTaggerEntry:' \
350 ############################################################
351 # 12. tagger line label check #2
362 check_verify_failure
'"tagger" line label check #2' \
363 '^error:.* missingTaggerEntry:' \
367 ############################################################
368 # 13. allow missing tag author name like fsck
379 test_expect_mktag_success
'allow missing tag author name'
381 ############################################################
382 # 14. disallow missing tag author name
393 check_verify_failure
'disallow malformed tagger' \
394 '^error:.* badEmail:' \
398 ############################################################
399 # 15. allow empty tag email
405 tagger T A Gger <> 0 +0000
409 test_expect_mktag_success
'allow empty tag email'
411 ############################################################
412 # 16. allow spaces in tag email like fsck
418 tagger T A Gger <tag ger@example.com> 0 +0000
422 test_expect_mktag_success
'allow spaces in tag email like fsck'
424 ############################################################
425 # 17. disallow missing tag timestamp
427 tr '_' ' ' >tag.sig
<<EOF
431 tagger T A Gger <tagger@example.com>__
435 check_verify_failure
'disallow missing tag timestamp' \
438 ############################################################
439 # 18. detect invalid tag timestamp1
445 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
449 check_verify_failure
'detect invalid tag timestamp1' \
452 ############################################################
453 # 19. detect invalid tag timestamp2
459 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
463 check_verify_failure
'detect invalid tag timestamp2' \
466 ############################################################
467 # 20. detect invalid tag timezone1
473 tagger T A Gger <tagger@example.com> 1206478233 GMT
477 check_verify_failure
'detect invalid tag timezone1' \
478 '^error:.* badTimezone:'
480 ############################################################
481 # 21. detect invalid tag timezone2
487 tagger T A Gger <tagger@example.com> 1206478233 + 30
491 check_verify_failure
'detect invalid tag timezone2' \
492 '^error:.* badTimezone:'
494 ############################################################
495 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
501 tagger T A Gger <tagger@example.com> 1206478233 -1430
505 test_expect_mktag_success
'allow invalid tag timezone'
507 ############################################################
508 # 23. detect invalid header entry
514 tagger T A Gger <tagger@example.com> 1206478233 -0500
515 this line should not be here
519 check_verify_failure
'detect invalid header entry' \
520 '^error:.* extraHeaderEntry:' \
524 test_expect_success
'invalid header entry config & fsck' '
525 test_must_fail git mktag <tag.sig &&
526 git mktag --no-strict <tag.sig &&
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 &&
531 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
532 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
534 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
535 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
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
548 tagger T A Gger <tagger@example.com> 1206478233 -0500
551 this line comes after an extra newline
554 test_expect_mktag_success
'allow extra newlines at start of body'
560 tagger T A Gger <tagger@example.com> 1206478233 -0500
564 test_expect_mktag_success
'allow a blank line before an empty body (1)'
570 tagger T A Gger <tagger@example.com> 1206478233 -0500
573 test_expect_mktag_success
'allow no blank line before an empty body (2)'
575 ############################################################
576 # 24. create valid tag
582 tagger T A Gger <tagger@example.com> 1206478233 -0500
585 test_expect_mktag_success
'create valid tag object'