1#!/bin/sh
   2#
   3#
   4test_description='git mktag: tag object verify test'
   6. ./test-lib.sh
   8###########################################################
  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.
  13check_verify_failure () {
  15        expect="$2"
  16        test_expect_success "$1" '
  17                ( test_must_fail git mktag <tag.sig 2>message ) &&
  18                grep "$expect" message
  19        '
  20}
  21###########################################################
  23# first create a commit, so we have a valid object/type
  24# for the tag.
  25test_expect_success 'setup' '
  26        echo Hello >A &&
  27        git update-index --add A &&
  28        git commit -m "Initial commit" &&
  29        head=$(git rev-parse --verify HEAD)
  30'
  31############################################################
  33#  1. length check
  34cat >tag.sig <<EOF
  36too short for a tag
  37EOF
  38check_verify_failure 'Tag object length check' \
  40        '^error: .*size wrong.*$'
  41############################################################
  43#  2. object line label check
  44cat >tag.sig <<EOF
  46xxxxxx 139e9b33986b1c2670fff52c5067603117b3e895
  47type tag
  48tag mytag
  49tagger . <> 0 +0000
  50EOF
  52check_verify_failure '"object" line label check' '^error: char0: .*"object "$'
  54############################################################
  56#  3. object line SHA1 check
  57cat >tag.sig <<EOF
  59object zz9e9b33986b1c2670fff52c5067603117b3e895
  60type tag
  61tag mytag
  62tagger . <> 0 +0000
  63EOF
  65check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$'
  67############################################################
  69#  4. type line label check
  70cat >tag.sig <<EOF
  72object 779e9b33986b1c2670fff52c5067603117b3e895
  73xxxx tag
  74tag mytag
  75tagger . <> 0 +0000
  76EOF
  78check_verify_failure '"type" line label check' '^error: char47: .*"\\ntype "$'
  80############################################################
  82#  5. type line eol check
  83echo "object 779e9b33986b1c2670fff52c5067603117b3e895" >tag.sig
  85printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
  86check_verify_failure '"type" line eol check' '^error: char48: .*"\\n"$'
  88############################################################
  90#  6. tag line label check #1
  91cat >tag.sig <<EOF
  93object 779e9b33986b1c2670fff52c5067603117b3e895
  94type tag
  95xxx mytag
  96tagger . <> 0 +0000
  97EOF
  99check_verify_failure '"tag" line label check #1' \
 101        '^error: char57: no "tag " found$'
 102############################################################
 104#  7. tag line label check #2
 105cat >tag.sig <<EOF
 107object 779e9b33986b1c2670fff52c5067603117b3e895
 108type taggggggggggggggggggggggggggggggg
 109tag
 110EOF
 111check_verify_failure '"tag" line label check #2' \
 113        '^error: char87: no "tag " found$'
 114############################################################
 116#  8. type line type-name length check
 117cat >tag.sig <<EOF
 119object 779e9b33986b1c2670fff52c5067603117b3e895
 120type taggggggggggggggggggggggggggggggg
 121tag mytag
 122EOF
 123check_verify_failure '"type" line type-name length check' \
 125        '^error: char53: type too long$'
 126############################################################
 128#  9. verify object (SHA1/type) check
 129cat >tag.sig <<EOF
 131object 779e9b33986b1c2670fff52c5067603117b3e895
 132type tagggg
 133tag mytag
 134tagger . <> 0 +0000
 135EOF
 137check_verify_failure 'verify object (SHA1/type) check' \
 139        '^error: char7: could not verify object.*$'
 140############################################################
 142# 10. verify tag-name check
 143cat >tag.sig <<EOF
 145object $head
 146type commit
 147tag my  tag
 148tagger . <> 0 +0000
 149EOF
 151check_verify_failure 'verify tag-name check' \
 153        '^error: char67: could not verify tag name$'
 154############################################################
 156# 11. tagger line label check #1
 157cat >tag.sig <<EOF
 159object $head
 160type commit
 161tag mytag
 162This is filler
 164EOF
 165check_verify_failure '"tagger" line label check #1' \
 167        '^error: char70: could not find "tagger "$'
 168############################################################
 170# 12. tagger line label check #2
 171cat >tag.sig <<EOF
 173object $head
 174type commit
 175tag mytag
 176tagger
 177This is filler
 179EOF
 180check_verify_failure '"tagger" line label check #2' \
 182        '^error: char70: could not find "tagger "$'
 183############################################################
 185# 13. disallow missing tag author name
 186cat >tag.sig <<EOF
 188object $head
 189type commit
 190tag mytag
 191tagger  <> 0 +0000
 192This is filler
 194EOF
 195check_verify_failure 'disallow missing tag author name' \
 197        '^error: char77: missing tagger name$'
 198############################################################
 200# 14. disallow missing tag author name
 201cat >tag.sig <<EOF
 203object $head
 204type commit
 205tag mytag
 206tagger T A Gger <
 207 > 0 +0000
 208EOF
 210check_verify_failure 'disallow malformed tagger' \
 212        '^error: char77: malformed tagger field$'
 213############################################################
 215# 15. allow empty tag email
 216cat >tag.sig <<EOF
 218object $head
 219type commit
 220tag mytag
 221tagger T A Gger <> 0 +0000
 222EOF
 224test_expect_success \
 226    'allow empty tag email' \
 227    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 228############################################################
 230# 16. disallow spaces in tag email
 231cat >tag.sig <<EOF
 233object $head
 234type commit
 235tag mytag
 236tagger T A Gger <tag ger@example.com> 0 +0000
 237EOF
 239check_verify_failure 'disallow spaces in tag email' \
 241        '^error: char77: malformed tagger field$'
 242############################################################
 244# 17. disallow missing tag timestamp
 245tr '_' ' ' >tag.sig <<EOF
 247object $head
 248type commit
 249tag mytag
 250tagger T A Gger <tagger@example.com>__
 251EOF
 253check_verify_failure 'disallow missing tag timestamp' \
 255        '^error: char107: missing tag timestamp$'
 256############################################################
 258# 18. detect invalid tag timestamp1
 259cat >tag.sig <<EOF
 261object $head
 262type commit
 263tag mytag
 264tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
 265EOF
 267check_verify_failure 'detect invalid tag timestamp1' \
 269        '^error: char107: missing tag timestamp$'
 270############################################################
 272# 19. detect invalid tag timestamp2
 273cat >tag.sig <<EOF
 275object $head
 276type commit
 277tag mytag
 278tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
 279EOF
 281check_verify_failure 'detect invalid tag timestamp2' \
 283        '^error: char111: malformed tag timestamp$'
 284############################################################
 286# 20. detect invalid tag timezone1
 287cat >tag.sig <<EOF
 289object $head
 290type commit
 291tag mytag
 292tagger T A Gger <tagger@example.com> 1206478233 GMT
 293EOF
 295check_verify_failure 'detect invalid tag timezone1' \
 297        '^error: char118: malformed tag timezone$'
 298############################################################
 300# 21. detect invalid tag timezone2
 301cat >tag.sig <<EOF
 303object $head
 304type commit
 305tag mytag
 306tagger T A Gger <tagger@example.com> 1206478233 +  30
 307EOF
 309check_verify_failure 'detect invalid tag timezone2' \
 311        '^error: char118: malformed tag timezone$'
 312############################################################
 314# 22. detect invalid tag timezone3
 315cat >tag.sig <<EOF
 317object $head
 318type commit
 319tag mytag
 320tagger T A Gger <tagger@example.com> 1206478233 -1430
 321EOF
 323check_verify_failure 'detect invalid tag timezone3' \
 325        '^error: char118: malformed tag timezone$'
 326############################################################
 328# 23. detect invalid header entry
 329cat >tag.sig <<EOF
 331object $head
 332type commit
 333tag mytag
 334tagger T A Gger <tagger@example.com> 1206478233 -0500
 335this line should not be here
 336EOF
 338check_verify_failure 'detect invalid header entry' \
 340        '^error: char124: trailing garbage in tag header$'
 341############################################################
 343# 24. create valid tag
 344cat >tag.sig <<EOF
 346object $head
 347type commit
 348tag mytag
 349tagger T A Gger <tagger@example.com> 1206478233 -0500
 350EOF
 352test_expect_success \
 354    'create valid tag' \
 355    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 356############################################################
 358# 25. check mytag
 359test_expect_success \
 361    'check mytag' \
 362    'git tag -l | grep mytag'
 363test_done