Show More
@@ -0,0 +1,17 b'' | |||
|
1 | from __future__ import absolute_import | |
|
2 | ||
|
3 | import base64 | |
|
4 | ||
|
5 | from mercurial.hgweb import common | |
|
6 | ||
|
7 | def perform_authentication(hgweb, req, op): | |
|
8 | auth = req.headers.get(b'Authorization') | |
|
9 | if not auth: | |
|
10 | raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
|
11 | [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
|
12 | ||
|
13 | if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: | |
|
14 | raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
|
15 | ||
|
16 | def extsetup(ui): | |
|
17 | common.permhooks.insert(0, perform_authentication) |
@@ -175,22 +175,9 b' test http authentication' | |||
|
175 | 175 | + use the same server to test server side streaming preference |
|
176 | 176 | |
|
177 | 177 | $ cd test |
|
178 | $ cat << EOT > userpass.py | |
|
179 | > import base64 | |
|
180 | > from mercurial.hgweb import common | |
|
181 | > def perform_authentication(hgweb, req, op): | |
|
182 | > auth = req.headers.get(b'Authorization') | |
|
183 | > if not auth: | |
|
184 | > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
|
185 | > [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
|
186 | > if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', | |
|
187 | > b'pass']: | |
|
188 | > raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
|
189 | > def extsetup(ui): | |
|
190 | > common.permhooks.insert(0, perform_authentication) | |
|
191 | > EOT | |
|
192 | $ hg serve --config extensions.x=userpass.py -p $HGPORT2 -d --pid-file=pid \ | |
|
193 | > --config server.preferuncompressed=True \ | |
|
178 | ||
|
179 | $ hg serve --config extensions.x=$TESTDIR/httpserverauth.py -p $HGPORT2 -d \ | |
|
180 | > --pid-file=pid --config server.preferuncompressed=True \ | |
|
194 | 181 | > --config web.push_ssl=False --config web.allow_push=* -A ../access.log |
|
195 | 182 | $ cat pid >> $DAEMON_PIDS |
|
196 | 183 |
@@ -171,21 +171,9 b' test http authentication' | |||
|
171 | 171 | + use the same server to test server side streaming preference |
|
172 | 172 | |
|
173 | 173 | $ cd test |
|
174 | $ cat << EOT > userpass.py | |
|
175 | > import base64 | |
|
176 | > from mercurial.hgweb import common | |
|
177 | > def perform_authentication(hgweb, req, op): | |
|
178 | > auth = req.headers.get(b'Authorization') | |
|
179 | > if not auth: | |
|
180 | > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
|
181 | > [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
|
182 | > if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: | |
|
183 | > raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
|
184 | > def extsetup(ui): | |
|
185 | > common.permhooks.insert(0, perform_authentication) | |
|
186 | > EOT | |
|
187 | $ hg serve --config extensions.x=userpass.py -p $HGPORT2 -d --pid-file=pid \ | |
|
188 | > --config server.preferuncompressed=True \ | |
|
174 | ||
|
175 | $ hg serve --config extensions.x=$TESTDIR/httpserverauth.py -p $HGPORT2 -d \ | |
|
176 | > --pid-file=pid --config server.preferuncompressed=True \ | |
|
189 | 177 | > --config web.push_ssl=False --config web.allow_push=* -A ../access.log |
|
190 | 178 | $ cat pid >> $DAEMON_PIDS |
|
191 | 179 |
@@ -420,20 +420,8 b' a large file from the server rather than' | |||
|
420 | 420 | $ rm "${USERCACHE}"/* |
|
421 | 421 | |
|
422 | 422 | $ cd .. |
|
423 | $ cat << EOT > userpass.py | |
|
424 | > import base64 | |
|
425 | > from mercurial.hgweb import common | |
|
426 | > def perform_authentication(hgweb, req, op): | |
|
427 | > auth = req.headers.get(b'Authorization') | |
|
428 | > if not auth: | |
|
429 | > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
|
430 | > [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
|
431 | > if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: | |
|
432 | > raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
|
433 | > def extsetup(ui): | |
|
434 | > common.permhooks.insert(0, perform_authentication) | |
|
435 | > EOT | |
|
436 | $ hg serve --config extensions.x=userpass.py -R credentialmain \ | |
|
423 | ||
|
424 | $ hg serve --config extensions.x=$TESTDIR/httpserverauth.py -R credentialmain \ | |
|
437 | 425 | > -d -p $HGPORT --pid-file hg.pid -A access.log |
|
438 | 426 | $ cat hg.pid >> $DAEMON_PIDS |
|
439 | 427 | $ cat << EOF > get_pass.py |
@@ -393,22 +393,7 b' the GET/PUT request.' | |||
|
393 | 393 | > l.password=pass |
|
394 | 394 | > EOF |
|
395 | 395 | |
|
396 | $ cat << EOF > userpass.py | |
|
397 | > import base64 | |
|
398 | > from mercurial.hgweb import common | |
|
399 | > def perform_authentication(hgweb, req, op): | |
|
400 | > auth = req.headers.get(b'Authorization') | |
|
401 | > if not auth: | |
|
402 | > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
|
403 | > [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
|
404 | > if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', | |
|
405 | > b'pass']: | |
|
406 | > raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
|
407 | > def extsetup(ui): | |
|
408 | > common.permhooks.insert(0, perform_authentication) | |
|
409 | > EOF | |
|
410 | ||
|
411 | $ hg --config extensions.x=$TESTTMP/userpass.py \ | |
|
396 | $ hg --config extensions.x=$TESTDIR/httpserverauth.py \ | |
|
412 | 397 | > -R server serve -d -p $HGPORT1 --pid-file=hg.pid \ |
|
413 | 398 | > -A $TESTTMP/access.log -E $TESTTMP/errors.log |
|
414 | 399 | $ mv hg.pid $DAEMON_PIDS |
General Comments 0
You need to be logged in to leave comments.
Login now