[CalendarServer-changes] [13411] CalendarServer/trunk/calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Fri May 2 16:48:16 PDT 2014


Revision: 13411
          http://trac.calendarserver.org//changeset/13411
Author:   sagen at apple.com
Date:     2014-05-02 16:48:16 -0700 (Fri, 02 May 2014)
Log Message:
-----------
Fix auth in calendar server agent

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/agent.py
    CalendarServer/trunk/calendarserver/tools/test/test_agent.py

Modified: CalendarServer/trunk/calendarserver/tools/agent.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/agent.py	2014-05-02 22:04:42 UTC (rev 13410)
+++ CalendarServer/trunk/calendarserver/tools/agent.py	2014-05-02 23:48:16 UTC (rev 13411)
@@ -34,7 +34,6 @@
 from plistlib import readPlistFromString, writePlistToString
 import socket
 
-from calendarserver.tap.util import getRootResource
 from twext.python.launchd import getLaunchDSocketFDs
 from twext.python.log import Logger
 from twext.who.checker import HTTPDigestCredentialChecker
@@ -75,7 +74,7 @@
 
     def requestAvatar(self, avatarId, mind, *interfaces):
         if IResource in interfaces:
-            if avatarId in self.allowedAvatarIds:
+            if avatarId.shortNames[0] in self.allowedAvatarIds:
                 return (IResource, self.root, lambda: None)
             else:
                 return (IResource, ForbiddenResource(), lambda: None)
@@ -91,18 +90,15 @@
     """
     isLeaf = True
 
-    def __init__(self, store, davRootResource, directory, inactivityDetector):
+    def __init__(self, store, directory, inactivityDetector):
         """
         @param store: an already opened store
-        @param davRootResource: the root resource, required for principal
-            operations
         @param directory: a directory service
         @param inactivityDetector: the InactivityDetector to tell when requests
             come in
         """
         Resource.__init__(self)
         self.store = store
-        self.davRootResource = davRootResource
         self.directory = directory
         self.inactivityDetector = inactivityDetector
 
@@ -139,10 +135,7 @@
         body = request.content.read()
         command = readPlistFromString(body)
         output = cStringIO.StringIO()
-        runner = Runner(
-            self.davRootResource, self.directory, self.store,
-            [command], output=output
-        )
+        runner = Runner(self.store, [command], output=output)
         d = runner.run()
         d.addCallback(onSuccess, output)
         d.addErrback(onError)
@@ -166,14 +159,13 @@
     family = socket.AF_INET
     endpoint = AdoptedStreamServerEndpoint(reactor, fd, family)
 
-    from twistedcaldav.config import config
-    davRootResource = getRootResource(config, store)
-    directory = davRootResource.getDirectory()
+    directory = store.directoryService()
 
     def becameInactive():
         log.warn("Agent inactive; shutting down")
         reactor.stop()
 
+    from twistedcaldav.config import config
     inactivityDetector = InactivityDetector(
         reactor, config.AgentInactivityTimeoutSeconds, becameInactive
     )
@@ -181,18 +173,18 @@
     root.putChild(
         "gateway",
         AgentGatewayResource(
-            store, davRootResource, directory, inactivityDetector
+            store, directory, inactivityDetector
         )
     )
 
     directory = OpenDirectoryDirectoryService("/Local/Default")
 
     portal = Portal(
-        AgentRealm(root, ["com.apple.calendarserver"]),
+        AgentRealm(root, [u"com.apple.calendarserver"]),
         [HTTPDigestCredentialChecker(directory)]
     )
     credentialFactory = NoQOPDigestCredentialFactory(
-        "md5", "CalendarServer Agent Realm"
+        "md5", "/Local/Default"
     )
     wrapper = HTTPAuthSessionWrapper(portal, [credentialFactory])
 
@@ -278,16 +270,14 @@
     Passes commands to gateway.Runner and returns the results
     """
 
-    def __init__(self, store, davRootResource, directory):
+    def __init__(self, store, directory):
         """
         @param store: an already opened store
-        @param davRootResource: the root resource, required for principal
             operations
         @param directory: a directory service
         """
         amp.AMP.__init__(self)
         self.store = store
-        self.davRootResource = davRootResource
         self.directory = directory
 
 
@@ -304,7 +294,7 @@
         output = cStringIO.StringIO()
         from calendarserver.tools.gateway import Runner
         runner = Runner(
-            self.davRootResource, self.directory, self.store,
+            self.store,
             [command], output=output
         )
 
@@ -332,9 +322,7 @@
         @param store: an already opened store
         """
         self.store = store
-        from twistedcaldav.config import config
-        self.davRootResource = getRootResource(config, self.store)
-        self.directory = self.davRootResource.getDirectory()
+        self.directory = self.store.directoryService()
 
 
     def buildProtocol(self, addr):

Modified: CalendarServer/trunk/calendarserver/tools/test/test_agent.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_agent.py	2014-05-02 22:04:42 UTC (rev 13410)
+++ CalendarServer/trunk/calendarserver/tools/test/test_agent.py	2014-05-02 23:48:16 UTC (rev 13411)
@@ -26,6 +26,11 @@
     pass
 
 else:
+    class FakeRecord(object):
+
+        def __init__(self, shortName):
+            self.shortNames = [shortName]
+
     class AgentTestCase(TestCase):
 
         def test_AgentRealm(self):
@@ -33,19 +38,19 @@
 
             # Valid avatar
             _ignore_interface, resource, ignored = realm.requestAvatar(
-                "abc", None, IResource
+                FakeRecord("abc"), None, IResource
             )
             self.assertEquals(resource, "root")
 
             # Not allowed avatar
             _ignore_interface, resource, ignored = realm.requestAvatar(
-                "def", None, IResource
+                FakeRecord("def"), None, IResource
             )
             self.assertTrue(isinstance(resource, ForbiddenResource))
 
             # Interface unhandled
             try:
-                realm.requestAvatar("def", None, None)
+                realm.requestAvatar(FakeRecord("def"), None, None)
             except NotImplementedError:
                 pass
             else:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140502/8b52e588/attachment.html>


More information about the calendarserver-changes mailing list