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