Mercurial > hg
comparison tests/test-http.t @ 36877:02bea04b4c54
hgweb: transition permissions hooks to modern request type (API)
We're trying to remove ``wsgirequest``. The permissions hooks don't
do anything they can't do with our new request type. So let's
pass that in.
This was the last use of ``wsgirequest`` in the wire protocol code!
.. api::
hgweb.hgweb_mod.permhooks no longer take a ``wsgirequest`` instance
as an argument.
Differential Revision: https://phab.mercurial-scm.org/D2793
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 10 Mar 2018 18:19:27 -0800 |
parents | e3c228b4510d |
children | 4901d1e22b27 |
comparison
equal
deleted
inserted
replaced
36876:97f44b0720e2 | 36877:02bea04b4c54 |
---|---|
166 $ cd test | 166 $ cd test |
167 $ cat << EOT > userpass.py | 167 $ cat << EOT > userpass.py |
168 > import base64 | 168 > import base64 |
169 > from mercurial.hgweb import common | 169 > from mercurial.hgweb import common |
170 > def perform_authentication(hgweb, req, op): | 170 > def perform_authentication(hgweb, req, op): |
171 > auth = req.env.get('HTTP_AUTHORIZATION') | 171 > auth = req.headers.get('Authorization') |
172 > if not auth: | 172 > if not auth: |
173 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who', | 173 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who', |
174 > [('WWW-Authenticate', 'Basic Realm="mercurial"')]) | 174 > [('WWW-Authenticate', 'Basic Realm="mercurial"')]) |
175 > if base64.b64decode(auth.split()[1]).split(':', 1) != ['user', 'pass']: | 175 > if base64.b64decode(auth.split()[1]).split(':', 1) != ['user', 'pass']: |
176 > raise common.ErrorResponse(common.HTTP_FORBIDDEN, 'no') | 176 > raise common.ErrorResponse(common.HTTP_FORBIDDEN, 'no') |
508 | 508 |
509 $ cat > cookieauth.py << EOF | 509 $ cat > cookieauth.py << EOF |
510 > from mercurial import util | 510 > from mercurial import util |
511 > from mercurial.hgweb import common | 511 > from mercurial.hgweb import common |
512 > def perform_authentication(hgweb, req, op): | 512 > def perform_authentication(hgweb, req, op): |
513 > cookie = req.env.get('HTTP_COOKIE') | 513 > cookie = req.headers.get('Cookie') |
514 > if not cookie: | 514 > if not cookie: |
515 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'no-cookie') | 515 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'no-cookie') |
516 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'Cookie: %s' % cookie) | 516 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'Cookie: %s' % cookie) |
517 > def extsetup(): | 517 > def extsetup(): |
518 > common.permhooks.insert(0, perform_authentication) | 518 > common.permhooks.insert(0, perform_authentication) |