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.
  25echo Hello >A
  26git update-index --add A
  27git commit -m "Initial commit"
  28head=$(git rev-parse --verify HEAD)
  29############################################################
  31#  1. length check
  32cat >tag.sig <<EOF
  34too short for a tag
  35EOF
  36check_verify_failure 'Tag object length check' \
  38        '^error: .*size wrong.*$'
  39############################################################
  41#  2. object line label check
  42cat >tag.sig <<EOF
  44xxxxxx 139e9b33986b1c2670fff52c5067603117b3e895
  45type tag
  46tag mytag
  47tagger . <> 0 +0000
  48EOF
  50check_verify_failure '"object" line label check' '^error: char0: .*"object "$'
  52############################################################
  54#  3. object line SHA1 check
  55cat >tag.sig <<EOF
  57object zz9e9b33986b1c2670fff52c5067603117b3e895
  58type tag
  59tag mytag
  60tagger . <> 0 +0000
  61EOF
  63check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$'
  65############################################################
  67#  4. type line label check
  68cat >tag.sig <<EOF
  70object 779e9b33986b1c2670fff52c5067603117b3e895
  71xxxx tag
  72tag mytag
  73tagger . <> 0 +0000
  74EOF
  76check_verify_failure '"type" line label check' '^error: char47: .*"\\ntype "$'
  78############################################################
  80#  5. type line eol check
  81echo "object 779e9b33986b1c2670fff52c5067603117b3e895" >tag.sig
  83printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
  84check_verify_failure '"type" line eol check' '^error: char48: .*"\\n"$'
  86############################################################
  88#  6. tag line label check #1
  89cat >tag.sig <<EOF
  91object 779e9b33986b1c2670fff52c5067603117b3e895
  92type tag
  93xxx mytag
  94tagger . <> 0 +0000
  95EOF
  97check_verify_failure '"tag" line label check #1' \
  99        '^error: char57: no "tag " found$'
 100############################################################
 102#  7. tag line label check #2
 103cat >tag.sig <<EOF
 105object 779e9b33986b1c2670fff52c5067603117b3e895
 106type taggggggggggggggggggggggggggggggg
 107tag
 108EOF
 109check_verify_failure '"tag" line label check #2' \
 111        '^error: char87: no "tag " found$'
 112############################################################
 114#  8. type line type-name length check
 115cat >tag.sig <<EOF
 117object 779e9b33986b1c2670fff52c5067603117b3e895
 118type taggggggggggggggggggggggggggggggg
 119tag mytag
 120EOF
 121check_verify_failure '"type" line type-name length check' \
 123        '^error: char53: type too long$'
 124############################################################
 126#  9. verify object (SHA1/type) check
 127cat >tag.sig <<EOF
 129object 779e9b33986b1c2670fff52c5067603117b3e895
 130type tagggg
 131tag mytag
 132tagger . <> 0 +0000
 133EOF
 135check_verify_failure 'verify object (SHA1/type) check' \
 137        '^error: char7: could not verify object.*$'
 138############################################################
 140# 10. verify tag-name check
 141cat >tag.sig <<EOF
 143object $head
 144type commit
 145tag my  tag
 146tagger . <> 0 +0000
 147EOF
 149check_verify_failure 'verify tag-name check' \
 151        '^error: char67: could not verify tag name$'
 152############################################################
 154# 11. tagger line label check #1
 155cat >tag.sig <<EOF
 157object $head
 158type commit
 159tag mytag
 160This is filler
 162EOF
 163check_verify_failure '"tagger" line label check #1' \
 165        '^error: char70: could not find "tagger "$'
 166############################################################
 168# 12. tagger line label check #2
 169cat >tag.sig <<EOF
 171object $head
 172type commit
 173tag mytag
 174tagger
 175This is filler
 177EOF
 178check_verify_failure '"tagger" line label check #2' \
 180        '^error: char70: could not find "tagger "$'
 181############################################################
 183# 13. disallow missing tag author name
 184cat >tag.sig <<EOF
 186object $head
 187type commit
 188tag mytag
 189tagger  <> 0 +0000
 190This is filler
 192EOF
 193check_verify_failure 'disallow missing tag author name' \
 195        '^error: char77: missing tagger name$'
 196############################################################
 198# 14. disallow missing tag author name
 199cat >tag.sig <<EOF
 201object $head
 202type commit
 203tag mytag
 204tagger T A Gger <
 205 > 0 +0000
 206EOF
 208check_verify_failure 'disallow malformed tagger' \
 210        '^error: char77: malformed tagger field$'
 211############################################################
 213# 15. allow empty tag email
 214cat >tag.sig <<EOF
 216object $head
 217type commit
 218tag mytag
 219tagger T A Gger <> 0 +0000
 220EOF
 222test_expect_success \
 224    'allow empty tag email' \
 225    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 226############################################################
 228# 16. disallow spaces in tag email
 229cat >tag.sig <<EOF
 231object $head
 232type commit
 233tag mytag
 234tagger T A Gger <tag ger@example.com> 0 +0000
 235EOF
 237check_verify_failure 'disallow spaces in tag email' \
 239        '^error: char77: malformed tagger field$'
 240############################################################
 242# 17. disallow missing tag timestamp
 243tr '_' ' ' >tag.sig <<EOF
 245object $head
 246type commit
 247tag mytag
 248tagger T A Gger <tagger@example.com>__
 249EOF
 251check_verify_failure 'disallow missing tag timestamp' \
 253        '^error: char107: missing tag timestamp$'
 254############################################################
 256# 18. detect invalid tag timestamp1
 257cat >tag.sig <<EOF
 259object $head
 260type commit
 261tag mytag
 262tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
 263EOF
 265check_verify_failure 'detect invalid tag timestamp1' \
 267        '^error: char107: missing tag timestamp$'
 268############################################################
 270# 19. detect invalid tag timestamp2
 271cat >tag.sig <<EOF
 273object $head
 274type commit
 275tag mytag
 276tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
 277EOF
 279check_verify_failure 'detect invalid tag timestamp2' \
 281        '^error: char111: malformed tag timestamp$'
 282############################################################
 284# 20. detect invalid tag timezone1
 285cat >tag.sig <<EOF
 287object $head
 288type commit
 289tag mytag
 290tagger T A Gger <tagger@example.com> 1206478233 GMT
 291EOF
 293check_verify_failure 'detect invalid tag timezone1' \
 295        '^error: char118: malformed tag timezone$'
 296############################################################
 298# 21. detect invalid tag timezone2
 299cat >tag.sig <<EOF
 301object $head
 302type commit
 303tag mytag
 304tagger T A Gger <tagger@example.com> 1206478233 +  30
 305EOF
 307check_verify_failure 'detect invalid tag timezone2' \
 309        '^error: char118: malformed tag timezone$'
 310############################################################
 312# 22. detect invalid tag timezone3
 313cat >tag.sig <<EOF
 315object $head
 316type commit
 317tag mytag
 318tagger T A Gger <tagger@example.com> 1206478233 -1430
 319EOF
 321check_verify_failure 'detect invalid tag timezone3' \
 323        '^error: char118: malformed tag timezone$'
 324############################################################
 326# 23. detect invalid header entry
 327cat >tag.sig <<EOF
 329object $head
 330type commit
 331tag mytag
 332tagger T A Gger <tagger@example.com> 1206478233 -0500
 333this line should not be here
 334EOF
 336check_verify_failure 'detect invalid header entry' \
 338        '^error: char124: trailing garbage in tag header$'
 339############################################################
 341# 24. create valid tag
 342cat >tag.sig <<EOF
 344object $head
 345type commit
 346tag mytag
 347tagger T A Gger <tagger@example.com> 1206478233 -0500
 348EOF
 350test_expect_success \
 352    'create valid tag' \
 353    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 354############################################################
 356# 25. check mytag
 357test_expect_success \
 359    'check mytag' \
 360    'git tag -l | grep mytag'
 361test_done