[CalendarServer-changes] [9362] CalendarServer/trunk/contrib/performance

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 15 11:19:22 PDT 2012


Revision: 9362
          http://trac.macosforge.org/projects/calendarserver/changeset/9362
Author:   cdaboo at apple.com
Date:     2012-06-15 11:19:21 -0700 (Fri, 15 Jun 2012)
Log Message:
-----------
Better handling of multiple auth types.

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/httpauth.py
    CalendarServer/trunk/contrib/performance/loadtest/population.py
    CalendarServer/trunk/contrib/performance/loadtest/test_sim.py

Modified: CalendarServer/trunk/contrib/performance/httpauth.py
===================================================================
--- CalendarServer/trunk/contrib/performance/httpauth.py	2012-06-15 16:26:13 UTC (rev 9361)
+++ CalendarServer/trunk/contrib/performance/httpauth.py	2012-06-15 18:19:21 UTC (rev 9362)
@@ -37,6 +37,8 @@
 
 
     def response(self, uri, method, keyring):
+        if type(keyring) is dict:
+            keyring = keyring['basic']
         username, password = keyring.passwd.find_user_password(self.realm, uri)
         credentials = ('%s:%s' % (username, password)).encode('base64').strip()
         authorization = 'basic ' + credentials
@@ -55,6 +57,8 @@
 
 
     def response(self, uri, method, keyring):
+        if type(keyring) is dict:
+            keyring = keyring['digest']
         username, password = keyring.passwd.find_user_password(self.realm, uri)
         if username is None:
             raise RuntimeError("Credentials for realm=%s uri=%s not found" % (self.realm, uri))
@@ -106,8 +110,8 @@
             'digest': DigestChallenge,
             }.get(scheme.lower())
         if challengeType is None:
-            return None
-        return challengeType(**args)
+            return "", None
+        return scheme.lower(), challengeType(**args)
 
 
     def _respondToChallenge(self, challenge, method, uri, headers, bodyProducer):
@@ -135,12 +139,17 @@
                 raise Exception(
                     "UNAUTHORIZED response with no WWW-Authenticate header")
 
-            for auth in authorization:
-                challenge = self._parse(auth)
-                if challenge is None:
-                    continue
-                self._challenged[self._authKey(method, uri)] = challenge
-                return self._respondToChallenge(challenge, method, uri, headers, bodyProducer)
+            # Always choose digest over basic if both present
+            challenges = dict([self._parse(auth) for auth in authorization])
+            if 'digest' in challenges:
+                key = 'digest'
+            elif 'basic' in challenges:
+                key = 'basic'
+            else:
+                key = None
+            if key:
+                self._challenged[self._authKey(method, uri)] = challenges[key]
+                return self._respondToChallenge(challenges[key], method, uri, headers, bodyProducer)
         return response
 
 

Modified: CalendarServer/trunk/contrib/performance/loadtest/population.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/population.py	2012-06-15 16:26:13 UTC (rev 9361)
+++ CalendarServer/trunk/contrib/performance/loadtest/population.py	2012-06-15 18:19:21 UTC (rev 9362)
@@ -26,6 +26,8 @@
 from tempfile import mkdtemp
 from itertools import izip
 from datetime import datetime
+from urllib2 import HTTPBasicAuthHandler
+from urllib2 import HTTPDigestAuthHandler
 import json
 import os
 
@@ -183,16 +185,21 @@
 
 
     def _createUser(self, number):
-        from urllib2 import HTTPDigestAuthHandler
         record = self._records[number]
         user = record.uid
-        auth = HTTPDigestAuthHandler()
-        auth.add_password(
+        authBasic = HTTPBasicAuthHandler()
+        authBasic.add_password(
             realm="Test Realm",
             uri=self.server,
             user=user.encode('utf-8'),
             passwd=record.password.encode('utf-8'))
-        return user, auth
+        authDigest = HTTPDigestAuthHandler()
+        authDigest.add_password(
+            realm="Test Realm",
+            uri=self.server,
+            user=user.encode('utf-8'),
+            passwd=record.password.encode('utf-8'))
+        return user, {"basic": authBasic, "digest": authDigest,}
 
 
     def stop(self):

Modified: CalendarServer/trunk/contrib/performance/loadtest/test_sim.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/test_sim.py	2012-06-15 16:26:13 UTC (rev 9361)
+++ CalendarServer/trunk/contrib/performance/loadtest/test_sim.py	2012-06-15 18:19:21 UTC (rev 9362)
@@ -136,8 +136,11 @@
             Populator(None), None, None, 'http://example.org:1234/', None, None)
         user, auth = calsim._createUser(0)
         self.assertEqual(
-            auth.passwd.find_user_password('Test Realm', 'http://example.org:1234/')[1],
+            auth['basic'].passwd.find_user_password('Test Realm', 'http://example.org:1234/')[1],
             'password-' + user)
+        self.assertEqual(
+            auth['digest'].passwd.find_user_password('Test Realm', 'http://example.org:1234/')[1],
+            'password-' + user)
 
 
     def test_stop(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120615/74341b08/attachment.html>


More information about the calendarserver-changes mailing list