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