##// END OF EJS Templates
tests: extract HTTP permissions tests to own test file...
Gregory Szorc -
r36769:2c647da8 stable
parent child Browse files
Show More
@@ -0,0 +1,52 b''
1 #require killdaemons
2
3 $ hg init test
4 $ cd test
5 $ echo a > a
6 $ hg ci -Ama
7 adding a
8 $ cd ..
9 $ hg clone test test2
10 updating to branch default
11 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
12 $ cd test2
13 $ echo a >> a
14 $ hg ci -mb
15 $ cd ../test
16
17 expect authorization error: all users denied
18
19 $ cat > .hg/hgrc <<EOF
20 > [web]
21 > push_ssl = false
22 > deny_push = *
23 > EOF
24
25 $ hg serve -p $HGPORT -d --pid-file hg.pid
26 $ cat hg.pid > $DAEMON_PIDS
27
28 $ hg --cwd ../test2 push http://localhost:$HGPORT/
29 pushing to http://localhost:$HGPORT/
30 searching for changes
31 abort: authorization failed
32 [255]
33
34 $ killdaemons.py
35
36 expect authorization error: some users denied, users must be authenticated
37
38 $ cat > .hg/hgrc <<EOF
39 > [web]
40 > push_ssl = false
41 > deny_push = unperson
42 > EOF
43
44 $ hg serve -p $HGPORT -d --pid-file hg.pid
45 $ cat hg.pid > $DAEMON_PIDS
46 $ hg --cwd ../test2 push http://localhost:$HGPORT/
47 pushing to http://localhost:$HGPORT/
48 searching for changes
49 abort: authorization failed
50 [255]
51
52 $ killdaemons.py
@@ -1,352 +1,330 b''
1 1 #require killdaemons
2 2
3 3 #testcases bundle1 bundle2
4 4
5 5 #if bundle1
6 6 $ cat << EOF >> $HGRCPATH
7 7 > [devel]
8 8 > # This test is dedicated to interaction through old bundle
9 9 > legacy.exchange = bundle1
10 10 > EOF
11 11 #endif
12 12
13 13 $ hg init test
14 14 $ cd test
15 15 $ echo a > a
16 16 $ hg ci -Ama
17 17 adding a
18 18 $ cd ..
19 19 $ hg clone test test2
20 20 updating to branch default
21 21 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
22 22 $ cd test2
23 23 $ echo a >> a
24 24 $ hg ci -mb
25 25 $ req() {
26 26 > hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
27 27 > cat hg.pid >> $DAEMON_PIDS
28 28 > hg --cwd ../test2 push http://localhost:$HGPORT/
29 29 > exitstatus=$?
30 30 > killdaemons.py
31 31 > echo % serve errors
32 32 > cat errors.log
33 33 > return $exitstatus
34 34 > }
35 35 $ cd ../test
36 36
37 37 expect ssl error
38 38
39 39 $ req
40 40 pushing to http://localhost:$HGPORT/
41 41 searching for changes
42 42 abort: HTTP Error 403: ssl required
43 43 % serve errors
44 44 [255]
45 45
46 46 expect authorization error
47 47
48 48 $ echo '[web]' > .hg/hgrc
49 49 $ echo 'push_ssl = false' >> .hg/hgrc
50 50 $ req
51 51 pushing to http://localhost:$HGPORT/
52 52 searching for changes
53 53 abort: authorization failed
54 54 % serve errors
55 55 [255]
56 56
57 57 expect authorization error: must have authorized user
58 58
59 59 $ echo 'allow_push = unperson' >> .hg/hgrc
60 60 $ req
61 61 pushing to http://localhost:$HGPORT/
62 62 searching for changes
63 63 abort: authorization failed
64 64 % serve errors
65 65 [255]
66 66
67 67 expect success
68 68
69 69 $ cat > $TESTTMP/hook.sh <<'EOF'
70 70 > echo "phase-move: $HG_NODE: $HG_OLDPHASE -> $HG_PHASE"
71 71 > EOF
72 72
73 73 $ cat >> .hg/hgrc <<EOF
74 74 > allow_push = *
75 75 > [hooks]
76 76 > changegroup = sh -c "printenv.py changegroup 0"
77 77 > pushkey = sh -c "printenv.py pushkey 0"
78 78 > txnclose-phase.test = sh $TESTTMP/hook.sh
79 79 > EOF
80 80 $ req
81 81 pushing to http://localhost:$HGPORT/
82 82 searching for changes
83 83 remote: adding changesets
84 84 remote: adding manifests
85 85 remote: adding file changes
86 86 remote: added 1 changesets with 1 changes to 1 files
87 87 remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b: draft -> public
88 88 remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872: -> public
89 89 remote: changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle1 !)
90 90 remote: changegroup hook: HG_BUNDLE2=1 HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle2 !)
91 91 % serve errors
92 92 $ hg rollback
93 93 repository tip rolled back to revision 0 (undo serve)
94 94
95 95 expect success, server lacks the httpheader capability
96 96
97 97 $ CAP=httpheader
98 98 $ . "$TESTDIR/notcapable"
99 99 $ req
100 100 pushing to http://localhost:$HGPORT/
101 101 searching for changes
102 102 remote: adding changesets
103 103 remote: adding manifests
104 104 remote: adding file changes
105 105 remote: added 1 changesets with 1 changes to 1 files
106 106 remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b: draft -> public
107 107 remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872: -> public
108 108 remote: changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle1 !)
109 109 remote: changegroup hook: HG_BUNDLE2=1 HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle2 !)
110 110 % serve errors
111 111 $ hg rollback
112 112 repository tip rolled back to revision 0 (undo serve)
113 113
114 114 expect success, server lacks the unbundlehash capability
115 115
116 116 $ CAP=unbundlehash
117 117 $ . "$TESTDIR/notcapable"
118 118 $ req
119 119 pushing to http://localhost:$HGPORT/
120 120 searching for changes
121 121 remote: adding changesets
122 122 remote: adding manifests
123 123 remote: adding file changes
124 124 remote: added 1 changesets with 1 changes to 1 files
125 125 remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b: draft -> public
126 126 remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872: -> public
127 127 remote: changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle1 !)
128 128 remote: changegroup hook: HG_BUNDLE2=1 HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob) (bundle2 !)
129 129 % serve errors
130 130 $ hg rollback
131 131 repository tip rolled back to revision 0 (undo serve)
132 132
133 133 expect success, pre-d1b16a746db6 server supports the unbundle capability, but
134 134 has no parameter
135 135
136 136 $ cat <<EOF > notcapable-unbundleparam.py
137 137 > from mercurial import extensions, httppeer
138 138 > def capable(orig, self, name):
139 139 > if name == 'unbundle':
140 140 > return True
141 141 > return orig(self, name)
142 142 > def uisetup(ui):
143 143 > extensions.wrapfunction(httppeer.httppeer, 'capable', capable)
144 144 > EOF
145 145 $ cp $HGRCPATH $HGRCPATH.orig
146 146 $ cat <<EOF >> $HGRCPATH
147 147 > [extensions]
148 148 > notcapable-unbundleparam = `pwd`/notcapable-unbundleparam.py
149 149 > EOF
150 150 $ req
151 151 pushing to http://localhost:$HGPORT/
152 152 searching for changes
153 153 remote: adding changesets
154 154 remote: adding manifests
155 155 remote: adding file changes
156 156 remote: added 1 changesets with 1 changes to 1 files
157 157 remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b: draft -> public
158 158 remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872: -> public
159 159 remote: changegroup hook: * (glob)
160 160 % serve errors
161 161 $ hg rollback
162 162 repository tip rolled back to revision 0 (undo serve)
163 163 $ mv $HGRCPATH.orig $HGRCPATH
164 164
165 165 Test pushing to a publishing repository with a failing prepushkey hook
166 166
167 167 $ cat > .hg/hgrc <<EOF
168 168 > [web]
169 169 > push_ssl = false
170 170 > allow_push = *
171 171 > [hooks]
172 172 > prepushkey = sh -c "printenv.py prepushkey 1"
173 173 > [devel]
174 174 > legacy.exchange=phases
175 175 > EOF
176 176
177 177 #if bundle1
178 178 Bundle1 works because a) phases are updated as part of changegroup application
179 179 and b) client checks phases after the "unbundle" command. Since it sees no
180 180 phase changes are necessary, it doesn't send the "pushkey" command and the
181 181 prepushkey hook never has to fire.
182 182
183 183 $ req
184 184 pushing to http://localhost:$HGPORT/
185 185 searching for changes
186 186 remote: adding changesets
187 187 remote: adding manifests
188 188 remote: adding file changes
189 189 remote: added 1 changesets with 1 changes to 1 files
190 190 % serve errors
191 191
192 192 #endif
193 193
194 194 #if bundle2
195 195 Bundle2 sends a "pushkey" bundle2 part. This runs as part of the transaction
196 196 and fails the entire push.
197 197 $ req
198 198 pushing to http://localhost:$HGPORT/
199 199 searching for changes
200 200 remote: adding changesets
201 201 remote: adding manifests
202 202 remote: adding file changes
203 203 remote: added 1 changesets with 1 changes to 1 files
204 204 remote: prepushkey hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_OLD=1 HG_PENDING=$TESTTMP/test HG_PHASES_MOVED=1 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
205 205 remote: pushkey-abort: prepushkey hook exited with status 1
206 206 remote: transaction abort!
207 207 remote: rollback completed
208 208 abort: updating ba677d0156c1 to public failed
209 209 % serve errors
210 210 [255]
211 211
212 212 #endif
213 213
214 214 Now remove the failing prepushkey hook.
215 215
216 216 $ cat >> .hg/hgrc <<EOF
217 217 > [hooks]
218 218 > prepushkey = sh -c "printenv.py prepushkey 0"
219 219 > EOF
220 220
221 221 We don't need to test bundle1 because it succeeded above.
222 222
223 223 #if bundle2
224 224 $ req
225 225 pushing to http://localhost:$HGPORT/
226 226 searching for changes
227 227 remote: adding changesets
228 228 remote: adding manifests
229 229 remote: adding file changes
230 230 remote: added 1 changesets with 1 changes to 1 files
231 231 remote: prepushkey hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_OLD=1 HG_PENDING=$TESTTMP/test HG_PHASES_MOVED=1 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
232 232 % serve errors
233 233 #endif
234 234
235 235 $ hg --config extensions.strip= strip -r 1:
236 236 saved backup bundle to $TESTTMP/test/.hg/strip-backup/ba677d0156c1-eea704d7-backup.hg
237 237
238 238 Now do a variant of the above, except on a non-publishing repository
239 239
240 240 $ cat >> .hg/hgrc <<EOF
241 241 > [phases]
242 242 > publish = false
243 243 > [hooks]
244 244 > prepushkey = sh -c "printenv.py prepushkey 1"
245 245 > EOF
246 246
247 247 #if bundle1
248 248 $ req
249 249 pushing to http://localhost:$HGPORT/
250 250 searching for changes
251 251 remote: adding changesets
252 252 remote: adding manifests
253 253 remote: adding file changes
254 254 remote: added 1 changesets with 1 changes to 1 files
255 255 remote: prepushkey hook: HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
256 256 remote: pushkey-abort: prepushkey hook exited with status 1
257 257 updating ba677d0156c1 to public failed!
258 258 % serve errors
259 259 #endif
260 260
261 261 #if bundle2
262 262 $ req
263 263 pushing to http://localhost:$HGPORT/
264 264 searching for changes
265 265 remote: adding changesets
266 266 remote: adding manifests
267 267 remote: adding file changes
268 268 remote: added 1 changesets with 1 changes to 1 files
269 269 remote: prepushkey hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_OLD=1 HG_PENDING=$TESTTMP/test HG_PHASES_MOVED=1 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
270 270 remote: pushkey-abort: prepushkey hook exited with status 1
271 271 remote: transaction abort!
272 272 remote: rollback completed
273 273 abort: updating ba677d0156c1 to public failed
274 274 % serve errors
275 275 [255]
276 276 #endif
277 277
278 278 Make phases updates work
279 279
280 280 $ cat >> .hg/hgrc <<EOF
281 281 > [hooks]
282 282 > prepushkey = sh -c "printenv.py prepushkey 0"
283 283 > EOF
284 284
285 285 #if bundle1
286 286 $ req
287 287 pushing to http://localhost:$HGPORT/
288 288 searching for changes
289 289 no changes found
290 290 remote: prepushkey hook: HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
291 291 % serve errors
292 292 [1]
293 293 #endif
294 294
295 295 #if bundle2
296 296 $ req
297 297 pushing to http://localhost:$HGPORT/
298 298 searching for changes
299 299 remote: adding changesets
300 300 remote: adding manifests
301 301 remote: adding file changes
302 302 remote: added 1 changesets with 1 changes to 1 files
303 303 remote: prepushkey hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_OLD=1 HG_PENDING=$TESTTMP/test HG_PHASES_MOVED=1 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
304 304 % serve errors
305 305 #endif
306 306
307 307 $ hg --config extensions.strip= strip -r 1:
308 308 saved backup bundle to $TESTTMP/test/.hg/strip-backup/ba677d0156c1-eea704d7-backup.hg
309 309
310 expect authorization error: all users denied
311
312 $ echo '[web]' > .hg/hgrc
313 $ echo 'push_ssl = false' >> .hg/hgrc
314 $ echo 'deny_push = *' >> .hg/hgrc
315 $ req
316 pushing to http://localhost:$HGPORT/
317 searching for changes
318 abort: authorization failed
319 % serve errors
320 [255]
321
322 expect authorization error: some users denied, users must be authenticated
323
324 $ echo 'deny_push = unperson' >> .hg/hgrc
325 $ req
326 pushing to http://localhost:$HGPORT/
327 searching for changes
328 abort: authorization failed
329 % serve errors
330 [255]
331
332 310 #if bundle2
333 311
334 312 $ cat > .hg/hgrc <<EOF
335 313 > [web]
336 314 > push_ssl = false
337 315 > allow_push = *
338 316 > [experimental]
339 317 > httppostargs=true
340 318 > EOF
341 319 $ req
342 320 pushing to http://localhost:$HGPORT/
343 321 searching for changes
344 322 remote: adding changesets
345 323 remote: adding manifests
346 324 remote: adding file changes
347 325 remote: added 1 changesets with 1 changes to 1 files
348 326 % serve errors
349 327
350 328 #endif
351 329
352 330 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now