##// 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,560 +1,536 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
25 > [experimental]
6 > [experimental]
26 > web.apiserver = true
7 > web.apiserver = true
27 > EOF
8 > EOF
28 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
9 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid
29 $ cat hg.pid > $DAEMON_PIDS
10 $ cat hg.pid > $DAEMON_PIDS
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
37 using raw connection to peer
18 using raw connection to peer
38 s> GET /api/exp-http-v2-0001 HTTP/1.1\r\n
19 s> GET /api/exp-http-v2-0001 HTTP/1.1\r\n
39 s> Accept-Encoding: identity\r\n
20 s> Accept-Encoding: identity\r\n
40 s> user-agent: test\r\n
21 s> user-agent: test\r\n
41 s> host: $LOCALIP:$HGPORT\r\n (glob)
22 s> host: $LOCALIP:$HGPORT\r\n (glob)
42 s> \r\n
23 s> \r\n
43 s> makefile('rb', None)
24 s> makefile('rb', None)
44 s> HTTP/1.1 404 Not Found\r\n
25 s> HTTP/1.1 404 Not Found\r\n
45 s> Server: testing stub value\r\n
26 s> Server: testing stub value\r\n
46 s> Date: $HTTP_DATE$\r\n
27 s> Date: $HTTP_DATE$\r\n
47 s> Content-Type: text/plain\r\n
28 s> Content-Type: text/plain\r\n
48 s> Content-Length: 33\r\n
29 s> Content-Length: 33\r\n
49 s> \r\n
30 s> \r\n
50 s> API exp-http-v2-0001 not enabled\n
31 s> API exp-http-v2-0001 not enabled\n
51
32
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
70 using raw connection to peer
46 using raw connection to peer
71 s> POST /api/exp-http-v2-0001/ro/badcommand HTTP/1.1\r\n
47 s> POST /api/exp-http-v2-0001/ro/badcommand HTTP/1.1\r\n
72 s> Accept-Encoding: identity\r\n
48 s> Accept-Encoding: identity\r\n
73 s> user-agent: test\r\n
49 s> user-agent: test\r\n
74 s> host: $LOCALIP:$HGPORT\r\n (glob)
50 s> host: $LOCALIP:$HGPORT\r\n (glob)
75 s> \r\n
51 s> \r\n
76 s> makefile('rb', None)
52 s> makefile('rb', None)
77 s> HTTP/1.1 404 Not Found\r\n
53 s> HTTP/1.1 404 Not Found\r\n
78 s> Server: testing stub value\r\n
54 s> Server: testing stub value\r\n
79 s> Date: $HTTP_DATE$\r\n
55 s> Date: $HTTP_DATE$\r\n
80 s> Content-Type: text/plain\r\n
56 s> Content-Type: text/plain\r\n
81 s> Content-Length: 42\r\n
57 s> Content-Length: 42\r\n
82 s> \r\n
58 s> \r\n
83 s> unknown wire protocol command: badcommand\n
59 s> unknown wire protocol command: badcommand\n
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
91 using raw connection to peer
67 using raw connection to peer
92 s> GET /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
68 s> GET /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
93 s> Accept-Encoding: identity\r\n
69 s> Accept-Encoding: identity\r\n
94 s> user-agent: test\r\n
70 s> user-agent: test\r\n
95 s> host: $LOCALIP:$HGPORT\r\n (glob)
71 s> host: $LOCALIP:$HGPORT\r\n (glob)
96 s> \r\n
72 s> \r\n
97 s> makefile('rb', None)
73 s> makefile('rb', None)
98 s> HTTP/1.1 405 Method Not Allowed\r\n
74 s> HTTP/1.1 405 Method Not Allowed\r\n
99 s> Server: testing stub value\r\n
75 s> Server: testing stub value\r\n
100 s> Date: $HTTP_DATE$\r\n
76 s> Date: $HTTP_DATE$\r\n
101 s> Allow: POST\r\n
77 s> Allow: POST\r\n
102 s> Content-Length: 30\r\n
78 s> Content-Length: 30\r\n
103 s> \r\n
79 s> \r\n
104 s> commands require POST requests
80 s> commands require POST requests
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
112 using raw connection to peer
88 using raw connection to peer
113 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
89 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
114 s> Accept-Encoding: identity\r\n
90 s> Accept-Encoding: identity\r\n
115 s> user-agent: test\r\n
91 s> user-agent: test\r\n
116 s> host: $LOCALIP:$HGPORT\r\n (glob)
92 s> host: $LOCALIP:$HGPORT\r\n (glob)
117 s> \r\n
93 s> \r\n
118 s> makefile('rb', None)
94 s> makefile('rb', None)
119 s> HTTP/1.1 406 Not Acceptable\r\n
95 s> HTTP/1.1 406 Not Acceptable\r\n
120 s> Server: testing stub value\r\n
96 s> Server: testing stub value\r\n
121 s> Date: $HTTP_DATE$\r\n
97 s> Date: $HTTP_DATE$\r\n
122 s> Content-Type: text/plain\r\n
98 s> Content-Type: text/plain\r\n
123 s> Content-Length: 85\r\n
99 s> Content-Length: 85\r\n
124 s> \r\n
100 s> \r\n
125 s> client MUST specify Accept header with value: application/mercurial-exp-framing-0003\n
101 s> client MUST specify Accept header with value: application/mercurial-exp-framing-0003\n
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
133 > EOF
109 > EOF
134 using raw connection to peer
110 using raw connection to peer
135 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
111 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
136 s> Accept-Encoding: identity\r\n
112 s> Accept-Encoding: identity\r\n
137 s> accept: invalid\r\n
113 s> accept: invalid\r\n
138 s> user-agent: test\r\n
114 s> user-agent: test\r\n
139 s> host: $LOCALIP:$HGPORT\r\n (glob)
115 s> host: $LOCALIP:$HGPORT\r\n (glob)
140 s> \r\n
116 s> \r\n
141 s> makefile('rb', None)
117 s> makefile('rb', None)
142 s> HTTP/1.1 406 Not Acceptable\r\n
118 s> HTTP/1.1 406 Not Acceptable\r\n
143 s> Server: testing stub value\r\n
119 s> Server: testing stub value\r\n
144 s> Date: $HTTP_DATE$\r\n
120 s> Date: $HTTP_DATE$\r\n
145 s> Content-Type: text/plain\r\n
121 s> Content-Type: text/plain\r\n
146 s> Content-Length: 85\r\n
122 s> Content-Length: 85\r\n
147 s> \r\n
123 s> \r\n
148 s> client MUST specify Accept header with value: application/mercurial-exp-framing-0003\n
124 s> client MUST specify Accept header with value: application/mercurial-exp-framing-0003\n
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
156 > content-type: badmedia
132 > content-type: badmedia
157 > EOF
133 > EOF
158 using raw connection to peer
134 using raw connection to peer
159 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
135 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
160 s> Accept-Encoding: identity\r\n
136 s> Accept-Encoding: identity\r\n
161 s> accept: application/mercurial-exp-framing-0003\r\n
137 s> accept: application/mercurial-exp-framing-0003\r\n
162 s> content-type: badmedia\r\n
138 s> content-type: badmedia\r\n
163 s> user-agent: test\r\n
139 s> user-agent: test\r\n
164 s> host: $LOCALIP:$HGPORT\r\n (glob)
140 s> host: $LOCALIP:$HGPORT\r\n (glob)
165 s> \r\n
141 s> \r\n
166 s> makefile('rb', None)
142 s> makefile('rb', None)
167 s> HTTP/1.1 415 Unsupported Media Type\r\n
143 s> HTTP/1.1 415 Unsupported Media Type\r\n
168 s> Server: testing stub value\r\n
144 s> Server: testing stub value\r\n
169 s> Date: $HTTP_DATE$\r\n
145 s> Date: $HTTP_DATE$\r\n
170 s> Content-Type: text/plain\r\n
146 s> Content-Type: text/plain\r\n
171 s> Content-Length: 88\r\n
147 s> Content-Length: 88\r\n
172 s> \r\n
148 s> \r\n
173 s> client MUST send Content-Type header with value: application/mercurial-exp-framing-0003\n
149 s> client MUST send Content-Type header with value: application/mercurial-exp-framing-0003\n
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
181 > user-agent: test
157 > user-agent: test
182 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
158 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
183 > EOF
159 > EOF
184 using raw connection to peer
160 using raw connection to peer
185 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
161 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
186 s> Accept-Encoding: identity\r\n
162 s> Accept-Encoding: identity\r\n
187 s> *\r\n (glob)
163 s> *\r\n (glob)
188 s> content-type: application/mercurial-exp-framing-0003\r\n
164 s> content-type: application/mercurial-exp-framing-0003\r\n
189 s> user-agent: test\r\n
165 s> user-agent: test\r\n
190 s> content-length: 29\r\n
166 s> content-length: 29\r\n
191 s> host: $LOCALIP:$HGPORT\r\n (glob)
167 s> host: $LOCALIP:$HGPORT\r\n (glob)
192 s> \r\n
168 s> \r\n
193 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
169 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
194 s> makefile('rb', None)
170 s> makefile('rb', None)
195 s> HTTP/1.1 200 OK\r\n
171 s> HTTP/1.1 200 OK\r\n
196 s> Server: testing stub value\r\n
172 s> Server: testing stub value\r\n
197 s> Date: $HTTP_DATE$\r\n
173 s> Date: $HTTP_DATE$\r\n
198 s> Content-Type: application/mercurial-exp-framing-0003\r\n
174 s> Content-Type: application/mercurial-exp-framing-0003\r\n
199 s> Transfer-Encoding: chunked\r\n
175 s> Transfer-Encoding: chunked\r\n
200 s> \r\n
176 s> \r\n
201 s> 25\r\n
177 s> 25\r\n
202 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
178 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
203 s> \r\n
179 s> \r\n
204 s> 0\r\n
180 s> 0\r\n
205 s> \r\n
181 s> \r\n
206
182
207 Request to read-write command fails because server is read-only by default
183 Request to read-write command fails because server is read-only by default
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
215 using raw connection to peer
191 using raw connection to peer
216 s> GET /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
192 s> GET /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
217 s> Accept-Encoding: identity\r\n
193 s> Accept-Encoding: identity\r\n
218 s> user-agent: test\r\n
194 s> user-agent: test\r\n
219 s> host: $LOCALIP:$HGPORT\r\n (glob)
195 s> host: $LOCALIP:$HGPORT\r\n (glob)
220 s> \r\n
196 s> \r\n
221 s> makefile('rb', None)
197 s> makefile('rb', None)
222 s> HTTP/1.1 405 Method Not Allowed\r\n
198 s> HTTP/1.1 405 Method Not Allowed\r\n
223 s> Server: testing stub value\r\n
199 s> Server: testing stub value\r\n
224 s> Date: $HTTP_DATE$\r\n
200 s> Date: $HTTP_DATE$\r\n
225 s> Allow: POST\r\n
201 s> Allow: POST\r\n
226 s> Content-Length: 30\r\n
202 s> Content-Length: 30\r\n
227 s> \r\n
203 s> \r\n
228 s> commands require POST requests
204 s> commands require POST requests
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
236 using raw connection to peer
212 using raw connection to peer
237 s> GET /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
213 s> GET /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
238 s> Accept-Encoding: identity\r\n
214 s> Accept-Encoding: identity\r\n
239 s> user-agent: test\r\n
215 s> user-agent: test\r\n
240 s> host: $LOCALIP:$HGPORT\r\n (glob)
216 s> host: $LOCALIP:$HGPORT\r\n (glob)
241 s> \r\n
217 s> \r\n
242 s> makefile('rb', None)
218 s> makefile('rb', None)
243 s> HTTP/1.1 405 Method Not Allowed\r\n
219 s> HTTP/1.1 405 Method Not Allowed\r\n
244 s> Server: testing stub value\r\n
220 s> Server: testing stub value\r\n
245 s> Date: $HTTP_DATE$\r\n
221 s> Date: $HTTP_DATE$\r\n
246 s> Allow: POST\r\n
222 s> Allow: POST\r\n
247 s> Content-Length: 30\r\n
223 s> Content-Length: 30\r\n
248 s> \r\n
224 s> \r\n
249 s> commands require POST requests
225 s> commands require POST requests
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
257 using raw connection to peer
233 using raw connection to peer
258 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
234 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
259 s> Accept-Encoding: identity\r\n
235 s> Accept-Encoding: identity\r\n
260 s> user-agent: test\r\n
236 s> user-agent: test\r\n
261 s> host: $LOCALIP:$HGPORT\r\n (glob)
237 s> host: $LOCALIP:$HGPORT\r\n (glob)
262 s> \r\n
238 s> \r\n
263 s> makefile('rb', None)
239 s> makefile('rb', None)
264 s> HTTP/1.1 403 ssl required\r\n
240 s> HTTP/1.1 403 ssl required\r\n
265 s> Server: testing stub value\r\n
241 s> Server: testing stub value\r\n
266 s> Date: $HTTP_DATE$\r\n
242 s> Date: $HTTP_DATE$\r\n
267 s> Content-Length: 17\r\n
243 s> Content-Length: 17\r\n
268 s> \r\n
244 s> \r\n
269 s> permission denied
245 s> permission denied
270
246
271 Restart server to allow non-ssl read-write operations
247 Restart server to allow non-ssl read-write operations
272
248
273 $ killdaemons.py
249 $ killdaemons.py
274 $ cat > server/.hg/hgrc << EOF
250 $ cat > server/.hg/hgrc << EOF
275 > [experimental]
251 > [experimental]
276 > web.apiserver = true
252 > web.apiserver = true
277 > web.api.http-v2 = true
253 > web.api.http-v2 = true
278 > [web]
254 > [web]
279 > push_ssl = false
255 > push_ssl = false
280 > allow-push = *
256 > allow-push = *
281 > EOF
257 > EOF
282
258
283 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
259 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
284 $ cat hg.pid > $DAEMON_PIDS
260 $ cat hg.pid > $DAEMON_PIDS
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
292 > content-type: $MEDIATYPE
268 > content-type: $MEDIATYPE
293 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
269 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
294 > EOF
270 > EOF
295 using raw connection to peer
271 using raw connection to peer
296 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
272 s> POST /api/exp-http-v2-0001/rw/customreadonly HTTP/1.1\r\n
297 s> Accept-Encoding: identity\r\n
273 s> Accept-Encoding: identity\r\n
298 s> accept: application/mercurial-exp-framing-0003\r\n
274 s> accept: application/mercurial-exp-framing-0003\r\n
299 s> content-type: application/mercurial-exp-framing-0003\r\n
275 s> content-type: application/mercurial-exp-framing-0003\r\n
300 s> user-agent: test\r\n
276 s> user-agent: test\r\n
301 s> content-length: 29\r\n
277 s> content-length: 29\r\n
302 s> host: $LOCALIP:$HGPORT\r\n (glob)
278 s> host: $LOCALIP:$HGPORT\r\n (glob)
303 s> \r\n
279 s> \r\n
304 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
280 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
305 s> makefile('rb', None)
281 s> makefile('rb', None)
306 s> HTTP/1.1 200 OK\r\n
282 s> HTTP/1.1 200 OK\r\n
307 s> Server: testing stub value\r\n
283 s> Server: testing stub value\r\n
308 s> Date: $HTTP_DATE$\r\n
284 s> Date: $HTTP_DATE$\r\n
309 s> Content-Type: application/mercurial-exp-framing-0003\r\n
285 s> Content-Type: application/mercurial-exp-framing-0003\r\n
310 s> Transfer-Encoding: chunked\r\n
286 s> Transfer-Encoding: chunked\r\n
311 s> \r\n
287 s> \r\n
312 s> 25\r\n
288 s> 25\r\n
313 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
289 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
314 s> \r\n
290 s> \r\n
315 s> 0\r\n
291 s> 0\r\n
316 s> \r\n
292 s> \r\n
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
324 > EOF
300 > EOF
325 using raw connection to peer
301 using raw connection to peer
326 s> POST /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
302 s> POST /api/exp-http-v2-0001/rw/badcommand HTTP/1.1\r\n
327 s> Accept-Encoding: identity\r\n
303 s> Accept-Encoding: identity\r\n
328 s> accept: application/mercurial-exp-framing-0003\r\n
304 s> accept: application/mercurial-exp-framing-0003\r\n
329 s> user-agent: test\r\n
305 s> user-agent: test\r\n
330 s> host: $LOCALIP:$HGPORT\r\n (glob)
306 s> host: $LOCALIP:$HGPORT\r\n (glob)
331 s> \r\n
307 s> \r\n
332 s> makefile('rb', None)
308 s> makefile('rb', None)
333 s> HTTP/1.1 404 Not Found\r\n
309 s> HTTP/1.1 404 Not Found\r\n
334 s> Server: testing stub value\r\n
310 s> Server: testing stub value\r\n
335 s> Date: $HTTP_DATE$\r\n
311 s> Date: $HTTP_DATE$\r\n
336 s> Content-Type: text/plain\r\n
312 s> Content-Type: text/plain\r\n
337 s> Content-Length: 42\r\n
313 s> Content-Length: 42\r\n
338 s> \r\n
314 s> \r\n
339 s> unknown wire protocol command: badcommand\n
315 s> unknown wire protocol command: badcommand\n
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
347 using raw connection to peer
323 using raw connection to peer
348 s> POST /api/exp-http-v2-0001/ro/debugreflect HTTP/1.1\r\n
324 s> POST /api/exp-http-v2-0001/ro/debugreflect HTTP/1.1\r\n
349 s> Accept-Encoding: identity\r\n
325 s> Accept-Encoding: identity\r\n
350 s> user-agent: test\r\n
326 s> user-agent: test\r\n
351 s> host: $LOCALIP:$HGPORT\r\n (glob)
327 s> host: $LOCALIP:$HGPORT\r\n (glob)
352 s> \r\n
328 s> \r\n
353 s> makefile('rb', None)
329 s> makefile('rb', None)
354 s> HTTP/1.1 404 Not Found\r\n
330 s> HTTP/1.1 404 Not Found\r\n
355 s> Server: testing stub value\r\n
331 s> Server: testing stub value\r\n
356 s> Date: $HTTP_DATE$\r\n
332 s> Date: $HTTP_DATE$\r\n
357 s> Content-Type: text/plain\r\n
333 s> Content-Type: text/plain\r\n
358 s> Content-Length: 34\r\n
334 s> Content-Length: 34\r\n
359 s> \r\n
335 s> \r\n
360 s> debugreflect service not available
336 s> debugreflect service not available
361
337
362 Restart server to get debugreflect endpoint
338 Restart server to get debugreflect endpoint
363
339
364 $ killdaemons.py
340 $ killdaemons.py
365 $ cat > server/.hg/hgrc << EOF
341 $ cat > server/.hg/hgrc << EOF
366 > [experimental]
342 > [experimental]
367 > web.apiserver = true
343 > web.apiserver = true
368 > web.api.debugreflect = true
344 > web.api.debugreflect = true
369 > web.api.http-v2 = true
345 > web.api.http-v2 = true
370 > [web]
346 > [web]
371 > push_ssl = false
347 > push_ssl = false
372 > allow-push = *
348 > allow-push = *
373 > EOF
349 > EOF
374
350
375 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
351 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
376 $ cat hg.pid > $DAEMON_PIDS
352 $ cat hg.pid > $DAEMON_PIDS
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
384 > user-agent: test
360 > user-agent: test
385 > frame 1 1 stream-begin command-request new cbor:{b'name': b'command1', b'args': {b'foo': b'val1', b'bar1': b'val'}}
361 > frame 1 1 stream-begin command-request new cbor:{b'name': b'command1', b'args': {b'foo': b'val1', b'bar1': b'val'}}
386 > EOF
362 > EOF
387 using raw connection to peer
363 using raw connection to peer
388 s> POST /api/exp-http-v2-0001/ro/debugreflect HTTP/1.1\r\n
364 s> POST /api/exp-http-v2-0001/ro/debugreflect HTTP/1.1\r\n
389 s> Accept-Encoding: identity\r\n
365 s> Accept-Encoding: identity\r\n
390 s> accept: application/mercurial-exp-framing-0003\r\n
366 s> accept: application/mercurial-exp-framing-0003\r\n
391 s> content-type: application/mercurial-exp-framing-0003\r\n
367 s> content-type: application/mercurial-exp-framing-0003\r\n
392 s> user-agent: test\r\n
368 s> user-agent: test\r\n
393 s> content-length: 47\r\n
369 s> content-length: 47\r\n
394 s> host: $LOCALIP:$HGPORT\r\n (glob)
370 s> host: $LOCALIP:$HGPORT\r\n (glob)
395 s> \r\n
371 s> \r\n
396 s> \'\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1
372 s> \'\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1
397 s> makefile('rb', None)
373 s> makefile('rb', None)
398 s> HTTP/1.1 200 OK\r\n
374 s> HTTP/1.1 200 OK\r\n
399 s> Server: testing stub value\r\n
375 s> Server: testing stub value\r\n
400 s> Date: $HTTP_DATE$\r\n
376 s> Date: $HTTP_DATE$\r\n
401 s> Content-Type: text/plain\r\n
377 s> Content-Type: text/plain\r\n
402 s> Content-Length: 205\r\n
378 s> Content-Length: 205\r\n
403 s> \r\n
379 s> \r\n
404 s> received: 1 1 1 \xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1\n
380 s> received: 1 1 1 \xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1\n
405 s> ["runcommand", {"args": {"bar1": "val", "foo": "val1"}, "command": "command1", "data": null, "requestid": 1}]\n
381 s> ["runcommand", {"args": {"bar1": "val", "foo": "val1"}, "command": "command1", "data": null, "requestid": 1}]\n
406 s> received: <no frame>\n
382 s> received: <no frame>\n
407 s> {"action": "noop"}
383 s> {"action": "noop"}
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
415 > user-agent: test
391 > user-agent: test
416 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
392 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
417 > EOF
393 > EOF
418 using raw connection to peer
394 using raw connection to peer
419 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
395 s> POST /api/exp-http-v2-0001/ro/customreadonly HTTP/1.1\r\n
420 s> Accept-Encoding: identity\r\n
396 s> Accept-Encoding: identity\r\n
421 s> accept: application/mercurial-exp-framing-0003\r\n
397 s> accept: application/mercurial-exp-framing-0003\r\n
422 s> content-type: application/mercurial-exp-framing-0003\r\n
398 s> content-type: application/mercurial-exp-framing-0003\r\n
423 s> user-agent: test\r\n
399 s> user-agent: test\r\n
424 s> content-length: 29\r\n
400 s> content-length: 29\r\n
425 s> host: $LOCALIP:$HGPORT\r\n (glob)
401 s> host: $LOCALIP:$HGPORT\r\n (glob)
426 s> \r\n
402 s> \r\n
427 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
403 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly
428 s> makefile('rb', None)
404 s> makefile('rb', None)
429 s> HTTP/1.1 200 OK\r\n
405 s> HTTP/1.1 200 OK\r\n
430 s> Server: testing stub value\r\n
406 s> Server: testing stub value\r\n
431 s> Date: $HTTP_DATE$\r\n
407 s> Date: $HTTP_DATE$\r\n
432 s> Content-Type: application/mercurial-exp-framing-0003\r\n
408 s> Content-Type: application/mercurial-exp-framing-0003\r\n
433 s> Transfer-Encoding: chunked\r\n
409 s> Transfer-Encoding: chunked\r\n
434 s> \r\n
410 s> \r\n
435 s> 25\r\n
411 s> 25\r\n
436 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
412 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
437 s> \r\n
413 s> \r\n
438 s> 0\r\n
414 s> 0\r\n
439 s> \r\n
415 s> \r\n
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
447 > user-agent: test
423 > user-agent: test
448 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
424 > frame 1 1 stream-begin command-request new cbor:{b'name': b'customreadonly'}
449 > frame 3 1 0 command-request new cbor:{b'name': b'customreadonly'}
425 > frame 3 1 0 command-request new cbor:{b'name': b'customreadonly'}
450 > EOF
426 > EOF
451 using raw connection to peer
427 using raw connection to peer
452 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
428 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
453 s> Accept-Encoding: identity\r\n
429 s> Accept-Encoding: identity\r\n
454 s> *\r\n (glob)
430 s> *\r\n (glob)
455 s> *\r\n (glob)
431 s> *\r\n (glob)
456 s> user-agent: test\r\n
432 s> user-agent: test\r\n
457 s> content-length: 58\r\n
433 s> content-length: 58\r\n
458 s> host: $LOCALIP:$HGPORT\r\n (glob)
434 s> host: $LOCALIP:$HGPORT\r\n (glob)
459 s> \r\n
435 s> \r\n
460 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly\x15\x00\x00\x03\x00\x01\x00\x11\xa1DnameNcustomreadonly
436 s> \x15\x00\x00\x01\x00\x01\x01\x11\xa1DnameNcustomreadonly\x15\x00\x00\x03\x00\x01\x00\x11\xa1DnameNcustomreadonly
461 s> makefile('rb', None)
437 s> makefile('rb', None)
462 s> HTTP/1.1 200 OK\r\n
438 s> HTTP/1.1 200 OK\r\n
463 s> Server: testing stub value\r\n
439 s> Server: testing stub value\r\n
464 s> Date: $HTTP_DATE$\r\n
440 s> Date: $HTTP_DATE$\r\n
465 s> Content-Type: application/mercurial-exp-framing-0003\r\n
441 s> Content-Type: application/mercurial-exp-framing-0003\r\n
466 s> Transfer-Encoding: chunked\r\n
442 s> Transfer-Encoding: chunked\r\n
467 s> \r\n
443 s> \r\n
468 s> 25\r\n
444 s> 25\r\n
469 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
445 s> \x1d\x00\x00\x01\x00\x02\x01Bcustomreadonly bytes response
470 s> \r\n
446 s> \r\n
471 s> 25\r\n
447 s> 25\r\n
472 s> \x1d\x00\x00\x03\x00\x02\x00Bcustomreadonly bytes response
448 s> \x1d\x00\x00\x03\x00\x02\x00Bcustomreadonly bytes response
473 s> \r\n
449 s> \r\n
474 s> 0\r\n
450 s> 0\r\n
475 s> \r\n
451 s> \r\n
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
483 > user-agent: test
459 > user-agent: test
484 > frame 1 1 stream-begin command-request new|more \xa2Dargs\xa1Inamespace
460 > frame 1 1 stream-begin command-request new|more \xa2Dargs\xa1Inamespace
485 > frame 3 1 0 command-request new|more \xa2Dargs\xa1Inamespace
461 > frame 3 1 0 command-request new|more \xa2Dargs\xa1Inamespace
486 > frame 3 1 0 command-request continuation JnamespacesDnameHlistkeys
462 > frame 3 1 0 command-request continuation JnamespacesDnameHlistkeys
487 > frame 1 1 0 command-request continuation IbookmarksDnameHlistkeys
463 > frame 1 1 0 command-request continuation IbookmarksDnameHlistkeys
488 > EOF
464 > EOF
489 using raw connection to peer
465 using raw connection to peer
490 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
466 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
491 s> Accept-Encoding: identity\r\n
467 s> Accept-Encoding: identity\r\n
492 s> accept: application/mercurial-exp-framing-0003\r\n
468 s> accept: application/mercurial-exp-framing-0003\r\n
493 s> content-type: application/mercurial-exp-framing-0003\r\n
469 s> content-type: application/mercurial-exp-framing-0003\r\n
494 s> user-agent: test\r\n
470 s> user-agent: test\r\n
495 s> content-length: 115\r\n
471 s> content-length: 115\r\n
496 s> host: $LOCALIP:$HGPORT\r\n (glob)
472 s> host: $LOCALIP:$HGPORT\r\n (glob)
497 s> \r\n
473 s> \r\n
498 s> \x11\x00\x00\x01\x00\x01\x01\x15\xa2Dargs\xa1Inamespace\x11\x00\x00\x03\x00\x01\x00\x15\xa2Dargs\xa1Inamespace\x19\x00\x00\x03\x00\x01\x00\x12JnamespacesDnameHlistkeys\x18\x00\x00\x01\x00\x01\x00\x12IbookmarksDnameHlistkeys
474 s> \x11\x00\x00\x01\x00\x01\x01\x15\xa2Dargs\xa1Inamespace\x11\x00\x00\x03\x00\x01\x00\x15\xa2Dargs\xa1Inamespace\x19\x00\x00\x03\x00\x01\x00\x12JnamespacesDnameHlistkeys\x18\x00\x00\x01\x00\x01\x00\x12IbookmarksDnameHlistkeys
499 s> makefile('rb', None)
475 s> makefile('rb', None)
500 s> HTTP/1.1 200 OK\r\n
476 s> HTTP/1.1 200 OK\r\n
501 s> Server: testing stub value\r\n
477 s> Server: testing stub value\r\n
502 s> Date: $HTTP_DATE$\r\n
478 s> Date: $HTTP_DATE$\r\n
503 s> Content-Type: application/mercurial-exp-framing-0003\r\n
479 s> Content-Type: application/mercurial-exp-framing-0003\r\n
504 s> Transfer-Encoding: chunked\r\n
480 s> Transfer-Encoding: chunked\r\n
505 s> \r\n
481 s> \r\n
506 s> 26\r\n
482 s> 26\r\n
507 s> \x1e\x00\x00\x03\x00\x02\x01Bbookmarks\t\n
483 s> \x1e\x00\x00\x03\x00\x02\x01Bbookmarks\t\n
508 s> namespaces\t\n
484 s> namespaces\t\n
509 s> phases\t
485 s> phases\t
510 s> \r\n
486 s> \r\n
511 s> 8\r\n
487 s> 8\r\n
512 s> \x00\x00\x00\x01\x00\x02\x00B
488 s> \x00\x00\x00\x01\x00\x02\x00B
513 s> \r\n
489 s> \r\n
514 s> 0\r\n
490 s> 0\r\n
515 s> \r\n
491 s> \r\n
516
492
517 Restart server to disable read-write access
493 Restart server to disable read-write access
518
494
519 $ killdaemons.py
495 $ killdaemons.py
520 $ cat > server/.hg/hgrc << EOF
496 $ cat > server/.hg/hgrc << EOF
521 > [experimental]
497 > [experimental]
522 > web.apiserver = true
498 > web.apiserver = true
523 > web.api.debugreflect = true
499 > web.api.debugreflect = true
524 > web.api.http-v2 = true
500 > web.api.http-v2 = true
525 > [web]
501 > [web]
526 > push_ssl = false
502 > push_ssl = false
527 > EOF
503 > EOF
528
504
529 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
505 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
530 $ cat hg.pid > $DAEMON_PIDS
506 $ cat hg.pid > $DAEMON_PIDS
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
538 > user-agent: test
514 > user-agent: test
539 > frame 1 1 stream-begin command-request new cbor:{b'name': b'unbundle'}
515 > frame 1 1 stream-begin command-request new cbor:{b'name': b'unbundle'}
540 > EOF
516 > EOF
541 using raw connection to peer
517 using raw connection to peer
542 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
518 s> POST /api/exp-http-v2-0001/ro/multirequest HTTP/1.1\r\n
543 s> Accept-Encoding: identity\r\n
519 s> Accept-Encoding: identity\r\n
544 s> accept: application/mercurial-exp-framing-0003\r\n
520 s> accept: application/mercurial-exp-framing-0003\r\n
545 s> content-type: application/mercurial-exp-framing-0003\r\n
521 s> content-type: application/mercurial-exp-framing-0003\r\n
546 s> user-agent: test\r\n
522 s> user-agent: test\r\n
547 s> content-length: 23\r\n
523 s> content-length: 23\r\n
548 s> host: $LOCALIP:$HGPORT\r\n (glob)
524 s> host: $LOCALIP:$HGPORT\r\n (glob)
549 s> \r\n
525 s> \r\n
550 s> \x0f\x00\x00\x01\x00\x01\x01\x11\xa1DnameHunbundle
526 s> \x0f\x00\x00\x01\x00\x01\x01\x11\xa1DnameHunbundle
551 s> makefile('rb', None)
527 s> makefile('rb', None)
552 s> HTTP/1.1 403 Forbidden\r\n
528 s> HTTP/1.1 403 Forbidden\r\n
553 s> Server: testing stub value\r\n
529 s> Server: testing stub value\r\n
554 s> Date: $HTTP_DATE$\r\n
530 s> Date: $HTTP_DATE$\r\n
555 s> Content-Type: text/plain\r\n
531 s> Content-Type: text/plain\r\n
556 s> Content-Length: 53\r\n
532 s> Content-Length: 53\r\n
557 s> \r\n
533 s> \r\n
558 s> insufficient permissions to execute command: unbundle
534 s> insufficient permissions to execute command: unbundle
559
535
560 $ cat error.log
536 $ cat error.log
General Comments 0
You need to be logged in to leave comments. Login now