<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13411] CalendarServer/trunk/calendarserver/tools</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13411">13411</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-05-02 16:48:16 -0700 (Fri, 02 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix auth in calendar server agent</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsagentpy">CalendarServer/trunk/calendarserver/tools/agent.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_agentpy">CalendarServer/trunk/calendarserver/tools/test/test_agent.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsagentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/agent.py (13410 => 13411)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -34,7 +34,6 @@
</span><span class="cx"> from plistlib import readPlistFromString, writePlistToString
</span><span class="cx"> import socket
</span><span class="cx">
</span><del>-from calendarserver.tap.util import getRootResource
</del><span class="cx"> from twext.python.launchd import getLaunchDSocketFDs
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twext.who.checker import HTTPDigestCredentialChecker
</span><span class="lines">@@ -75,7 +74,7 @@
</span><span class="cx">
</span><span class="cx"> def requestAvatar(self, avatarId, mind, *interfaces):
</span><span class="cx"> if IResource in interfaces:
</span><del>- if avatarId in self.allowedAvatarIds:
</del><ins>+ if avatarId.shortNames[0] in self.allowedAvatarIds:
</ins><span class="cx"> return (IResource, self.root, lambda: None)
</span><span class="cx"> else:
</span><span class="cx"> return (IResource, ForbiddenResource(), lambda: None)
</span><span class="lines">@@ -91,18 +90,15 @@
</span><span class="cx"> """
</span><span class="cx"> isLeaf = True
</span><span class="cx">
</span><del>- def __init__(self, store, davRootResource, directory, inactivityDetector):
</del><ins>+ def __init__(self, store, directory, inactivityDetector):
</ins><span class="cx"> """
</span><span class="cx"> @param store: an already opened store
</span><del>- @param davRootResource: the root resource, required for principal
- operations
</del><span class="cx"> @param directory: a directory service
</span><span class="cx"> @param inactivityDetector: the InactivityDetector to tell when requests
</span><span class="cx"> come in
</span><span class="cx"> """
</span><span class="cx"> Resource.__init__(self)
</span><span class="cx"> self.store = store
</span><del>- self.davRootResource = davRootResource
</del><span class="cx"> self.directory = directory
</span><span class="cx"> self.inactivityDetector = inactivityDetector
</span><span class="cx">
</span><span class="lines">@@ -139,10 +135,7 @@
</span><span class="cx"> body = request.content.read()
</span><span class="cx"> command = readPlistFromString(body)
</span><span class="cx"> output = cStringIO.StringIO()
</span><del>- runner = Runner(
- self.davRootResource, self.directory, self.store,
- [command], output=output
- )
</del><ins>+ runner = Runner(self.store, [command], output=output)
</ins><span class="cx"> d = runner.run()
</span><span class="cx"> d.addCallback(onSuccess, output)
</span><span class="cx"> d.addErrback(onError)
</span><span class="lines">@@ -166,14 +159,13 @@
</span><span class="cx"> family = socket.AF_INET
</span><span class="cx"> endpoint = AdoptedStreamServerEndpoint(reactor, fd, family)
</span><span class="cx">
</span><del>- from twistedcaldav.config import config
- davRootResource = getRootResource(config, store)
- directory = davRootResource.getDirectory()
</del><ins>+ directory = store.directoryService()
</ins><span class="cx">
</span><span class="cx"> def becameInactive():
</span><span class="cx"> log.warn("Agent inactive; shutting down")
</span><span class="cx"> reactor.stop()
</span><span class="cx">
</span><ins>+ from twistedcaldav.config import config
</ins><span class="cx"> inactivityDetector = InactivityDetector(
</span><span class="cx"> reactor, config.AgentInactivityTimeoutSeconds, becameInactive
</span><span class="cx"> )
</span><span class="lines">@@ -181,18 +173,18 @@
</span><span class="cx"> root.putChild(
</span><span class="cx"> "gateway",
</span><span class="cx"> AgentGatewayResource(
</span><del>- store, davRootResource, directory, inactivityDetector
</del><ins>+ store, directory, inactivityDetector
</ins><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> directory = OpenDirectoryDirectoryService("/Local/Default")
</span><span class="cx">
</span><span class="cx"> portal = Portal(
</span><del>- AgentRealm(root, ["com.apple.calendarserver"]),
</del><ins>+ AgentRealm(root, [u"com.apple.calendarserver"]),
</ins><span class="cx"> [HTTPDigestCredentialChecker(directory)]
</span><span class="cx"> )
</span><span class="cx"> credentialFactory = NoQOPDigestCredentialFactory(
</span><del>- "md5", "CalendarServer Agent Realm"
</del><ins>+ "md5", "/Local/Default"
</ins><span class="cx"> )
</span><span class="cx"> wrapper = HTTPAuthSessionWrapper(portal, [credentialFactory])
</span><span class="cx">
</span><span class="lines">@@ -278,16 +270,14 @@
</span><span class="cx"> Passes commands to gateway.Runner and returns the results
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def __init__(self, store, davRootResource, directory):
</del><ins>+ def __init__(self, store, directory):
</ins><span class="cx"> """
</span><span class="cx"> @param store: an already opened store
</span><del>- @param davRootResource: the root resource, required for principal
</del><span class="cx"> operations
</span><span class="cx"> @param directory: a directory service
</span><span class="cx"> """
</span><span class="cx"> amp.AMP.__init__(self)
</span><span class="cx"> self.store = store
</span><del>- self.davRootResource = davRootResource
</del><span class="cx"> self.directory = directory
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -304,7 +294,7 @@
</span><span class="cx"> output = cStringIO.StringIO()
</span><span class="cx"> from calendarserver.tools.gateway import Runner
</span><span class="cx"> runner = Runner(
</span><del>- self.davRootResource, self.directory, self.store,
</del><ins>+ self.store,
</ins><span class="cx"> [command], output=output
</span><span class="cx"> )
</span><span class="cx">
</span><span class="lines">@@ -332,9 +322,7 @@
</span><span class="cx"> @param store: an already opened store
</span><span class="cx"> """
</span><span class="cx"> self.store = store
</span><del>- from twistedcaldav.config import config
- self.davRootResource = getRootResource(config, self.store)
- self.directory = self.davRootResource.getDirectory()
</del><ins>+ self.directory = self.store.directoryService()
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def buildProtocol(self, addr):
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_agentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_agent.py (13410 => 13411)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -26,6 +26,11 @@
</span><span class="cx"> pass
</span><span class="cx">
</span><span class="cx"> else:
</span><ins>+ class FakeRecord(object):
+
+ def __init__(self, shortName):
+ self.shortNames = [shortName]
+
</ins><span class="cx"> class AgentTestCase(TestCase):
</span><span class="cx">
</span><span class="cx"> def test_AgentRealm(self):
</span><span class="lines">@@ -33,19 +38,19 @@
</span><span class="cx">
</span><span class="cx"> # Valid avatar
</span><span class="cx"> _ignore_interface, resource, ignored = realm.requestAvatar(
</span><del>- "abc", None, IResource
</del><ins>+ FakeRecord("abc"), None, IResource
</ins><span class="cx"> )
</span><span class="cx"> self.assertEquals(resource, "root")
</span><span class="cx">
</span><span class="cx"> # Not allowed avatar
</span><span class="cx"> _ignore_interface, resource, ignored = realm.requestAvatar(
</span><del>- "def", None, IResource
</del><ins>+ FakeRecord("def"), None, IResource
</ins><span class="cx"> )
</span><span class="cx"> self.assertTrue(isinstance(resource, ForbiddenResource))
</span><span class="cx">
</span><span class="cx"> # Interface unhandled
</span><span class="cx"> try:
</span><del>- realm.requestAvatar("def", None, None)
</del><ins>+ realm.requestAvatar(FakeRecord("def"), None, None)
</ins><span class="cx"> except NotImplementedError:
</span><span class="cx"> pass
</span><span class="cx"> else:
</span></span></pre>
</div>
</div>
</body>
</html>