diff tests/httpserverauth.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 46432c04f010
children 6000f5b25c9b
line wrap: on
line diff
--- a/tests/httpserverauth.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/tests/httpserverauth.py	Sun Oct 06 09:45:02 2019 -0400
@@ -4,9 +4,8 @@
 import hashlib
 
 from mercurial.hgweb import common
-from mercurial import (
-    node,
-)
+from mercurial import node
+
 
 def parse_keqv_list(req, l):
     """Parse list of key=value strings where keys are not duplicated."""
@@ -18,6 +17,7 @@
         parsed[k] = v
     return parsed
 
+
 class digestauthserver(object):
     def __init__(self):
         self._user_hashes = {}
@@ -42,8 +42,10 @@
         # We aren't testing the protocol here, just that the bytes make the
         # proper round trip.  So hardcoded seems fine.
         nonce = b'064af982c5b571cea6450d8eda91c20d'
-        return b'realm="%s", nonce="%s", algorithm=MD5, qop="auth"' % (realm,
-                                                                       nonce)
+        return b'realm="%s", nonce="%s", algorithm=MD5, qop="auth"' % (
+            realm,
+            nonce,
+        )
 
     def checkauth(self, req, header):
         log = req.rawenv[b'wsgi.errors']
@@ -53,8 +55,9 @@
 
         if resp.get(b'algorithm', b'MD5').upper() != b'MD5':
             log.write(b'Unsupported algorithm: %s' % resp.get(b'algorithm'))
-            raise common.ErrorResponse(common.HTTP_FORBIDDEN,
-                                       b"unknown algorithm")
+            raise common.ErrorResponse(
+                common.HTTP_FORBIDDEN, b"unknown algorithm"
+            )
         user = resp[b'username']
         realm = resp[b'realm']
         nonce = resp[b'nonce']
@@ -79,22 +82,29 @@
 
         respdig = kd(ha1, noncebit)
         if respdig != resp[b'response']:
-            log.write(b'User/realm "%s/%s" gave %s, but expected %s'
-                      % (user, realm, resp[b'response'], respdig))
+            log.write(
+                b'User/realm "%s/%s" gave %s, but expected %s'
+                % (user, realm, resp[b'response'], respdig)
+            )
             return False
 
         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)])
+            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')
@@ -102,12 +112,16 @@
         return
 
     if not auth:
-        raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who',
-                [(b'WWW-Authenticate', b'Basic Realm="mercurial"')])
+        raise common.ErrorResponse(
+            common.HTTP_UNAUTHORIZED,
+            b'who',
+            [(b'WWW-Authenticate', b'Basic Realm="mercurial"')],
+        )
 
     if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']:
         raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
 
+
 def extsetup(ui):
     common.permhooks.insert(0, perform_authentication)
     digest.adduser(b'user', b'pass', b'mercurial')