diff tests/httpserverauth.py @ 41602: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
line wrap: on
line diff
--- a/tests/httpserverauth.py	Tue Feb 05 16:16:14 2019 -0500
+++ b/tests/httpserverauth.py	Tue Feb 05 16:47:19 2019 -0500
@@ -85,8 +85,22 @@
 
         return True
 
+digest = digestauthserver()
+
 def perform_authentication(hgweb, req, op):
     auth = req.headers.get(b'Authorization')
+
+    if req.headers.get(b'X-HgTest-AuthType') == b'Digest':
+        if not auth:
+            challenge = digest.makechallenge(b'mercurial')
+            raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who',
+                    [(b'WWW-Authenticate', b'Digest %s' % challenge)])
+
+        if not digest.checkauth(req, auth[7:]):
+            raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
+
+        return
+
     if not auth:
         raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who',
                 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')])
@@ -96,3 +110,4 @@
 
 def extsetup(ui):
     common.permhooks.insert(0, perform_authentication)
+    digest.adduser(b'user', b'pass', b'mercurial')