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