]>
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 () { | |
fce3b089 ÆAB |
15 | subject=$1 && |
16 | message=$2 && | |
17 | shift 2 && | |
18 | ||
19 | no_strict= && | |
20 | while test $# != 0 | |
21 | do | |
22 | case "$1" in | |
23 | --no-strict) | |
24 | no_strict=yes | |
25 | ;; | |
26 | esac && | |
27 | shift | |
28 | done && | |
29 | ||
30 | test_expect_success "fail with [--[no-]strict]: $subject" ' | |
31 | test_must_fail git mktag <tag.sig 2>err && | |
32 | if test -z "$no_strict" | |
06ce7915 | 33 | then |
fce3b089 ÆAB |
34 | test_must_fail git mktag <tag.sig 2>err2 && |
35 | test_cmp err err2 | |
6a748c2c ÆAB |
36 | else |
37 | git mktag --no-strict <tag.sig | |
06ce7915 | 38 | fi |
fce3b089 | 39 | ' |
446c6fae RJ |
40 | } |
41 | ||
ca9a1ed9 ÆAB |
42 | test_expect_mktag_success() { |
43 | test_expect_success "$1" ' | |
44 | git hash-object -t tag -w --stdin <tag.sig >expected && | |
45 | git fsck --strict && | |
46 | ||
47 | git mktag <tag.sig >hash && | |
48 | test_cmp expected hash && | |
49 | test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" && | |
50 | git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) && | |
51 | git fsck --strict | |
52 | ' | |
53 | } | |
54 | ||
446c6fae RJ |
55 | ########################################################### |
56 | # first create a commit, so we have a valid object/type | |
57 | # for the tag. | |
4a45f7dd | 58 | test_expect_success 'setup' ' |
b5ca549c | 59 | test_commit A && |
692654dc ÆAB |
60 | test_commit B && |
61 | head=$(git rev-parse --verify HEAD) && | |
62 | head_parent=$(git rev-parse --verify HEAD~) && | |
63 | tree=$(git rev-parse HEAD^{tree}) && | |
64 | blob=$(git rev-parse --verify HEAD:B.t) | |
4a45f7dd | 65 | ' |
446c6fae | 66 | |
3f390a36 ÆAB |
67 | test_expect_success 'basic usage' ' |
68 | cat >tag.sig <<-EOF && | |
69 | object $head | |
70 | type commit | |
71 | tag mytag | |
72 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
73 | EOF | |
74 | git mktag <tag.sig && | |
75 | git mktag --end-of-options <tag.sig && | |
76 | test_expect_code 129 git mktag --unknown-option | |
77 | ' | |
78 | ||
446c6fae RJ |
79 | ############################################################ |
80 | # 1. length check | |
81 | ||
82 | cat >tag.sig <<EOF | |
83 | too short for a tag | |
84 | EOF | |
85 | ||
e9b20943 | 86 | check_verify_failure 'Tag object length check' \ |
06ce7915 | 87 | '^error:.* missingObject:' 'strict' |
446c6fae RJ |
88 | |
89 | ############################################################ | |
90 | # 2. object line label check | |
91 | ||
92 | cat >tag.sig <<EOF | |
0d35ccb5 | 93 | xxxxxx $head |
446c6fae RJ |
94 | type tag |
95 | tag mytag | |
e0aaf781 BC |
96 | tagger . <> 0 +0000 |
97 | ||
446c6fae RJ |
98 | EOF |
99 | ||
acf9de4c | 100 | check_verify_failure '"object" line label check' '^error:.* missingObject:' |
446c6fae RJ |
101 | |
102 | ############################################################ | |
0d35ccb5 | 103 | # 3. object line hash check |
446c6fae RJ |
104 | |
105 | cat >tag.sig <<EOF | |
0d35ccb5 | 106 | object $(echo $head | tr 0-9a-f z) |
446c6fae RJ |
107 | type tag |
108 | tag mytag | |
e0aaf781 BC |
109 | tagger . <> 0 +0000 |
110 | ||
446c6fae RJ |
111 | EOF |
112 | ||
acf9de4c | 113 | check_verify_failure '"object" line check' '^error:.* badObjectSha1:' |
446c6fae RJ |
114 | |
115 | ############################################################ | |
116 | # 4. type line label check | |
117 | ||
118 | cat >tag.sig <<EOF | |
acb49d1c | 119 | object $head |
446c6fae RJ |
120 | xxxx tag |
121 | tag mytag | |
e0aaf781 BC |
122 | tagger . <> 0 +0000 |
123 | ||
446c6fae RJ |
124 | EOF |
125 | ||
acf9de4c | 126 | check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:' |
446c6fae RJ |
127 | |
128 | ############################################################ | |
129 | # 5. type line eol check | |
130 | ||
acb49d1c | 131 | echo "object $head" >tag.sig |
2aad957a | 132 | printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig |
446c6fae | 133 | |
acf9de4c | 134 | check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:' |
446c6fae RJ |
135 | |
136 | ############################################################ | |
137 | # 6. tag line label check #1 | |
138 | ||
139 | cat >tag.sig <<EOF | |
acb49d1c | 140 | object $head |
446c6fae RJ |
141 | type tag |
142 | xxx mytag | |
e0aaf781 BC |
143 | tagger . <> 0 +0000 |
144 | ||
446c6fae RJ |
145 | EOF |
146 | ||
e9b20943 | 147 | check_verify_failure '"tag" line label check #1' \ |
acf9de4c | 148 | '^error:.* missingTagEntry:' |
446c6fae RJ |
149 | |
150 | ############################################################ | |
151 | # 7. tag line label check #2 | |
152 | ||
153 | cat >tag.sig <<EOF | |
acb49d1c | 154 | object $head |
446c6fae RJ |
155 | type taggggggggggggggggggggggggggggggg |
156 | tag | |
157 | EOF | |
158 | ||
e9b20943 | 159 | check_verify_failure '"tag" line label check #2' \ |
acf9de4c | 160 | '^error:.* badType:' |
446c6fae RJ |
161 | |
162 | ############################################################ | |
163 | # 8. type line type-name length check | |
164 | ||
165 | cat >tag.sig <<EOF | |
acb49d1c | 166 | object $head |
446c6fae RJ |
167 | type taggggggggggggggggggggggggggggggg |
168 | tag mytag | |
169 | EOF | |
170 | ||
e9b20943 | 171 | check_verify_failure '"type" line type-name length check' \ |
acf9de4c | 172 | '^error:.* badType:' |
446c6fae RJ |
173 | |
174 | ############################################################ | |
30f882c1 | 175 | # 9. verify object (hash/type) check |
446c6fae RJ |
176 | |
177 | cat >tag.sig <<EOF | |
acb49d1c | 178 | object $(test_oid deadbeef) |
30f882c1 ÆAB |
179 | type tag |
180 | tag mytag | |
181 | tagger . <> 0 +0000 | |
182 | ||
183 | EOF | |
184 | ||
185 | check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \ | |
acf9de4c | 186 | '^fatal: could not read tagged object' |
30f882c1 ÆAB |
187 | |
188 | cat >tag.sig <<EOF | |
189 | object $head | |
446c6fae RJ |
190 | type tagggg |
191 | tag mytag | |
e0aaf781 BC |
192 | tagger . <> 0 +0000 |
193 | ||
446c6fae RJ |
194 | EOF |
195 | ||
30f882c1 | 196 | check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \ |
acf9de4c | 197 | '^error:.* badType:' |
30f882c1 ÆAB |
198 | |
199 | cat >tag.sig <<EOF | |
200 | object $(test_oid deadbeef) | |
201 | type tagggg | |
202 | tag mytag | |
203 | tagger . <> 0 +0000 | |
204 | ||
205 | EOF | |
206 | ||
207 | check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \ | |
acf9de4c | 208 | '^error:.* badType:' |
446c6fae | 209 | |
30f882c1 ÆAB |
210 | cat >tag.sig <<EOF |
211 | object $head | |
212 | type tree | |
213 | tag mytag | |
214 | tagger . <> 0 +0000 | |
215 | ||
216 | EOF | |
217 | ||
692654dc | 218 | check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ |
acf9de4c | 219 | '^fatal: object.*tagged as.*tree.*but is.*commit' |
692654dc ÆAB |
220 | |
221 | ############################################################ | |
222 | # 9.5. verify object (hash/type) check -- replacement | |
223 | ||
224 | test_expect_success 'setup replacement of commit -> commit and tree -> blob' ' | |
225 | git replace $head_parent $head && | |
226 | git replace -f $tree $blob | |
227 | ' | |
228 | ||
229 | cat >tag.sig <<EOF | |
230 | object $head_parent | |
231 | type commit | |
232 | tag mytag | |
233 | tagger . <> 0 +0000 | |
234 | ||
235 | EOF | |
236 | ||
237 | test_expect_mktag_success 'tag to a commit replaced by another commit' | |
238 | ||
239 | cat >tag.sig <<EOF | |
240 | object $tree | |
241 | type tree | |
242 | tag mytag | |
243 | tagger . <> 0 +0000 | |
244 | ||
245 | EOF | |
246 | ||
30f882c1 | 247 | check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ |
acf9de4c | 248 | '^fatal: object.*tagged as.*tree.*but is.*blob' |
30f882c1 | 249 | |
446c6fae RJ |
250 | ############################################################ |
251 | # 10. verify tag-name check | |
252 | ||
253 | cat >tag.sig <<EOF | |
254 | object $head | |
255 | type commit | |
256 | tag my tag | |
e0aaf781 BC |
257 | tagger . <> 0 +0000 |
258 | ||
446c6fae RJ |
259 | EOF |
260 | ||
e9b20943 | 261 | check_verify_failure 'verify tag-name check' \ |
fce3b089 ÆAB |
262 | '^error:.* badTagName:' \ |
263 | --no-strict | |
446c6fae RJ |
264 | |
265 | ############################################################ | |
3dff5379 | 266 | # 11. tagger line label check #1 |
446c6fae RJ |
267 | |
268 | cat >tag.sig <<EOF | |
269 | object $head | |
270 | type commit | |
271 | tag mytag | |
e0aaf781 BC |
272 | |
273 | This is filler | |
446c6fae RJ |
274 | EOF |
275 | ||
e9b20943 | 276 | check_verify_failure '"tagger" line label check #1' \ |
fce3b089 ÆAB |
277 | '^error:.* missingTaggerEntry:' \ |
278 | --no-strict | |
446c6fae RJ |
279 | |
280 | ############################################################ | |
3dff5379 | 281 | # 12. tagger line label check #2 |
446c6fae RJ |
282 | |
283 | cat >tag.sig <<EOF | |
284 | object $head | |
285 | type commit | |
286 | tag mytag | |
287 | tagger | |
e0aaf781 BC |
288 | |
289 | This is filler | |
446c6fae RJ |
290 | EOF |
291 | ||
e9b20943 | 292 | check_verify_failure '"tagger" line label check #2' \ |
fce3b089 ÆAB |
293 | '^error:.* missingTaggerEntry:' \ |
294 | --no-strict | |
446c6fae RJ |
295 | |
296 | ############################################################ | |
acf9de4c | 297 | # 13. allow missing tag author name like fsck |
446c6fae RJ |
298 | |
299 | cat >tag.sig <<EOF | |
300 | object $head | |
301 | type commit | |
302 | tag mytag | |
e0aaf781 BC |
303 | tagger <> 0 +0000 |
304 | ||
305 | This is filler | |
306 | EOF | |
307 | ||
acf9de4c | 308 | test_expect_mktag_success 'allow missing tag author name' |
e0aaf781 BC |
309 | |
310 | ############################################################ | |
ba26ab99 | 311 | # 14. disallow missing tag author name |
e0aaf781 BC |
312 | |
313 | cat >tag.sig <<EOF | |
314 | object $head | |
315 | type commit | |
316 | tag mytag | |
317 | tagger T A Gger < | |
318 | > 0 +0000 | |
319 | ||
320 | EOF | |
321 | ||
ba26ab99 | 322 | check_verify_failure 'disallow malformed tagger' \ |
fce3b089 ÆAB |
323 | '^error:.* badEmail:' \ |
324 | --no-strict | |
e0aaf781 BC |
325 | |
326 | ############################################################ | |
327 | # 15. allow empty tag email | |
328 | ||
329 | cat >tag.sig <<EOF | |
330 | object $head | |
331 | type commit | |
332 | tag mytag | |
333 | tagger T A Gger <> 0 +0000 | |
334 | ||
335 | EOF | |
336 | ||
ca9a1ed9 | 337 | test_expect_mktag_success 'allow empty tag email' |
e0aaf781 BC |
338 | |
339 | ############################################################ | |
acf9de4c | 340 | # 16. allow spaces in tag email like fsck |
ba26ab99 BC |
341 | |
342 | cat >tag.sig <<EOF | |
343 | object $head | |
344 | type commit | |
345 | tag mytag | |
346 | tagger T A Gger <tag ger@example.com> 0 +0000 | |
347 | ||
348 | EOF | |
349 | ||
acf9de4c | 350 | test_expect_mktag_success 'allow spaces in tag email like fsck' |
ba26ab99 BC |
351 | |
352 | ############################################################ | |
353 | # 17. disallow missing tag timestamp | |
e0aaf781 | 354 | |
74f16b0c | 355 | tr '_' ' ' >tag.sig <<EOF |
e0aaf781 BC |
356 | object $head |
357 | type commit | |
358 | tag mytag | |
74f16b0c | 359 | tagger T A Gger <tagger@example.com>__ |
e0aaf781 BC |
360 | |
361 | EOF | |
362 | ||
ba26ab99 | 363 | check_verify_failure 'disallow missing tag timestamp' \ |
acf9de4c | 364 | '^error:.* badDate:' |
e0aaf781 BC |
365 | |
366 | ############################################################ | |
ba26ab99 | 367 | # 18. detect invalid tag timestamp1 |
e0aaf781 BC |
368 | |
369 | cat >tag.sig <<EOF | |
370 | object $head | |
371 | type commit | |
372 | tag mytag | |
373 | tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008 | |
374 | ||
375 | EOF | |
376 | ||
ba26ab99 | 377 | check_verify_failure 'detect invalid tag timestamp1' \ |
acf9de4c | 378 | '^error:.* badDate:' |
e0aaf781 BC |
379 | |
380 | ############################################################ | |
ba26ab99 BC |
381 | # 19. detect invalid tag timestamp2 |
382 | ||
383 | cat >tag.sig <<EOF | |
384 | object $head | |
385 | type commit | |
386 | tag mytag | |
387 | tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500 | |
388 | ||
389 | EOF | |
390 | ||
391 | check_verify_failure 'detect invalid tag timestamp2' \ | |
acf9de4c | 392 | '^error:.* badDate:' |
ba26ab99 BC |
393 | |
394 | ############################################################ | |
395 | # 20. detect invalid tag timezone1 | |
e0aaf781 BC |
396 | |
397 | cat >tag.sig <<EOF | |
398 | object $head | |
399 | type commit | |
400 | tag mytag | |
401 | tagger T A Gger <tagger@example.com> 1206478233 GMT | |
402 | ||
403 | EOF | |
404 | ||
ba26ab99 | 405 | check_verify_failure 'detect invalid tag timezone1' \ |
acf9de4c | 406 | '^error:.* badTimezone:' |
ba26ab99 BC |
407 | |
408 | ############################################################ | |
409 | # 21. detect invalid tag timezone2 | |
410 | ||
411 | cat >tag.sig <<EOF | |
412 | object $head | |
413 | type commit | |
414 | tag mytag | |
415 | tagger T A Gger <tagger@example.com> 1206478233 + 30 | |
416 | ||
417 | EOF | |
418 | ||
419 | check_verify_failure 'detect invalid tag timezone2' \ | |
acf9de4c | 420 | '^error:.* badTimezone:' |
ba26ab99 BC |
421 | |
422 | ############################################################ | |
acf9de4c | 423 | # 22. allow invalid tag timezone3 (the maximum is -1200/+1400) |
ba26ab99 BC |
424 | |
425 | cat >tag.sig <<EOF | |
426 | object $head | |
427 | type commit | |
428 | tag mytag | |
429 | tagger T A Gger <tagger@example.com> 1206478233 -1430 | |
430 | ||
431 | EOF | |
432 | ||
acf9de4c | 433 | test_expect_mktag_success 'allow invalid tag timezone' |
e0aaf781 BC |
434 | |
435 | ############################################################ | |
ba26ab99 | 436 | # 23. detect invalid header entry |
e0aaf781 BC |
437 | |
438 | cat >tag.sig <<EOF | |
439 | object $head | |
440 | type commit | |
441 | tag mytag | |
442 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
443 | this line should not be here | |
444 | ||
445 | EOF | |
446 | ||
447 | check_verify_failure 'detect invalid header entry' \ | |
fce3b089 ÆAB |
448 | '^error:.* extraHeaderEntry:' \ |
449 | --no-strict | |
e0aaf781 | 450 | |
acfc0133 ÆAB |
451 | test_expect_success 'invalid header entry config & fsck' ' |
452 | test_must_fail git mktag <tag.sig && | |
06ce7915 ÆAB |
453 | git mktag --no-strict <tag.sig && |
454 | ||
acfc0133 | 455 | test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig && |
06ce7915 ÆAB |
456 | test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig && |
457 | ||
acfc0133 | 458 | test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig && |
06ce7915 ÆAB |
459 | git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig && |
460 | ||
acfc0133 | 461 | git -c fsck.extraHeaderEntry=ignore mktag <tag.sig && |
06ce7915 ÆAB |
462 | git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig && |
463 | ||
acfc0133 | 464 | git fsck && |
780aa0a2 | 465 | git -c fsck.extraHeaderEntry=warn fsck 2>err && |
acfc0133 | 466 | grep "warning .*extraHeaderEntry:" err && |
780aa0a2 | 467 | test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck && |
acfc0133 ÆAB |
468 | grep "error .* extraHeaderEntry:" err |
469 | ' | |
470 | ||
47c95e77 ÆAB |
471 | cat >tag.sig <<EOF |
472 | object $head | |
473 | type commit | |
474 | tag mytag | |
475 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
476 | ||
477 | ||
478 | this line comes after an extra newline | |
479 | EOF | |
480 | ||
ca9a1ed9 | 481 | test_expect_mktag_success 'allow extra newlines at start of body' |
47c95e77 ÆAB |
482 | |
483 | cat >tag.sig <<EOF | |
484 | object $head | |
485 | type commit | |
486 | tag mytag | |
487 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
488 | ||
489 | EOF | |
490 | ||
9a1a3a4d | 491 | test_expect_mktag_success 'allow a blank line before an empty body (1)' |
47c95e77 ÆAB |
492 | |
493 | cat >tag.sig <<EOF | |
494 | object $head | |
495 | type commit | |
496 | tag mytag | |
497 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
498 | EOF | |
499 | ||
9a1a3a4d | 500 | test_expect_mktag_success 'allow no blank line before an empty body (2)' |
47c95e77 | 501 | |
e0aaf781 | 502 | ############################################################ |
ba26ab99 | 503 | # 24. create valid tag |
e0aaf781 BC |
504 | |
505 | cat >tag.sig <<EOF | |
506 | object $head | |
507 | type commit | |
508 | tag mytag | |
509 | tagger T A Gger <tagger@example.com> 1206478233 -0500 | |
446c6fae RJ |
510 | EOF |
511 | ||
ca9a1ed9 | 512 | test_expect_mktag_success 'create valid tag object' |
446c6fae RJ |
513 | |
514 | test_done |