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