[CalendarServer-changes] [14974] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 16 12:02:11 PDT 2015


Revision: 14974
          http://trac.calendarserver.org//changeset/14974
Author:   cdaboo at apple.com
Date:     2015-07-16 12:02:11 -0700 (Thu, 16 Jul 2015)
Log Message:
-----------
Fix exception with missing sharee when examining an attachment path.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/storebridge.py
    CalendarServer/trunk/twistedcaldav/test/test_sharing.py

Modified: CalendarServer/trunk/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/storebridge.py	2015-07-16 18:49:23 UTC (rev 14973)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py	2015-07-16 19:02:11 UTC (rev 14974)
@@ -2011,34 +2011,35 @@
                 userprivs.extend(privileges)
 
             principal = yield self.principalForUID(invite.shareeUID)
-            aces += (
-                # Inheritable specific access for the resource's associated principal.
-                davxml.ACE(
-                    davxml.Principal(davxml.HRef(principal.principalURL())),
-                    davxml.Grant(*userprivs),
-                    davxml.Protected(),
-                    TwistedACLInheritable(),
-                ),
-            )
-
-            if config.EnableProxyPrincipals:
+            if principal is not None:
                 aces += (
-                    # DAV:read/DAV:read-current-user-privilege-set access for this principal's calendar-proxy-read users.
+                    # Inheritable specific access for the resource's associated principal.
                     davxml.ACE(
-                        davxml.Principal(davxml.HRef(joinURL(principal.principalURL(), "calendar-proxy-read/"))),
+                        davxml.Principal(davxml.HRef(principal.principalURL())),
                         davxml.Grant(*userprivs),
                         davxml.Protected(),
                         TwistedACLInheritable(),
                     ),
-                    # DAV:read/DAV:read-current-user-privilege-set/DAV:write access for this principal's calendar-proxy-write users.
-                    davxml.ACE(
-                        davxml.Principal(davxml.HRef(joinURL(principal.principalURL(), "calendar-proxy-write/"))),
-                        davxml.Grant(*userprivs),
-                        davxml.Protected(),
-                        TwistedACLInheritable(),
-                    ),
                 )
 
+                if config.EnableProxyPrincipals:
+                    aces += (
+                        # DAV:read/DAV:read-current-user-privilege-set access for this principal's calendar-proxy-read users.
+                        davxml.ACE(
+                            davxml.Principal(davxml.HRef(joinURL(principal.principalURL(), "calendar-proxy-read/"))),
+                            davxml.Grant(*userprivs),
+                            davxml.Protected(),
+                            TwistedACLInheritable(),
+                        ),
+                        # DAV:read/DAV:read-current-user-privilege-set/DAV:write access for this principal's calendar-proxy-write users.
+                        davxml.ACE(
+                            davxml.Principal(davxml.HRef(joinURL(principal.principalURL(), "calendar-proxy-write/"))),
+                            davxml.Grant(*userprivs),
+                            davxml.Protected(),
+                            TwistedACLInheritable(),
+                        ),
+                    )
+
         returnValue(aces)
 
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_sharing.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_sharing.py	2015-07-16 18:49:23 UTC (rev 14973)
+++ CalendarServer/trunk/twistedcaldav/test/test_sharing.py	2015-07-16 19:02:11 UTC (rev 14974)
@@ -18,25 +18,28 @@
 from txweb2.dav.util import allDataFromStream
 from txweb2.http_headers import MimeType
 from txweb2.iweb import IResponse
+from txweb2.stream import MemoryStream
 
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 
 from twistedcaldav import customxml
 from twistedcaldav.config import config
+from twistedcaldav.ical import Component
 from twistedcaldav.test.test_cache import StubResponseCacheResource
 from twistedcaldav.test.util import norequest, StoreTestCase, SimpleStoreRequest
 
 from txdav.common.datastore.sql_tables import _BIND_MODE_DIRECT
 from txdav.xml import element as davxml
 from txdav.xml.parser import WebDAVDocument
-
-from xml.etree.cElementTree import XML
 from txdav.who.wiki import (
     DirectoryRecord as WikiDirectoryRecord,
     DirectoryService as WikiDirectoryService,
     WikiAccessLevel
 )
 
+from xml.etree.cElementTree import XML
+import urlparse
+
 sharedOwnerType = davxml.ResourceType.sharedownercalendar  # @UndefinedVariable
 regularCalendarType = davxml.ResourceType.calendar  # @UndefinedVariable
 
@@ -51,13 +54,13 @@
 
 
 
-class SharingTests(StoreTestCase):
+class BaseSharingTests(StoreTestCase):
 
     def configure(self):
         """
         Override configuration hook to turn on sharing.
         """
-        super(SharingTests, self).configure()
+        super(BaseSharingTests, self).configure()
         self.patch(config.Sharing, "Enabled", True)
         self.patch(config.Sharing.Calendars, "Enabled", True)
         self.patch(config.Authentication.Wiki, "Enabled", True)
@@ -65,7 +68,7 @@
 
     @inlineCallbacks
     def setUp(self):
-        yield super(SharingTests, self).setUp()
+        yield super(BaseSharingTests, self).setUp()
         self.resource = yield self._getResource()
 
 
@@ -73,7 +76,7 @@
     def _refreshRoot(self, request=None):
         if request is None:
             request = norequest()
-        result = yield super(SharingTests, self)._refreshRoot(request)
+        result = yield super(BaseSharingTests, self)._refreshRoot(request)
         self.resource = (
             yield self.site.resource.locateChild(request, ["calendar"])
         )[0]
@@ -228,6 +231,9 @@
         return None
 
 
