##// END OF EJS Templates
tests: extract wire protocol shell helpers to standalone file...
Gregory Szorc -
r37500:fa9faf58 default
parent child Browse files
Show More
@@ -0,0 +1,41 b''
1 HTTPV2=exp-http-v2-0001
2 MEDIATYPE=application/mercurial-exp-framing-0003
3
4 sendhttpraw() {
5 hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
6 }
7
8 cat > dummycommands.py << EOF
9 from mercurial import (
10 wireprototypes,
11 wireproto,
12 )
13
14 @wireproto.wireprotocommand('customreadonly', permission='pull')
15 def customreadonly(repo, proto):
16 return wireprototypes.bytesresponse(b'customreadonly bytes response')
17
18 @wireproto.wireprotocommand('customreadwrite', permission='push')
19 def customreadwrite(repo, proto):
20 return wireprototypes.bytesresponse(b'customreadwrite bytes response')
21 EOF
22
23 cat >> $HGRCPATH << EOF
24 [extensions]
25 drawdag = $TESTDIR/drawdag.py
26 EOF
27
28 enabledummycommands() {
29 cat >> $HGRCPATH << EOF
30 [extensions]
31 dummycommands = $TESTTMP/dummycommands.py
32 EOF
33 }
34
35 enablehttpv2() {
36 cat >> $1/.hg/hgrc << EOF
37 [experimental]
38 web.apiserver = true
39 web.api.http-v2 = true
40 EOF
41 }
@@ -1,24 +1,5 b''
1 $ HTTPV2=exp-http-v2-0001
1 $ . $TESTDIR/wireprotohelpers.sh
2 $ MEDIATYPE=application/mercurial-exp-framing-0003
2 $ enabledummycommands
3
4 $ send() {
5 > hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
6 > }
7
8 $ cat > dummycommands.py << EOF
9 > from mercurial import wireprototypes, wireproto
10 > @wireproto.wireprotocommand('customreadonly', permission='pull')
11 > def customreadonly(repo, proto):
12 > return wireprototypes.bytesresponse(b'customreadonly bytes response')
13 > @wireproto.wireprotocommand('customreadwrite', permission='push')
14 > def customreadwrite(repo, proto):
15 > return wireprototypes.bytesresponse(b'customreadwrite bytes response')
16 > EOF
17
18 $ cat >> $HGRCPATH << EOF
19 > [extensions]
20 > dummycommands = $TESTTMP/dummycommands.py
21 > EOF
22
3
23 $ hg init server
4 $ hg init server
24 $ cat > server/.hg/hgrc << EOF
5 $ cat > server/.hg/hgrc << EOF
@@ -30,7 +11,7 b''
30
11
31 HTTP v2 protocol not enabled by default
12 HTTP v2 protocol not enabled by default
32
13
33 $ send << EOF
14 $ sendhttpraw << EOF
34 > httprequest GET api/$HTTPV2
15 > httprequest GET api/$HTTPV2
35 > user-agent: test
16 > user-agent: test
36 > EOF
17 > EOF
@@ -52,18 +33,13 b' HTTP v2 protocol not enabled by default'
52 Restart server with support for HTTP v2 API
33 Restart server with support for HTTP v2 API
53
34
54 $ killdaemons.py
35 $ killdaemons.py
55 $ cat > server/.hg/hgrc << EOF
36 $ enablehttpv2 server
56 > [experimental]
57 > web.apiserver = true
58 > web.api.http-v2 = true
59 > EOF
60
61 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
37 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
62 $ cat hg.pid > $DAEMON_PIDS
38 $ cat hg.pid > $DAEMON_PIDS
63
39
64 Request to unknown command yields 404
40 Request to unknown command yields 404
65
41
66 $ send << EOF
42 $ sendhttpraw << EOF
67 > httprequest POST api/$HTTPV2/ro/badcommand
43 > httprequest POST api/$HTTPV2/ro/badcommand
68 > user-agent: test
44 > user-agent: test
69 > EOF
45 > EOF
@@ -84,7 +60,7 b' Request to unknown command yields 404'
84
60
85 GET to read-only command yields a 405
61 GET to read-only command yields a 405
86
62
87 $ send << EOF
63 $ sendhttpraw << EOF
88 > httprequest GET api/$HTTPV2/ro/customreadonly
64 > httprequest GET api/$HTTPV2/ro/customreadonly
89 > user-agent: test
65 > user-agent: test
90 > EOF
66 > EOF
@@ -105,7 +81,7 b' GET to read-only command yields a 405'
105
81
106 Missing Accept header results in 406
82 Missing Accept header results in 406
107
83
108 $ send << EOF
84 $ sendhttpraw << EOF
109 > httprequest POST api/$HTTPV2/ro/customreadonly
85 > httprequest POST api/$HTTPV2/ro/customreadonly
110 > user-agent: test
86 > user-agent: test
111 > EOF
87 > EOF
@@ -126,7 +102,7 b' Missing Accept header results in 406'
126
102
127 Bad Accept header results in 406
103 Bad Accept header results in 406
128
104
129 $ send << EOF
105 $ sendhttpraw << EOF
130 > httprequest POST api/$HTTPV2/ro/customreadonly
106 > httprequest POST api/$HTTPV2/ro/customreadonly
131 > accept: invalid
107 > accept: invalid
132 > user-agent: test
108 > user-agent: test
@@ -149,7 +125,7 b' Bad Accept header results in 406'
149
125
150 Bad Content-Type header results in 415
126 Bad Content-Type header results in 415
151
127
152 $ send << EOF
128 $ sendhttpraw << EOF
153 > httprequest POST api/$HTTPV2/ro/customreadonly
129 > httprequest POST api/$HTTPV2/ro/customreadonly
154 > accept: $MEDIATYPE
130 > accept: $MEDIATYPE
155 > user-agent: test
131 > user-agent: test
@@ -174,7 +150,7 b' Bad Content-Type header results in 415'
174
150
175 Request to read-only command works out of the box
151 Request to read-only command works out of the box
176
152
177 $ send << EOF
153 $ sendhttpraw << EOF
178 > httprequest POST api/$HTTPV2/ro/customreadonly
154 > httprequest POST api/$HTTPV2/ro/customreadonly
179 > accept: $MEDIATYPE
155 > accept: $MEDIATYPE
180 > content-type: $MEDIATYPE
156 > content-type: $MEDIATYPE
@@ -208,7 +184,7 b' Request to read-write command fails beca'
208
184
209 GET to read-write request yields 405
185 GET to read-write request yields 405
210
186
211 $ send << EOF
187 $ sendhttpraw << EOF
212 > httprequest GET api/$HTTPV2/rw/customreadonly
188 > httprequest GET api/$HTTPV2/rw/customreadonly
213 > user-agent: test
189 > user-agent: test
214 > EOF
190 > EOF
@@ -229,7 +205,7 b' GET to read-write request yields 405'
229
205
230 Even for unknown commands
206 Even for unknown commands
231
207
232 $ send << EOF
208 $ sendhttpraw << EOF
233 > httprequest GET api/$HTTPV2/rw/badcommand
209 > httprequest GET api/$HTTPV2/rw/badcommand
234 > user-agent: test
210 > user-agent: test
235 > EOF
211 > EOF
@@ -250,7 +226,7 b' Even for unknown commands'
250
226
251 SSL required by default
227 SSL required by default
252
228
253 $ send << EOF
229 $ sendhttpraw << EOF
254 > httprequest POST api/$HTTPV2/rw/customreadonly
230 > httprequest POST api/$HTTPV2/rw/customreadonly
255 > user-agent: test
231 > user-agent: test
256 > EOF
232 > EOF
@@ -285,7 +261,7 b' Restart server to allow non-ssl read-wri'
285
261
286 Authorized request for valid read-write command works
262 Authorized request for valid read-write command works
287
263
288 $ send << EOF
264 $ sendhttpraw << EOF
289 > httprequest POST api/$HTTPV2/rw/customreadonly
265 > httprequest POST api/$HTTPV2/rw/customreadonly
290 > user-agent: test
266 > user-agent: test
291 > accept: $MEDIATYPE
267 > accept: $MEDIATYPE
@@ -317,7 +293,7 b' Authorized request for valid read-write '
317
293
318 Authorized request for unknown command is rejected
294 Authorized request for unknown command is rejected
319
295
320 $ send << EOF
296 $ sendhttpraw << EOF
321 > httprequest POST api/$HTTPV2/rw/badcommand
297 > httprequest POST api/$HTTPV2/rw/badcommand
322 > user-agent: test
298 > user-agent: test
323 > accept: $MEDIATYPE
299 > accept: $MEDIATYPE
@@ -340,7 +316,7 b' Authorized request for unknown command i'
340
316
341 debugreflect isn't enabled by default
317 debugreflect isn't enabled by default
342
318
343 $ send << EOF
319 $ sendhttpraw << EOF
344 > httprequest POST api/$HTTPV2/ro/debugreflect
320 > httprequest POST api/$HTTPV2/ro/debugreflect
345 > user-agent: test
321 > user-agent: test
346 > EOF
322 > EOF
@@ -377,7 +353,7 b' Restart server to get debugreflect endpo'
377
353
378 Command frames can be reflected via debugreflect
354 Command frames can be reflected via debugreflect
379
355
380 $ send << EOF
356 $ sendhttpraw << EOF
381 > httprequest POST api/$HTTPV2/ro/debugreflect
357 > httprequest POST api/$HTTPV2/ro/debugreflect
382 > accept: $MEDIATYPE
358 > accept: $MEDIATYPE
383 > content-type: $MEDIATYPE
359 > content-type: $MEDIATYPE
@@ -408,7 +384,7 b' Command frames can be reflected via debu'
408
384
409 Multiple requests to regular command URL are not allowed
385 Multiple requests to regular command URL are not allowed
410
386
411 $ send << EOF
387 $ sendhttpraw << EOF
412 > httprequest POST api/$HTTPV2/ro/customreadonly
388 > httprequest POST api/$HTTPV2/ro/customreadonly
413 > accept: $MEDIATYPE
389 > accept: $MEDIATYPE
414 > content-type: $MEDIATYPE
390 > content-type: $MEDIATYPE
@@ -440,7 +416,7 b' Multiple requests to regular command URL'
440
416
441 Multiple requests to "multirequest" URL are allowed
417 Multiple requests to "multirequest" URL are allowed
442
418
443 $ send << EOF
419 $ sendhttpraw << EOF
444 > httprequest POST api/$HTTPV2/ro/multirequest
420 > httprequest POST api/$HTTPV2/ro/multirequest
445 > accept: $MEDIATYPE
421 > accept: $MEDIATYPE
446 > content-type: $MEDIATYPE
422 > content-type: $MEDIATYPE
@@ -476,7 +452,7 b' Multiple requests to "multirequest" URL '
476
452
477 Interleaved requests to "multirequest" are processed
453 Interleaved requests to "multirequest" are processed
478
454
479 $ send << EOF
455 $ sendhttpraw << EOF
480 > httprequest POST api/$HTTPV2/ro/multirequest
456 > httprequest POST api/$HTTPV2/ro/multirequest
481 > accept: $MEDIATYPE
457 > accept: $MEDIATYPE
482 > content-type: $MEDIATYPE
458 > content-type: $MEDIATYPE
@@ -531,7 +507,7 b' Restart server to disable read-write acc'
531
507
532 Attempting to run a read-write command via multirequest on read-only URL is not allowed
508 Attempting to run a read-write command via multirequest on read-only URL is not allowed
533
509
534 $ send << EOF
510 $ sendhttpraw << EOF
535 > httprequest POST api/$HTTPV2/ro/multirequest
511 > httprequest POST api/$HTTPV2/ro/multirequest
536 > accept: $MEDIATYPE
512 > accept: $MEDIATYPE
537 > content-type: $MEDIATYPE
513 > content-type: $MEDIATYPE
General Comments 0
You need to be logged in to leave comments. Login now