##// END OF EJS Templates
test-archive: gracefully handle HTTPErrors on get-with-headers...
Angel Ezquerra -
r18770:dcb6a99e default
parent child Browse files
Show More
@@ -1,300 +1,308
1 1 $ "$TESTDIR/hghave" serve || exit 80
2 2
3 3 $ hg init test
4 4 $ cd test
5 5 $ echo foo>foo
6 6 $ hg commit -Am 1 -d '1 0'
7 7 adding foo
8 8 $ echo bar>bar
9 9 $ hg commit -Am 2 -d '2 0'
10 10 adding bar
11 11 $ mkdir baz
12 12 $ echo bletch>baz/bletch
13 13 $ hg commit -Am 3 -d '1000000000 0'
14 14 adding baz/bletch
15 15 $ echo "[web]" >> .hg/hgrc
16 16 $ echo "name = test-archive" >> .hg/hgrc
17 17 $ cp .hg/hgrc .hg/hgrc-base
18 18 > test_archtype() {
19 19 > echo "allow_archive = $1" >> .hg/hgrc
20 20 > hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
21 21 > cat hg.pid >> $DAEMON_PIDS
22 22 > echo % $1 allowed should give 200
23 23 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "archive/tip.$2" | head -n 1
24 24 > echo % $3 and $4 disallowed should both give 403
25 25 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "archive/tip.$3" | head -n 1
26 26 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "archive/tip.$4" | head -n 1
27 27 > "$TESTDIR/killdaemons.py" $DAEMON_PIDS
28 28 > cat errors.log
29 29 > cp .hg/hgrc-base .hg/hgrc
30 30 > }
31 31
32 32 check http return codes
33 33
34 34 $ test_archtype gz tar.gz tar.bz2 zip
35 35 % gz allowed should give 200
36 36 200 Script output follows
37 37 % tar.bz2 and zip disallowed should both give 403
38 38 403 Archive type not allowed: bz2
39 39 403 Archive type not allowed: zip
40 40 $ test_archtype bz2 tar.bz2 zip tar.gz
41 41 % bz2 allowed should give 200
42 42 200 Script output follows
43 43 % zip and tar.gz disallowed should both give 403
44 44 403 Archive type not allowed: zip
45 45 403 Archive type not allowed: gz
46 46 $ test_archtype zip zip tar.gz tar.bz2
47 47 % zip allowed should give 200
48 48 200 Script output follows
49 49 % tar.gz and tar.bz2 disallowed should both give 403
50 50 403 Archive type not allowed: gz
51 51 403 Archive type not allowed: bz2
52 52
53 53 $ echo "allow_archive = gz bz2 zip" >> .hg/hgrc
54 54 $ hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
55 55 $ cat hg.pid >> $DAEMON_PIDS
56 56
57 57 invalid arch type should give 404
58 58
59 59 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT "archive/tip.invalid" | head -n 1
60 60 404 Unsupported archive type: None
61 61
62 62 $ TIP=`hg id -v | cut -f1 -d' '`
63 63 $ QTIP=`hg id -q`
64 64 $ cat > getarchive.py <<EOF
65 65 > import os, sys, urllib2
66 66 > try:
67 67 > # Set stdout to binary mode for win32 platforms
68 68 > import msvcrt
69 69 > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
70 70 > except ImportError:
71 71 > pass
72 > node, archive = sys.argv[1:]
73 > f = urllib2.urlopen('http://127.0.0.1:%s/?cmd=archive;node=%s;type=%s'
74 > % (os.environ['HGPORT'], node, archive))
75 > sys.stdout.write(f.read())
72 > if len(sys.argv) <= 3:
73 > node, archive = sys.argv[1:]
74 > requeststr = 'cmd=archive;node=%s;type=%s' % (node, archive)
75 > else:
76 > node, archive, file = sys.argv[1:]
77 > requeststr = 'cmd=archive;node=%s;type=%s;file=%s' % (node, archive, file)
78 > try:
79 > f = urllib2.urlopen('http://127.0.0.1:%s/?%s'
80 > % (os.environ['HGPORT'], requeststr))
81 > sys.stdout.write(f.read())
82 > except urllib2.HTTPError, e:
83 > sys.stderr.write(str(e) + '\n')
76 84 > EOF
77 85 $ python getarchive.py "$TIP" gz | gunzip | tar tf - 2>/dev/null
78 86 test-archive-2c0277f05ed4/.hg_archival.txt
79 87 test-archive-2c0277f05ed4/bar
80 88 test-archive-2c0277f05ed4/baz/bletch
81 89 test-archive-2c0277f05ed4/foo
82 90 $ python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - 2>/dev/null
83 91 test-archive-2c0277f05ed4/.hg_archival.txt
84 92 test-archive-2c0277f05ed4/bar
85 93 test-archive-2c0277f05ed4/baz/bletch
86 94 test-archive-2c0277f05ed4/foo
87 95 $ python getarchive.py "$TIP" zip > archive.zip
88 96 $ unzip -t archive.zip
89 97 Archive: archive.zip
90 98 testing: test-archive-2c0277f05ed4/.hg_archival.txt OK
91 99 testing: test-archive-2c0277f05ed4/bar OK
92 100 testing: test-archive-2c0277f05ed4/baz/bletch OK
93 101 testing: test-archive-2c0277f05ed4/foo OK
94 102 No errors detected in compressed data of archive.zip.
95 103
96 104 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
97 105
98 106 $ hg archive -t tar test.tar
99 107 $ tar tf test.tar
100 108 test/.hg_archival.txt
101 109 test/bar
102 110 test/baz/bletch
103 111 test/foo
104 112
105 113 $ hg archive --debug -t tbz2 -X baz test.tar.bz2
106 114 archiving: 0/2 files (0.00%)
107 115 archiving: bar 1/2 files (50.00%)
108 116 archiving: foo 2/2 files (100.00%)
109 117 $ bunzip2 -dc test.tar.bz2 | tar tf - 2>/dev/null
110 118 test/.hg_archival.txt
111 119 test/bar
112 120 test/foo
113 121
114 122 $ hg archive -t tgz -p %b-%h test-%h.tar.gz
115 123 $ gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null
116 124 test-2c0277f05ed4/.hg_archival.txt
117 125 test-2c0277f05ed4/bar
118 126 test-2c0277f05ed4/baz/bletch
119 127 test-2c0277f05ed4/foo
120 128
121 129 $ hg archive autodetected_test.tar
122 130 $ tar tf autodetected_test.tar
123 131 autodetected_test/.hg_archival.txt
124 132 autodetected_test/bar
125 133 autodetected_test/baz/bletch
126 134 autodetected_test/foo
127 135
128 136 The '-t' should override autodetection
129 137
130 138 $ hg archive -t tar autodetect_override_test.zip
131 139 $ tar tf autodetect_override_test.zip
132 140 autodetect_override_test.zip/.hg_archival.txt
133 141 autodetect_override_test.zip/bar
134 142 autodetect_override_test.zip/baz/bletch
135 143 autodetect_override_test.zip/foo
136 144
137 145 $ for ext in tar tar.gz tgz tar.bz2 tbz2 zip; do
138 146 > hg archive auto_test.$ext
139 147 > if [ -d auto_test.$ext ]; then
140 148 > echo "extension $ext was not autodetected."
141 149 > fi
142 150 > done
143 151
144 152 $ cat > md5comp.py <<EOF
145 153 > try:
146 154 > from hashlib import md5
147 155 > except ImportError:
148 156 > from md5 import md5
149 157 > import sys
150 158 > f1, f2 = sys.argv[1:3]
151 159 > h1 = md5(file(f1, 'rb').read()).hexdigest()
152 160 > h2 = md5(file(f2, 'rb').read()).hexdigest()
153 161 > print h1 == h2 or "md5 differ: " + repr((h1, h2))
154 162 > EOF
155 163
156 164 archive name is stored in the archive, so create similar archives and
157 165 rename them afterwards.
158 166
159 167 $ hg archive -t tgz tip.tar.gz
160 168 $ mv tip.tar.gz tip1.tar.gz
161 169 $ sleep 1
162 170 $ hg archive -t tgz tip.tar.gz
163 171 $ mv tip.tar.gz tip2.tar.gz
164 172 $ python md5comp.py tip1.tar.gz tip2.tar.gz
165 173 True
166 174
167 175 $ hg archive -t zip -p /illegal test.zip
168 176 abort: archive prefix contains illegal components
169 177 [255]
170 178 $ hg archive -t zip -p very/../bad test.zip
171 179
172 180 $ hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
173 181 $ unzip -t test.zip
174 182 Archive: test.zip
175 183 testing: test/bar OK
176 184 testing: test/baz/bletch OK
177 185 testing: test/foo OK
178 186 No errors detected in compressed data of test.zip.
179 187
180 188 $ hg archive -t tar - | tar tf - 2>/dev/null
181 189 test-2c0277f05ed4/.hg_archival.txt
182 190 test-2c0277f05ed4/bar
183 191 test-2c0277f05ed4/baz/bletch
184 192 test-2c0277f05ed4/foo
185 193
186 194 $ hg archive -r 0 -t tar rev-%r.tar
187 195 $ if [ -f rev-0.tar ]; then
188 196 $ fi
189 197
190 198 test .hg_archival.txt
191 199
192 200 $ hg archive ../test-tags
193 201 $ cat ../test-tags/.hg_archival.txt
194 202 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
195 203 node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
196 204 branch: default
197 205 latesttag: null
198 206 latesttagdistance: 3
199 207 $ hg tag -r 2 mytag
200 208 $ hg tag -r 2 anothertag
201 209 $ hg archive -r 2 ../test-lasttag
202 210 $ cat ../test-lasttag/.hg_archival.txt
203 211 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
204 212 node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
205 213 branch: default
206 214 tag: anothertag
207 215 tag: mytag
208 216
209 217 $ hg archive -t bogus test.bogus
210 218 abort: unknown archive type 'bogus'
211 219 [255]
212 220
213 221 enable progress extension:
214 222
215 223 $ cp $HGRCPATH $HGRCPATH.no-progress
216 224 $ cat >> $HGRCPATH <<EOF
217 225 > [extensions]
218 226 > progress =
219 227 > [progress]
220 228 > assume-tty = 1
221 229 > format = topic bar number
222 230 > delay = 0
223 231 > refresh = 0
224 232 > width = 60
225 233 > EOF
226 234
227 235 $ hg archive ../with-progress
228 236 \r (no-eol) (esc)
229 237 archiving [ ] 0/4\r (no-eol) (esc)
230 238 archiving [ ] 0/4\r (no-eol) (esc)
231 239 archiving [=========> ] 1/4\r (no-eol) (esc)
232 240 archiving [=========> ] 1/4\r (no-eol) (esc)
233 241 archiving [====================> ] 2/4\r (no-eol) (esc)
234 242 archiving [====================> ] 2/4\r (no-eol) (esc)
235 243 archiving [===============================> ] 3/4\r (no-eol) (esc)
236 244 archiving [===============================> ] 3/4\r (no-eol) (esc)
237 245 archiving [==========================================>] 4/4\r (no-eol) (esc)
238 246 archiving [==========================================>] 4/4\r (no-eol) (esc)
239 247 \r (no-eol) (esc)
240 248
241 249 cleanup after progress extension test:
242 250
243 251 $ cp $HGRCPATH.no-progress $HGRCPATH
244 252
245 253 server errors
246 254
247 255 $ cat errors.log
248 256
249 257 empty repo
250 258
251 259 $ hg init ../empty
252 260 $ cd ../empty
253 261 $ hg archive ../test-empty
254 262 abort: no working directory: please specify a revision
255 263 [255]
256 264
257 265 old file -- date clamped to 1980
258 266
259 267 $ touch -t 197501010000 old
260 268 $ hg add old
261 269 $ hg commit -m old
262 270 $ hg archive ../old.zip
263 271 $ unzip -l ../old.zip
264 272 Archive: ../old.zip
265 273 \s*Length.* (re)
266 274 *-----* (glob)
267 275 *147*80*00:00*old/.hg_archival.txt (glob)
268 276 *0*80*00:00*old/old (glob)
269 277 *-----* (glob)
270 278 \s*147\s+2 files (re)
271 279
272 280 $ cd ..
273 281
274 282 issue3600: check whether "hg archive" can create archive files which
275 283 are extracted with expected timestamp, even though TZ is not
276 284 configured as GMT.
277 285
278 286 $ mkdir issue3600
279 287 $ cd issue3600
280 288
281 289 $ hg init repo
282 290 $ echo a > repo/a
283 291 $ hg -R repo add repo/a
284 292 $ hg -R repo commit -m '#0' -d '456789012 21600'
285 293 $ cat > show_mtime.py <<EOF
286 294 > import sys, os
287 295 > print int(os.stat(sys.argv[1]).st_mtime)
288 296 > EOF
289 297
290 298 $ hg -R repo archive --prefix tar-extracted archive.tar
291 299 $ (TZ=UTC-3; export TZ; tar xf archive.tar)
292 300 $ python show_mtime.py tar-extracted/a
293 301 456789012
294 302
295 303 $ hg -R repo archive --prefix zip-extracted archive.zip
296 304 $ (TZ=UTC-3; export TZ; unzip -q archive.zip)
297 305 $ python show_mtime.py zip-extracted/a
298 306 456789012
299 307
300 308 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now