[CalendarServer-changes] [14799] CalendarServer/trunk/txdav

source_changes at macosforge.org source_changes at macosforge.org
Tue May 19 02:18:40 PDT 2015


Revision: 14799
          http://trac.calendarserver.org//changeset/14799
Author:   cdaboo at apple.com
Date:     2015-05-19 02:18:40 -0700 (Tue, 19 May 2015)
Log Message:
-----------
Object resource names > 255 chars now generate a 403 error rather than 500.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/carddav/datastore/test/common.py
    CalendarServer/trunk/txdav/common/datastore/file.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2015-05-19 08:30:26 UTC (rev 14798)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2015-05-19 09:18:40 UTC (rev 14799)
@@ -35,7 +35,8 @@
 from txdav.idav import IPropertyStore, IDataStore
 from txdav.base.propertystore.base import PropertyName
 from txdav.common.icommondatastore import HomeChildNameAlreadyExistsError, \
-    ICommonTransaction, InvalidComponentForStoreError, InvalidUIDError
+    ICommonTransaction, InvalidComponentForStoreError, InvalidUIDError, \
+    ObjectResourceNameNotAllowedError
 from txdav.common.icommondatastore import InvalidObjectResourceError
 from txdav.common.icommondatastore import NoSuchHomeChildError
 from txdav.common.icommondatastore import ObjectResourceNameAlreadyExistsError
@@ -1393,6 +1394,36 @@
 
 
     @inlineCallbacks
+    def test_createCalendarObjectWithName_invalidName(self):
+        """
+        L{ICalendar.createCalendarObjectWithName} raises
+        L{CalendarObjectNameAlreadyExistsError} if the calendar object name
+        starts with a ".".
+        """
+        cal = yield self.calendarUnderTest()
+        comp = VComponent.fromString(test_event_text)
+        yield self.failUnlessFailure(
+            maybeDeferred(cal.createCalendarObjectWithName, ".1.ics", comp),
+            ObjectResourceNameNotAllowedError,
+        )
+
+
+    @inlineCallbacks
+    def test_createCalendarObjectWithName_longName(self):
+        """
+        L{ICalendar.createCalendarObjectWithName} raises
+        L{CalendarObjectNameAlreadyExistsError} if the calendar object name
+        is too long.
+        """
+        cal = yield self.calendarUnderTest()
+        comp = VComponent.fromString(test_event_text)
+        yield self.failUnlessFailure(
+            maybeDeferred(cal.createCalendarObjectWithName, "A" * 256 + ".ics", comp),
+            ObjectResourceNameNotAllowedError,
+        )
+
+
+    @inlineCallbacks
     def test_createCalendarObjectWithName_invalid(self):
         """
         L{ICalendar.createCalendarObjectWithName} raises

Modified: CalendarServer/trunk/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2015-05-19 08:30:26 UTC (rev 14798)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2015-05-19 09:18:40 UTC (rev 14799)
@@ -32,7 +32,8 @@
 from txdav.carddav.iaddressbookstore import IAddressBookObject, IAddressBookHome, \
     IAddressBook, IAddressBookTransaction
 from txdav.common.datastore.test.util import CommonCommonTests
-from txdav.common.icommondatastore import InvalidUIDError
+from txdav.common.icommondatastore import InvalidUIDError, \
+    ObjectResourceNameNotAllowedError
 from txdav.common.icommondatastore import ICommonTransaction
 from txdav.common.icommondatastore import InvalidObjectResourceError
 from txdav.common.icommondatastore import NoSuchHomeChildError
@@ -710,6 +711,36 @@
 
 
     @inlineCallbacks
+    def test_createAddressBookObjectWithName_invalidName(self):
+        """
+        L{IAddressBook.createAddressBookObjectWithName} raises
+        L{AddressBookObjectNameAlreadyExistsError} if an addressbook object
+        gname starts with a ".".
+        """
+        yield self.failUnlessFailure(
+            maybeDeferred(
+                (yield self.addressbookUnderTest()).createAddressBookObjectWithName,
+                ".1.vcf", VComponent.fromString(vcard4_text)),
+            ObjectResourceNameNotAllowedError
+        )
+
+
+    @inlineCallbacks
+    def test_createAddressBookObjectWithName_longName(self):
+        """
+        L{IAddressBook.createAddressBookObjectWithName} raises
+        L{AddressBookObjectNameAlreadyExistsError} if an addressbook object
+        name is too long.
+        """
+        yield self.failUnlessFailure(
+            maybeDeferred(
+                (yield self.addressbookUnderTest()).createAddressBookObjectWithName,
+                "A" * 256 + ".vcf", VComponent.fromString(vcard4_text)),
+            ObjectResourceNameNotAllowedError
+        )
+
+
+    @inlineCallbacks
     def test_createAddressBookObjectWithName_invalid(self):
         """
         L{IAddressBook.createAddressBookObjectWithName} raises

Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py	2015-05-19 08:30:26 UTC (rev 14798)
+++ CalendarServer/trunk/txdav/common/datastore/file.py	2015-05-19 09:18:40 UTC (rev 14799)
@@ -1234,6 +1234,9 @@
         if name.startswith("."):
             raise ObjectResourceNameNotAllowedError(name)
 
+        if len(name) > 255:
+            raise ObjectResourceNameNotAllowedError(name)
+
         objectResourcePath = self._path.child(name)
         if objectResourcePath.exists():
             raise ObjectResourceNameAlreadyExistsError(name)

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-19 08:30:26 UTC (rev 14798)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-19 09:18:40 UTC (rev 14799)
@@ -4871,6 +4871,9 @@
         if name.startswith("."):
             raise ObjectResourceNameNotAllowedError(name)
 
+        if len(name) > 255:
+            raise ObjectResourceNameNotAllowedError(name)
+
         c = cls._externalClass if parent.externalClass() else cls
         objectResource = c(parent, name, None, None, options=options)
         yield objectResource.setComponent(component, inserting=True)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150519/41a6a108/attachment.html>


More information about the calendarserver-changes mailing list