Mercurial > public > mercurial-scm > hg-stable
comparison tests/httpserverauth.py @ 41598:549af2fa089f
tests: extract the http server authentication extension to a single module
We had 4 copy/pastes of this, and no coverage for http digests (which are
currently broken on py3).
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 05 Feb 2019 09:37:23 -0500 |
parents | |
children | ccaa52865fac |
comparison
equal
deleted
inserted
replaced
41597:a4cd77a425a3 | 41598:549af2fa089f |
---|---|
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) |