Selaa lähdekoodia

Strip newlines from base64 data when building Basic auth header. Fixes #21

Mike Naberezny 12 vuotta sitten
vanhempi
commit
0bb1cc09fd
3 muutettua tiedostoa jossa 8 lisäystä ja 5 poistoa
  1. 3 0
      CHANGES.txt
  2. 3 3
      supervisor/http_client.py
  3. 2 2
      supervisor/xmlrpc.py

+ 3 - 0
CHANGES.txt

@@ -5,6 +5,9 @@
   or group name contains characters that are not compatible with the
   eventlistener protocol.
 
+- Fixed a bug where the ``tail -f`` command in ``supervisorctl`` would fail
+  if the combined length of the username and password was over 56 characters.
+
 3.0b2 (2013-05-28)
 ------------------
 

+ 3 - 3
supervisor/http_client.py

@@ -117,9 +117,9 @@ class HTTPHandler(object, asynchat.async_chat):
         self.header('Accept', '*/*')
         self.header('User-agent', self.user_agent)
         if self.password:
-            auth = '%s:%s' % (self.username, self.password)
-            auth = base64.encodestring(auth).strip()
-            self.header('Authorization', 'Basic %s' % auth)
+            unencoded = '%s:%s' % (self.username, self.password)
+            encoded = base64.encodestring(unencoded).replace('\n', '')
+            self.header('Authorization', 'Basic %s' % encoded)
         self.push(CRLF)
         self.push(CRLF)
 

+ 2 - 2
supervisor/xmlrpc.py

@@ -7,6 +7,7 @@ import re
 from cStringIO import StringIO
 import traceback
 import sys
+import base64
 
 from supervisor.medusa.http_server import get_header
 from supervisor.medusa.xmlrpc_handler import xmlrpc_handler
@@ -451,8 +452,7 @@ class SupervisorTransport(xmlrpclib.Transport):
             # basic auth
             if self.username is not None and self.password is not None:
                 unencoded = "%s:%s" % (self.username, self.password)
-                encoded = unencoded.encode('base64')
-                encoded = encoded.replace('\012', '')
+                encoded = base64.encodestring(unencoded).replace('\n', '')
                 self.headers["Authorization"] = "Basic %s" % encoded
                 
         self.headers["Content-Length"] = str(len(request_body))