2006-07-29 19:15:47 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2008-09-03 10:59:27 +02:00
|
|
|
test_description='git mktag: tag object verify test'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# check the tag.sig file, expecting verify_tag() to fail,
|
|
|
|
# and checking that the error message matches the pattern
|
|
|
|
# given in the expect.pat file.
|
|
|
|
|
|
|
|
check_verify_failure () {
|
2008-01-05 07:45:08 +01:00
|
|
|
expect="$2"
|
|
|
|
test_expect_success "$1" '
|
2021-01-05 20:42:41 +01:00
|
|
|
test_must_fail env GIT_TEST_GETTEXT_POISON=false \
|
|
|
|
git mktag <tag.sig 2>message &&
|
2008-03-26 01:20:52 +01:00
|
|
|
grep "$expect" message
|
2008-01-05 07:45:08 +01:00
|
|
|
'
|
2006-07-29 19:15:47 +02:00
|
|
|
}
|
|
|
|
|
2021-01-05 20:42:40 +01:00
|
|
|
test_expect_mktag_success() {
|
|
|
|
test_expect_success "$1" '
|
|
|
|
git hash-object -t tag -w --stdin <tag.sig >expected &&
|
|
|
|
git fsck --strict &&
|
|
|
|
|
|
|
|
git mktag <tag.sig >hash &&
|
|
|
|
test_cmp expected hash &&
|
|
|
|
test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
|
|
|
|
git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
|
|
|
|
git fsck --strict
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
###########################################################
|
|
|
|
# first create a commit, so we have a valid object/type
|
|
|
|
# for the tag.
|
2010-03-20 09:29:11 +01:00
|
|
|
test_expect_success 'setup' '
|
2021-01-05 20:42:34 +01:00
|
|
|
test_commit A &&
|
2010-03-20 09:29:11 +01:00
|
|
|
head=$(git rev-parse --verify HEAD)
|
|
|
|
'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 1. length check
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
too short for a tag
|
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure 'Tag object length check' \
|
|
|
|
'^error: .*size wrong.*$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 2. object line label check
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2021-01-05 20:42:35 +01:00
|
|
|
xxxxxx $head
|
2006-07-29 19:15:47 +02:00
|
|
|
type tag
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"object" line label check' '^error: char0: .*"object "$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
2021-01-05 20:42:35 +01:00
|
|
|
# 3. object line hash check
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2021-01-05 20:42:35 +01:00
|
|
|
object $(echo $head | tr 0-9a-f z)
|
2006-07-29 19:15:47 +02:00
|
|
|
type tag
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 4. type line label check
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2019-08-18 21:16:42 +02:00
|
|
|
object $head
|
2006-07-29 19:15:47 +02:00
|
|
|
xxxx tag
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2019-08-18 21:16:42 +02:00
|
|
|
check_verify_failure '"type" line label check' '^error: char.*: .*"\\ntype "$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 5. type line eol check
|
|
|
|
|
2019-08-18 21:16:42 +02:00
|
|
|
echo "object $head" >tag.sig
|
2007-01-16 02:31:29 +01:00
|
|
|
printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
|
2006-07-29 19:15:47 +02:00
|
|
|
|
2019-08-18 21:16:42 +02:00
|
|
|
check_verify_failure '"type" line eol check' '^error: char.*: .*"\\n"$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 6. tag line label check #1
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2019-08-18 21:16:42 +02:00
|
|
|
object $head
|
2006-07-29 19:15:47 +02:00
|
|
|
type tag
|
|
|
|
xxx mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"tag" line label check #1' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: no "tag " found$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 7. tag line label check #2
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2019-08-18 21:16:42 +02:00
|
|
|
object $head
|
2006-07-29 19:15:47 +02:00
|
|
|
type taggggggggggggggggggggggggggggggg
|
|
|
|
tag
|
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"tag" line label check #2' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: no "tag " found$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 8. type line type-name length check
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2019-08-18 21:16:42 +02:00
|
|
|
object $head
|
2006-07-29 19:15:47 +02:00
|
|
|
type taggggggggggggggggggggggggggggggg
|
|
|
|
tag mytag
|
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"type" line type-name length check' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: type too long$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
2021-01-05 20:42:41 +01:00
|
|
|
# 9. verify object (hash/type) check
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
2019-08-18 21:16:42 +02:00
|
|
|
object $(test_oid deadbeef)
|
2021-01-05 20:42:41 +01:00
|
|
|
type tag
|
|
|
|
tag mytag
|
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
|
|
|
|
'^error: char7: could not verify object.*$'
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
2006-07-29 19:15:47 +02:00
|
|
|
type tagggg
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2021-01-05 20:42:41 +01:00
|
|
|
check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
|
|
|
|
'^fatal: invalid object type'
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $(test_oid deadbeef)
|
|
|
|
type tagggg
|
|
|
|
tag mytag
|
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
|
2008-01-05 07:45:08 +01:00
|
|
|
'^error: char7: could not verify object.*$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
2021-01-05 20:42:41 +01:00
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type tree
|
|
|
|
tag mytag
|
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
|
|
|
|
'^error: char7: could not verify object'
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
############################################################
|
|
|
|
# 10. verify tag-name check
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag my tag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger . <> 0 +0000
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure 'verify tag-name check' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: could not verify tag name$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
2007-02-04 05:49:16 +01:00
|
|
|
# 11. tagger line label check #1
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
This is filler
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"tagger" line label check #1' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: could not find "tagger "$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
2007-02-04 05:49:16 +01:00
|
|
|
# 12. tagger line label check #2
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
This is filler
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2008-01-05 07:45:08 +01:00
|
|
|
check_verify_failure '"tagger" line label check #2' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: could not find "tagger "$'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 13. disallow missing tag author name
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
2008-03-27 17:16:04 +01:00
|
|
|
tagger <> 0 +0000
|
|
|
|
|
|
|
|
This is filler
|
|
|
|
EOF
|
|
|
|
|
2008-04-01 01:25:23 +02:00
|
|
|
check_verify_failure 'disallow missing tag author name' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: missing tagger name$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 14. disallow missing tag author name
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <
|
|
|
|
> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2008-04-01 01:25:23 +02:00
|
|
|
check_verify_failure 'disallow malformed tagger' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tagger field$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 15. allow empty tag email
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2021-01-05 20:42:40 +01:00
|
|
|
test_expect_mktag_success 'allow empty tag email'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 16. disallow spaces in tag email
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tag ger@example.com> 0 +0000
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'disallow spaces in tag email' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tagger field$'
|
2008-04-01 01:25:23 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 17. disallow missing tag timestamp
|
2008-03-27 17:16:04 +01:00
|
|
|
|
2008-06-14 09:26:37 +02:00
|
|
|
tr '_' ' ' >tag.sig <<EOF
|
2008-03-27 17:16:04 +01:00
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
2008-06-14 09:26:37 +02:00
|
|
|
tagger T A Gger <tagger@example.com>__
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2008-04-01 01:25:23 +02:00
|
|
|
check_verify_failure 'disallow missing tag timestamp' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: missing tag timestamp$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 18. detect invalid tag timestamp1
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2008-04-01 01:25:23 +02:00
|
|
|
check_verify_failure 'detect invalid tag timestamp1' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: missing tag timestamp$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 19. detect invalid tag timestamp2
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'detect invalid tag timestamp2' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tag timestamp$'
|
2008-04-01 01:25:23 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 20. detect invalid tag timezone1
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 GMT
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2008-04-01 01:25:23 +02:00
|
|
|
check_verify_failure 'detect invalid tag timezone1' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tag timezone$'
|
2008-04-01 01:25:23 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 21. detect invalid tag timezone2
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 + 30
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'detect invalid tag timezone2' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tag timezone$'
|
2008-04-01 01:25:23 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 22. detect invalid tag timezone3
|
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -1430
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'detect invalid tag timezone3' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: malformed tag timezone$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 23. detect invalid header entry
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -0500
|
|
|
|
this line should not be here
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'detect invalid header entry' \
|
2019-08-18 21:16:42 +02:00
|
|
|
'^error: char.*: trailing garbage in tag header$'
|
2008-03-27 17:16:04 +01:00
|
|
|
|
2021-01-05 20:42:39 +01:00
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -0500
|
|
|
|
|
|
|
|
|
|
|
|
this line comes after an extra newline
|
|
|
|
EOF
|
|
|
|
|
2021-01-05 20:42:40 +01:00
|
|
|
test_expect_mktag_success 'allow extra newlines at start of body'
|
2021-01-05 20:42:39 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -0500
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2021-01-05 20:42:40 +01:00
|
|
|
test_expect_mktag_success 'require a blank line before an empty body (1)'
|
2021-01-05 20:42:39 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -0500
|
|
|
|
EOF
|
|
|
|
|
|
|
|
check_verify_failure 'require a blank line before an empty body (2)' \
|
|
|
|
'^error: char.*: trailing garbage in tag header$'
|
|
|
|
|
2008-03-27 17:16:04 +01:00
|
|
|
############################################################
|
2008-04-01 01:25:23 +02:00
|
|
|
# 24. create valid tag
|
2008-03-27 17:16:04 +01:00
|
|
|
|
|
|
|
cat >tag.sig <<EOF
|
|
|
|
object $head
|
|
|
|
type commit
|
|
|
|
tag mytag
|
|
|
|
tagger T A Gger <tagger@example.com> 1206478233 -0500
|
|
|
|
|
2006-07-29 19:15:47 +02:00
|
|
|
EOF
|
|
|
|
|
2021-01-05 20:42:40 +01:00
|
|
|
test_expect_mktag_success 'create valid tag object'
|
2006-07-29 19:15:47 +02:00
|
|
|
|
|
|
|
test_done
|