Mercurial > public > mercurial-scm > hg
comparison tests/httpserverauth.py @ 41589:46432c04f010
tests: enable HTTP digest testing
I suppose we could spin the client side extension off to a *.py file if it gets
more use. I was basically just looking to avoid killing the server and
relaunching it just to change authentication schemes, because that doesn't
always work on Windows.
The test changes capture the problem with py3.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 05 Feb 2019 16:47:19 -0500 |
parents | ccaa52865fac |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
41588:765a608c2108 | 41589:46432c04f010 |
---|---|
83 % (user, realm, resp[b'response'], respdig)) | 83 % (user, realm, resp[b'response'], respdig)) |
84 return False | 84 return False |
85 | 85 |
86 return True | 86 return True |
87 | 87 |
88 digest = digestauthserver() | |
89 | |
88 def perform_authentication(hgweb, req, op): | 90 def perform_authentication(hgweb, req, op): |
89 auth = req.headers.get(b'Authorization') | 91 auth = req.headers.get(b'Authorization') |
92 | |
93 if req.headers.get(b'X-HgTest-AuthType') == b'Digest': | |
94 if not auth: | |
95 challenge = digest.makechallenge(b'mercurial') | |
96 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
97 [(b'WWW-Authenticate', b'Digest %s' % challenge)]) | |
98 | |
99 if not digest.checkauth(req, auth[7:]): | |
100 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |
101 | |
102 return | |
103 | |
90 if not auth: | 104 if not auth: |
91 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | 105 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', |
92 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | 106 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) |
93 | 107 |
94 if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: | 108 if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: |
95 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | 109 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') |
96 | 110 |
97 def extsetup(ui): | 111 def extsetup(ui): |
98 common.permhooks.insert(0, perform_authentication) | 112 common.permhooks.insert(0, perform_authentication) |
113 digest.adduser(b'user', b'pass', b'mercurial') |