+
+class SharingTests(BaseSharingTests):
+
     @inlineCallbacks
     def test_upgradeToShare(self):
 
@@ -1499,3 +1505,156 @@
                 customxml.InviteStatusAccepted(),
             ),
         ))
+
+
+
+class DropboxSharingTests(BaseSharingTests):
+
+    def configure(self):
+        """
+        Override configuration hook to turn on dropbox.
+        """
+        super(DropboxSharingTests, self).configure()
+        self.patch(config, "EnableDropBox", True)
+        self.patch(config, "EnableManagedAttachments", False)
+
+
+    @inlineCallbacks
+    def test_dropboxWithMissingInvitee(self):
+
+        yield self.resource.upgradeToShare()
+
+        yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
+            <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+                <CS:set>
+                    <D:href>mailto:user02 at example.com</D:href>
+                    <CS:summary>My Shared Calendar</CS:summary>
+                    <CS:read-write/>
+                </CS:set>
+            </CS:share>
+            """)
+
+        propInvite = (yield self.resource.readProperty(customxml.Invite, None))
+        uid = self._getUIDElementValue(propInvite)
+
+        yield self._doPOSTSharerAccept("""<?xml version='1.0' encoding='UTF-8'?>
+            <invite-reply xmlns='http://calendarserver.org/ns/'>
+              <href xmlns='DAV:'>mailto:user01 at example.com</href>
+              <invite-accepted/>
+              <hosturl>
+                <href xmlns='DAV:'>/calendars/__uids__/user01/calendar/</href>
+              </hosturl>
+              <in-reply-to>%s</in-reply-to>
+              <summary>The Shared Calendar</summary>
+              <common-name>User 02</common-name>
+              <first-name>user</first-name>
+              <last-name>02</last-name>
+            </invite-reply>
+            """ % (uid,)
+        )
+
+        calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+        component = Component.fromString("""BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART:20060101T100000Z
+DURATION:PT1H
+SUMMARY:event 1
+UID:event1 at ninevah.local
+ATTACH;VALUE=URI:/calendars/users/home1/some-dropbox-id/some-dropbox-id/caldavd.plist
+X-APPLE-DROPBOX:/calendars/users/home1/dropbox/some-dropbox-id
+END:VEVENT
+END:VCALENDAR
+""")
+        yield calendar.createCalendarObjectWithName("dropbox.ics", component)
+        yield self.commit()
+
+        yield self.directory.removeRecords(((yield self.userUIDFromShortName("user02")),))
+        self.assertTrue((yield self.userUIDFromShortName("user02")) is None)
+
+        # Get dropbox and test ACLs
+        request = SimpleStoreRequest(self, "GET", "/calendars/__uids__/user01/dropbox/some-dropbox-id/")
+        resource = yield request.locateResource("/calendars/__uids__/user01/dropbox/some-dropbox-id/")
+        acl = yield resource.accessControlList(request)
+        self.assertTrue(acl is not None)
+
+
+
+class MamnagedAttachmentSharingTests(BaseSharingTests):
+
+    def configure(self):
+        """
+        Override configuration hook to turn on managed attachments.
+        """
+        super(MamnagedAttachmentSharingTests, self).configure()
+        self.patch(config, "EnableDropBox", False)
+        self.patch(config, "EnableManagedAttachments", True)
+
+
+    @inlineCallbacks
+    def test_attachmentWithMissingInvitee(self):
+
+        yield self.resource.upgradeToShare()
+
+        yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
+            <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+                <CS:set>
+                    <D:href>mailto:user02 at example.com</D:href>
+                    <CS:summary>My Shared Calendar</CS:summary>
+                    <CS:read-write/>
+                </CS:set>
+            </CS:share>
+            """)
+
+        propInvite = (yield self.resource.readProperty(customxml.Invite, None))
+        uid = self._getUIDElementValue(propInvite)
+
+        yield self._doPOSTSharerAccept("""<?xml version='1.0' encoding='UTF-8'?>
+            <invite-reply xmlns='http://calendarserver.org/ns/'>
+              <href xmlns='DAV:'>mailto:user01 at example.com</href>
+              <invite-accepted/>
+              <hosturl>
+                <href xmlns='DAV:'>/calendars/__uids__/user01/calendar/</href>
+              </hosturl>
+              <in-reply-to>%s</in-reply-to>
+              <summary>The Shared Calendar</summary>
+              <common-name>User 02</common-name>
+              <first-name>user</first-name>
+              <last-name>02</last-name>
+            </invite-reply>
+            """ % (uid,)
+        )
+
+        calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+        component = Component.fromString("""BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART:20060101T100000Z
+DURATION:PT1H
+SUMMARY:event 1
+UID:event1 at ninevah.local
+END:VEVENT
+END:VCALENDAR
+""")
+        obj = yield calendar.createCalendarObjectWithName("dropbox.ics", component)
+        _ignore_attachment, location = yield obj.addAttachment(None, MimeType("text", "plain"), "new.txt", MemoryStream("new attachment text"))
+        yield self.commit()
+
+        yield self.directory.removeRecords(((yield self.userUIDFromShortName("user02")),))
+        self.assertTrue((yield self.userUIDFromShortName("user02")) is None)
+
+        # Get dropbox and test ACLs
+        location = urlparse.urlparse(location)[2]
+        location = "/".join(location.split("/")[:-1])
+        request = SimpleStoreRequest(self, "GET", location)
+        resource = yield request.locateResource(location)
+        acl = yield resource.accessControlList(request)
+        self.assertTrue(acl is not None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150716/ba7d7ee1/attachment-0001.html>


More information about the calendarserver-changes mailing list