]>
Commit | Line | Data |
---|---|---|
446c6fae RJ |
1 | #!/bin/sh |
2 | # | |
3 | # | |
4 | ||
0cb0e143 | 5 | test_description='git mktag: tag object verify test' |
446c6fae RJ |
6 | |
7 | . ./test-lib.sh | |
8 | ||
9 | ########################################################### | |
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. | |
13 | ||
14 | check_verify_failure () { | |
e9b20943 JH |
15 | expect="$2" |
16 | test_expect_success "$1" ' | |
0cb0e143 | 17 | ( test_must_fail git mktag <tag.sig 2>message ) && |
525d4615 | 18 | grep "$expect" message |
e9b20943 | 19 | ' |
446c6fae RJ |
20 | } |
21 | ||
22 | ########################################################### | |
23 | # first create a commit, so we have a valid object/type | |
24 | # for the tag. | |
4a45f7dd | 25 | test_expect_success 'setup' ' |
acb49d1c | 26 | test_oid_init && |
4a45f7dd BG |
27 | echo Hello >A && |
28 | git update-index --add A && | |
29 | git commit -m "Initial commit" && | |
30 | head=$(git rev-parse --verify HEAD) | |
31 | ' | |
446c6fae RJ |
32 | |
33 | ############################################################ | |
34 | # 1. length check | |
35 | ||
36 | cat >tag.sig <<EOF | |
37 | too short for a tag | |
38 | EOF | |
39 | ||
e9b20943 JH |
40 | check_verify_failure 'Tag object length check' \ |
41 | '^error: .*size wrong.*$' | |
446c6fae RJ |
42 | |
43 | ############################################################ | |
44 | # 2. object line label check | |
45 | ||
46 | cat >tag.sig <<EOF | |
47 | xxxxxx 139e9b33986b1c2670fff52c5067603117b3e895 | |
48 | type tag | |
49 | tag mytag | |
e0aaf781 BC |
50 | tagger . <> 0 +0000 |
51 | ||
446c6fae RJ |
52 | EOF |
53 | ||
e9b20943 | 54 | check_verify_failure '"object" line label check' '^error: char0: .*"object "$' |
446c6fae RJ |
55 | |
56 | ############################################################ | |
57 | # 3. object line SHA1 check | |
58 | ||
59 | cat >tag.sig <<EOF | |
60 | object zz9e9b33986b1c2670fff52c5067603117b3e895 | |
61 | type tag | |
62 | tag mytag | |
e0aaf781 BC |
63 | tagger . <> 0 +0000 |
64 | ||
446c6fae RJ |
65 | EOF |
66 | ||
e9b20943 | 67 | check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$' |
446c6fae RJ |
68 | |
69 | ############################################################ | |
70 | # 4. type line label check | |
71 | ||
72 | cat >tag.sig <<EOF | |
acb49d1c | 73 | object $head |
446c6fae RJ |
74 | xxxx tag |
75 | tag mytag | |
e0aaf781 BC |
76 | tagger . <> 0 +0000 |
77 | ||
446c6fae RJ |
78 | EOF |
79 | ||
acb49d1c | 80 | check_verify_failure '"type" line label check' '^error: char.*: .*"\\ntype "$' |
446c6fae RJ |
81 | |
82 | ############################################################ | |
83 | # 5. type line eol check | |
84 | ||
acb49d1c | 85 | echo "object $head" >tag.sig |
2aad957a | 86 | printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig |
446c6fae | 87 | |
acb49d1c | 88 | check_verify_failure '"type" line eol check' '^error: char.*: .*"\\n"$' |
446c6fae RJ |
89 | |
90 | ############################################################ | |
91 | # 6. tag line label check #1 | |
92 | ||
93 | cat >tag.sig <<EOF | |
acb49d1c | 94 | object $head |
446c6fae RJ |
95 | type tag |
96 | xxx mytag | |
e0aaf781 BC |
97 | tagger . <> 0 +0000 |
98 | ||
446c6fae RJ |
99 | EOF |
100 | ||
e9b20943 | 101 | check_verify_failure '"tag" line label check #1' \ |
acb49d1c | 102 | '^error: char.*: no "tag " found$' |
446c6fae RJ |
103 | |
104 | ############################################################ | |
105 | # 7. tag line label check #2 | |
106 | ||
107 | cat >tag.sig <<EOF | |
acb49d1c | 108 | object $head |
446c6fae RJ |
109 | type taggggggggggggggggggggggggggggggg |
110 | tag | |
111 | EOF | |
112 | ||
e9b20943 | 113 | check_verify_failure '"tag" line label check #2' \ |
acb49d1c | 114 | '^error: char.*: no "tag " found$' |
446c6fae RJ |
115 | |
116 | ############################################################ | |
117 | # 8. type line type-name length check | |
118 | ||
119 | cat >tag.sig <<EOF | |
acb49d1c | 120 | object $head |
446c6fae RJ |
121 | type taggggggggggggggggggggggggggggggg |
122 | tag mytag | |
123 | EOF | |
124 | ||
e9b20943 | 125 | check_verify_failure '"type" line type-name length check' \ |
acb49d1c | 126 | '^error: char.*: type too long$' |
446c6fae RJ |
127 | |
128 | ############################################################ | |
129 | # 9. verify object (SHA1/type) check | |
130 | ||
131 | cat >tag.sig <<EOF | |
acb49d1c | 132 | object $(test_oid deadbeef) |
446c6fae RJ |
133 | type tagggg |
134 | tag mytag | |
e0aaf781 BC |
135 | tagger . <> 0 +0000 |
136 | ||
446c6fae RJ |
137 | EOF |
138 | ||
e9b20943 JH |
139 | check_verify_failure 'verify object (SHA1/type) check' \ |
140 | '^error: char7: could not verify object.*$' | |
446c6fae RJ |
141 | |
142 | ############################################################ | |
143 | # 10. verify tag-name check | |
144 | ||
145 | cat >tag.sig <<EOF | |
146 | object $head | |
147 | type commit | |
148 | tag my tag | |
e0aaf781 BC |
149 | tagger . <> 0 +0000 |
150 | ||
446c6fae RJ |
151 | EOF |
152 | ||
e9b20943 | 153 | check_verify_failure 'verify tag-name check' \ |
acb49d1c | 154 | '^error: char.*: could not verify tag name$' |
446c6fae RJ |
155 | |
156 | ############################################################ | |
3dff5379 | 157 | # 11. tagger line label check #1 |
446c6fae RJ |
158 | |
159 | cat >tag.sig <<EOF | |
160 | object $head | |
161 | type commit | |
162 | tag mytag | |
e0aaf781 BC |
163 | |
164 | This is filler | |
446c6fae RJ |
165 | EOF |
166 | ||
e9b20943 | 167 | check_verify_failure '"tagger" line label check #1' \ |
acb49d1c | 168 | '^error: char.*: could not find "tagger "$' |
446c6fae RJ |
169 | |
170 | ############################################################ | |
3dff5379 | 171 | # 12. tagger line label check #2 |
446c6fae RJ |
172 | |
173 | cat >tag.sig <<EOF | |
174 | object $head | |
175 | type commit | |
176 | tag mytag | |
177 | tagger | |
e0aaf781 BC |
178 | |
179 | This is filler | |
446c6fae RJ |
180 | EOF |
181 | ||
e9b20943 | 182 | check_verify_failure '"tagger" line label check #2' \ |
acb49d1c | 183 | '^error: char.*: could not find "tagger "$' |
446c6fae RJ |
184 | |
185 | ############################################################ | |
ba26ab99 | 186 | # 13. disallow missing tag author name |
446c6fae RJ |
187 | |
188 | cat >tag.sig <<EOF | |
189 | object $head | |
190 | type commit | |
191 | tag mytag | |
e0aaf781 BC |
192 | tagger <> 0 +0000 |
193 | ||
194 | This is filler | |
195 | EOF | |
196 | ||
ba26ab99 | 197 | check_verify_failure 'disallow missing tag author name' \ |
acb49d1c | 198 | '^error: char.*: missing tagger name$' |
e0aaf781 BC |
199 | |
200 | ############################################################ | |
ba26ab99 | 201 | # 14. disallow missing tag author name |
e0aaf781 BC |
202 | |
203 | cat >tag.sig <<EOF | |
204 | object $head | |
205 | type commit | |
206 | tag mytag | |
207 | tagger T A Gger < | |
208 | > 0 +0000 | |
209 | ||
210 | EOF | |
211 | ||
ba26ab99 | 212 | check_verify_failure 'disallow malformed tagger' \ |
acb49d1c | 213 | '^error: char.*: malformed tagger field$' |
e0aaf781 BC |
214 | |
215 | ############################################################ | |
216 | # 15. allow empty tag email | |
217 | ||
218 | cat >tag.sig <<EOF | |
219 | object $head | |
220 | type commit | |
221 | tag mytag | |
222 | tagger T A Gger <> 0 +0000 | |
223 | ||
224 | EOF | |
225 | ||
226 | test_expect_success \ | |
227 | 'allow empty tag email' \ | |
0cb0e143 | 228 | 'git mktag <tag.sig >.git/refs/tags/mytag 2>message' |
e0aaf781 BC |
229 | |
230 | ############################################################ | |
ba26ab99 BC |
231 | # 16. disallow spaces in tag email |
232 | ||
233 | cat >tag.sig <<EOF | |
234 | object $head | |
235 | type commit | |
236 | tag mytag | |
237 | tagger T A Gger <tag ger@example.com> 0 +0000 | |
238 | ||
239 | EOF | |
240 | ||
241 | check_verify_failure 'disallow spaces in tag email' \ | |
acb49d1c | 242 | '^error: char.*: malformed tagger field$' |
ba26ab99 BC |
243 | |
244 | ############################################################ | |
245 | # 17. disallow missing tag timestamp | |
e0aaf781 | 246 | |
74f16b0c | 247 | tr '_' ' ' >tag.sig <<EOF |
e0aaf781 BC |
248 | object $head |
249 | type commit | |
250 | tag mytag | |
74f16b0c | 251 | tagger T A Gger <tagger@example.com>__ |
e0aaf781 BC |
252 | |
253 | EOF | |
254 | ||
ba26ab99 | 255 | check_verify_failure 'disallow missing tag timestamp' \ |
acb49d1c | 256 | '^error: char.*: missing tag timestamp$' |
e0aaf781 BC |
257 | |
258 | ############################################################ | |
ba26ab99 | 259 | # 18. detect invalid tag timestamp1 |
e0aaf781 BC |
260 | |
261 | cat >tag.sig <<EOF | |
262 | object $head | |
263 | type commit | |
264 | tag mytag | |
265 | tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008 | |
266 | ||
267 | EOF | |
268 | ||
ba26ab99 | 269 | check_verify_failure 'detect invalid tag timestamp1' \ |
acb49d1c | 270 | '^error: char.*: missing tag timestamp$' |
e0aaf781 BC |
271 | |
272 | ############################################################ | |
ba26ab99 BC |
273 | # 19. detect invalid tag timestamp2 |
274 | ||
275 | cat >tag.sig <<EOF | |
276 | object $head | |
277 | type commit | |
278 | tag mytag | |
279 | tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500 | |
280 | ||
281 | EOF | |
282 | ||
283 | check_verify_failure 'detect invalid tag timestamp2' \ | |
acb49d1c | 284 | '^error: char.*: malformed tag timestamp$' |
ba26ab99 BC |
285 | |
286 | ############################################################ | |
287 | # 20. detect invalid tag timezone1 | |
e0aaf781 BC |
288 | |
289 | cat >tag.sig <<EOF | |
290 | object $head | |
291 | type commit | |
292 | tag mytag | |
293 | tagger T A Gger <tagger@example.com> 1206478233 GMT | |
294 | ||
295 | EOF | |
296 | ||
ba26ab99 | 297 | check_verify_failure 'detect invalid tag timezone1' \ |
acb49d1c | 298 | '^error: char.*: malformed tag timezone$' |
ba26ab99 BC |
299 | |
300 | ############################################################ | |
301 | # 21. detect invalid tag timezone2 | |
302 | ||
303 | cat >tag.sig <<EOF | |
304 | object $head | |
305 | type commit | |
306 | tag mytag | |
307 | tagger T A Gger <tagger@example.com> 1206478233 + 30 | |
308 | ||
309 | EOF | |
310 | ||
311 | check_verify_failure 'detect invalid tag timezone2' \ | |
acb49d1c | 312 | '^error: char.*: malformed tag timezone$' |
ba26ab99 BC |
313 | |
314 | ############################################################ | |
315 | # 22. detect invalid tag timezone3 | |
316 | ||
317 | cat >tag.sig <<EOF | |
318 | object $head | |
319 | type commit | |
320 | tag mytag | |
321 | tagger T A Gger <tagger@example.com> 1206478233 -1430 | |
322 | ||
323 | EOF | |
324 | ||
325 | check_verify_failure 'detect invalid tag timezone3' \ | |
acb49d1c | 326 | '^error: char.*: malformed tag timezone$' |
e0aaf781 BC |
327 | |
328 | ############################################################ | |
ba26ab99 | 329 | # 23. detect invalid header entry |
e0aaf781 BC |
330 | |
331 | cat >tag.sig <<EOF | |
332 | object $head | |
333 | type commit | |
334 | tag mytag | |
335 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
336 | this line should not be here | |
337 | ||
338 | EOF | |
339 | ||
340 | check_verify_failure 'detect invalid header entry' \ | |
acb49d1c | 341 | '^error: char.*: trailing garbage in tag header$' |
e0aaf781 BC |
342 | |
343 | ############################################################ | |
ba26ab99 | 344 | # 24. create valid tag |
e0aaf781 BC |
345 | |
346 | cat >tag.sig <<EOF | |
347 | object $head | |
348 | type commit | |
349 | tag mytag | |
350 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
351 | ||
446c6fae RJ |
352 | EOF |
353 | ||
354 | test_expect_success \ | |
355 | 'create valid tag' \ | |
0cb0e143 | 356 | 'git mktag <tag.sig >.git/refs/tags/mytag 2>message' |
446c6fae RJ |
357 | |
358 | ############################################################ | |
ba26ab99 | 359 | # 25. check mytag |
446c6fae RJ |
360 | |
361 | test_expect_success \ | |
362 | 'check mytag' \ | |
0cb0e143 | 363 | 'git tag -l | grep mytag' |
446c6fae RJ |
364 | |
365 | ||
366 | test_done |