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