<!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>[13319] CalendarServer/trunk</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/13319">13319</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-04-18 08:01:49 -0700 (Fri, 18 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Reinstate MaximumAttachmentSize limit.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkconfcaldavdappleplist">CalendarServer/trunk/conf/caldavd-apple.plist</a></li>
<li><a href="#CalendarServertrunkconfcaldavdtestplist">CalendarServer/trunk/conf/caldavd-test.plist</a></li>
<li><a href="#CalendarServertrunkconfcaldavdplist">CalendarServer/trunk/conf/caldavd.plist</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstorebridgepy">CalendarServer/trunk/twistedcaldav/storebridge.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastorefilepy">CalendarServer/trunk/txdav/caldav/datastore/file.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_attachmentspy">CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavicalendarstorepy">CalendarServer/trunk/txdav/caldav/icalendarstore.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkconfcaldavdappleplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd-apple.plist (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd-apple.plist        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/conf/caldavd-apple.plist        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -167,8 +167,12 @@
</span><span class="cx"> 
</span><span class="cx">     &lt;!-- User quota (in bytes) [0 = no quota] applies to attachments only --&gt;
</span><span class="cx">     &lt;key&gt;UserQuota&lt;/key&gt;
</span><del>-    &lt;integer&gt;104857600&lt;/integer&gt;&lt;!-- 100Mb --&gt;
</del><ins>+    &lt;integer&gt;104857600&lt;/integer&gt; &lt;!-- 100Mb --&gt;
</ins><span class="cx"> 
</span><ins>+    &lt;!-- Maximum size for a single attachment (in bytes) [0 = no limit] --&gt;
+    &lt;key&gt;MaximumAttachmentSize&lt;/key&gt;
+    &lt;integer&gt;10485760&lt;/integer&gt; &lt;!-- 10Mb --&gt;
+
</ins><span class="cx">     &lt;!-- Maximum number of calendars/address books allowed in a home --&gt;
</span><span class="cx">     &lt;!-- 0 for no limit --&gt;
</span><span class="cx">     &lt;key&gt;MaxCollectionsPerHome&lt;/key&gt;
</span></span></pre></div>
<a id="CalendarServertrunkconfcaldavdtestplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd-test.plist (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd-test.plist        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/conf/caldavd-test.plist        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -145,8 +145,12 @@
</span><span class="cx"> 
</span><span class="cx">     &lt;!-- User quota (in bytes) [0 = no quota] applies to attachments only --&gt;
</span><span class="cx">     &lt;key&gt;UserQuota&lt;/key&gt;
</span><del>-    &lt;integer&gt;104857600&lt;/integer&gt;&lt;!-- 100Mb --&gt;
</del><ins>+    &lt;integer&gt;104857600&lt;/integer&gt; &lt;!-- 100Mb --&gt;
</ins><span class="cx"> 
</span><ins>+    &lt;!-- Maximum size for a single attachment (in bytes) [0 = no limit] --&gt;
+    &lt;key&gt;MaximumAttachmentSize&lt;/key&gt;
+    &lt;integer&gt;10485760&lt;/integer&gt; &lt;!-- 10Mb --&gt;
+
</ins><span class="cx">     &lt;!-- Maximum number of calendars/address books allowed in a home --&gt;
</span><span class="cx">     &lt;!-- 0 for no limit --&gt;
</span><span class="cx">     &lt;key&gt;MaxCollectionsPerHome&lt;/key&gt;
</span></span></pre></div>
<a id="CalendarServertrunkconfcaldavdplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd.plist (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd.plist        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/conf/caldavd.plist        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -126,6 +126,10 @@
</span><span class="cx">     &lt;key&gt;UserQuota&lt;/key&gt;
</span><span class="cx">     &lt;integer&gt;104857600&lt;/integer&gt; &lt;!-- 100Mb --&gt;
</span><span class="cx"> 
</span><ins>+    &lt;!-- Maximum size for a single attachment (in bytes) [0 = no limit] --&gt;
+    &lt;key&gt;MaximumAttachmentSize&lt;/key&gt;
+    &lt;integer&gt;10485760&lt;/integer&gt; &lt;!-- 10Mb --&gt;
+
</ins><span class="cx">     &lt;!-- Maximum number of calendars/address books allowed in a home --&gt;
</span><span class="cx">     &lt;!-- 0 for no limit --&gt;
</span><span class="cx">     &lt;key&gt;MaxCollectionsPerHome&lt;/key&gt;
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -350,7 +350,8 @@
</span><span class="cx">     #
</span><span class="cx"> 
</span><span class="cx">     # Attachments
</span><del>-    &quot;UserQuota&quot;: 104857600, # User attachment quota (in bytes)
</del><ins>+    &quot;UserQuota&quot;: 104857600, # User attachment quota (in bytes - default 100MB)
+    &quot;MaximumAttachmentSize&quot;: 10485760, # Maximum size for a single attachment (in bytes - default 10MB)
</ins><span class="cx"> 
</span><span class="cx">     # Resource data
</span><span class="cx">     &quot;MaxCollectionsPerHome&quot;: 50, # Maximum number of calendars/address books allowed in a home
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstorebridgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/storebridge.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/storebridge.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx">     InvalidPerUserDataMerge,
</span><span class="cx">     AttendeeAllowedError, ResourceDeletedError, InvalidAttachmentOperation,
</span><span class="cx">     ShareeAllowedError, DuplicatePrivateCommentsError, InvalidSplit
</span><del>-)
</del><ins>+, AttachmentSizeTooLarge)
</ins><span class="cx"> from txdav.carddav.iaddressbookstore import (
</span><span class="cx">     KindChangeNotAllowedError, GroupWithUnsharedAddressNotAllowedError
</span><span class="cx"> )
</span><span class="lines">@@ -2123,6 +2123,11 @@
</span><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             yield t.loseConnection()
</span><ins>+        except AttachmentSizeTooLarge:
+            raise HTTPError(
+                ErrorResponse(FORBIDDEN,
+                              (caldav_namespace, &quot;max-attachment-size&quot;))
+            )
</ins><span class="cx">         except QuotaExceeded:
</span><span class="cx">             raise HTTPError(
</span><span class="cx">                 ErrorResponse(INSUFFICIENT_STORAGE_SPACE,
</span><span class="lines">@@ -3176,6 +3181,12 @@
</span><span class="cx">                     &quot;The action parameter in the request-URI is not valid&quot;,
</span><span class="cx">                 ))
</span><span class="cx"> 
</span><ins>+        except AttachmentSizeTooLarge:
+            raise HTTPError(
+                ErrorResponse(FORBIDDEN,
+                              (caldav_namespace, &quot;max-attachment-size&quot;))
+            )
+
</ins><span class="cx">         except QuotaExceeded:
</span><span class="cx">             raise HTTPError(ErrorResponse(
</span><span class="cx">                 INSUFFICIENT_STORAGE_SPACE,
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastorefilepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/file.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/file.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/txdav/caldav/datastore/file.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.ical import InvalidICalendarDataError
</span><span class="cx"> 
</span><del>-from txdav.caldav.icalendarstore import IAttachment
</del><ins>+from txdav.caldav.icalendarstore import IAttachment, AttachmentSizeTooLarge
</ins><span class="cx"> from txdav.caldav.icalendarstore import ICalendar, ICalendarObject
</span><span class="cx"> from txdav.caldav.icalendarstore import ICalendarHome
</span><span class="cx"> 
</span><span class="lines">@@ -803,6 +803,13 @@
</span><span class="cx">         newSize = self._file.tell()
</span><span class="cx">         # FIXME: do anything
</span><span class="cx">         self._file.close()
</span><ins>+
+        # Check max size for attachment
+        if newSize &gt; config.MaximumAttachmentSize:
+            self._path.remove()
+            return fail(AttachmentSizeTooLarge())
+
+        # Check overall user quota
</ins><span class="cx">         allowed = home.quotaAllowedBytes()
</span><span class="cx">         if allowed is not None and allowed &lt; (home.quotaUsedBytes()
</span><span class="cx">                                               + (newSize - oldSize)):
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -77,7 +77,8 @@
</span><span class="cx">     ValidOrganizerError, ShareeAllowedError, ComponentRemoveState, \
</span><span class="cx">     InvalidDefaultCalendar, \
</span><span class="cx">     InvalidAttachmentOperation, DuplicatePrivateCommentsError, \
</span><del>-    TimeRangeUpperLimit, TimeRangeLowerLimit, InvalidSplit
</del><ins>+    TimeRangeUpperLimit, TimeRangeLowerLimit, InvalidSplit, \
+    AttachmentSizeTooLarge
</ins><span class="cx"> from txdav.caldav.icalendarstore import QuotaExceeded
</span><span class="cx"> from txdav.common.datastore.sql import CommonHome, CommonHomeChild, \
</span><span class="cx">     CommonObjectResource, ECALENDARTYPE
</span><span class="lines">@@ -4053,6 +4054,15 @@
</span><span class="cx">         oldSize = self._attachment.size()
</span><span class="cx">         newSize = self._file.tell()
</span><span class="cx">         self._file.close()
</span><ins>+
+        # Check max size for attachment
+        if newSize &gt; config.MaximumAttachmentSize:
+            self._path.remove()
+            if self._creating:
+                yield self._attachment._internalRemove()
+            raise AttachmentSizeTooLarge()
+
+        # Check overall user quota
</ins><span class="cx">         allowed = home.quotaAllowedBytes()
</span><span class="cx">         if allowed is not None and allowed &lt; ((yield home.quotaUsedBytes())
</span><span class="cx">                                               + (newSize - oldSize)):
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_attachmentspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx"> from txdav.caldav.datastore.test.common import CaptureProtocol
</span><span class="cx"> from txdav.caldav.datastore.test.util import buildCalendarStore
</span><span class="cx"> from txdav.caldav.icalendarstore import IAttachmentStorageTransport, IAttachment, \
</span><del>-    QuotaExceeded
</del><ins>+    QuotaExceeded, AttachmentSizeTooLarge
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema
</span><span class="cx"> from txdav.common.datastore.test.util import CommonCommonTests, \
</span><span class="cx">     populateCalendarsFrom, deriveQuota, withSpecialQuota
</span><span class="lines">@@ -523,6 +523,77 @@
</span><span class="cx">         yield checkOriginal()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def exceedSizeTest(self, getit):
+        &quot;&quot;&quot;
+        If too many bytes are passed to the transport returned by
+        L{ICalendarObject.createAttachmentWithName},
+        L{IAttachmentStorageTransport.loseConnection} will return a L{Deferred}
+        that fails with L{AttachmentSizeTooLarge}.
+        &quot;&quot;&quot;
+        attachment = yield getit()
+        t = attachment.store(MimeType(&quot;text&quot;, &quot;x-fixture&quot;), &quot;&quot;)
+        sample = &quot;all work and no play makes jack a dull boy&quot;
+        chunk = (sample * (config.MaximumAttachmentSize / len(sample)))
+
+        t.write(chunk)
+        t.writeSequence([chunk, chunk])
+
+        d = t.loseConnection()
+        yield self.failUnlessFailure(d, AttachmentSizeTooLarge)
+
+
+    @inlineCallbacks
+    def test_exceedSizeNew(self):
+        &quot;&quot;&quot;
+        When size is exceeded on a new attachment, that attachment will no
+        longer exist.
+        &quot;&quot;&quot;
+
+        self.patch(config, &quot;MaximumAttachmentSize&quot;, 100)
+        obj = yield self.calendarObjectUnderTest()
+        yield self.exceedSizeTest(
+            lambda: obj.createAttachmentWithName(&quot;too-big.attachment&quot;)
+        )
+        self.assertEquals((yield obj.attachments()), [])
+        yield self.commit()
+        obj = yield self.calendarObjectUnderTest()
+        self.assertEquals((yield obj.attachments()), [])
+
+
+    @inlineCallbacks
+    def test_exceedSizeReplace(self):
+        &quot;&quot;&quot;
+        When size is exceeded while replacing an attachment, that attachment's
+        contents will not be replaced.
+        &quot;&quot;&quot;
+        self.patch(config, &quot;MaximumAttachmentSize&quot;, 100)
+        obj = yield self.calendarObjectUnderTest()
+        create = lambda: obj.createAttachmentWithName(&quot;exists.attachment&quot;)
+        get = lambda: obj.attachmentWithName(&quot;exists.attachment&quot;)
+        attachment = yield create()
+        t = attachment.store(MimeType(&quot;text&quot;, &quot;x-fixture&quot;), &quot;&quot;)
+        sampleData = &quot;a reasonably sized attachment&quot;
+        t.write(sampleData)
+        yield t.loseConnection()
+        yield self.exceedSizeTest(get)
+        @inlineCallbacks
+        def checkOriginal():
+            actual = yield self.attachmentToString(attachment)
+            expected = sampleData
+            # note: 60 is less than len(expected); trimming is just to make
+            # the error message look sane when the test fails.
+            actual = actual[:60]
+            self.assertEquals(actual, expected)
+        yield checkOriginal()
+        yield self.commit()
+        # Make sure that things go back to normal after a commit of that
+        # transaction.
+        obj = yield self.calendarObjectUnderTest()
+        attachment = yield get()
+        yield checkOriginal()
+
+
</ins><span class="cx">     def test_removeAttachmentWithName(self, refresh=lambda x: x):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         L{ICalendarObject.removeAttachmentWithName} will remove the calendar
</span><span class="lines">@@ -1061,6 +1132,76 @@
</span><span class="cx">         yield checkOriginal()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def exceedSizeTest(self, getit):
+        &quot;&quot;&quot;
+        If too many bytes are passed to the transport returned by
+        L{ICalendarObject.createAttachmentWithName},
+        L{IAttachmentStorageTransport.loseConnection} will return a L{Deferred}
+        that fails with L{AttachmentSizeTooLarge}.
+        &quot;&quot;&quot;
+        attachment = yield getit()
+        t = attachment.store(MimeType(&quot;text&quot;, &quot;x-fixture&quot;), &quot;&quot;)
+        sample = &quot;all work and no play makes jack a dull boy&quot;
+        chunk = (sample * (config.MaximumAttachmentSize / len(sample)))
+
+        t.write(chunk)
+        t.writeSequence([chunk, chunk])
+
+        d = t.loseConnection()
+        yield self.failUnlessFailure(d, AttachmentSizeTooLarge)
+
+
+    @inlineCallbacks
+    def test_exceedSizeNew(self):
+        &quot;&quot;&quot;
+        When size is exceeded on a new attachment, that attachment will no
+        longer exist.
+        &quot;&quot;&quot;
+        self.patch(config, &quot;MaximumAttachmentSize&quot;, 100)
+        obj = yield self.calendarObjectUnderTest()
+        yield self.exceedSizeTest(
+            lambda: obj.createAttachmentWithName(&quot;too-big.attachment&quot;)
+        )
+        self.assertEquals((yield obj.attachments()), [])
+        yield self.commit()
+        obj = yield self.calendarObjectUnderTest()
+        self.assertEquals((yield obj.attachments()), [])
+
+
+    @inlineCallbacks
+    def test_exceedSizeReplace(self):
+        &quot;&quot;&quot;
+        When size is exceeded while replacing an attachment, that attachment's
+        contents will not be replaced.
+        &quot;&quot;&quot;
+        self.patch(config, &quot;MaximumAttachmentSize&quot;, 100)
+        obj = yield self.calendarObjectUnderTest()
+        create = lambda: obj.createAttachmentWithName(&quot;exists.attachment&quot;)
+        get = lambda: obj.attachmentWithName(&quot;exists.attachment&quot;)
+        attachment = yield create()
+        t = attachment.store(MimeType(&quot;text&quot;, &quot;x-fixture&quot;), &quot;&quot;)
+        sampleData = &quot;a reasonably sized attachment&quot;
+        t.write(sampleData)
+        yield t.loseConnection()
+        yield self.exceedSizeTest(get)
+        @inlineCallbacks
+        def checkOriginal():
+            actual = yield self.attachmentToString(attachment)
+            expected = sampleData
+            # note: 60 is less than len(expected); trimming is just to make
+            # the error message look sane when the test fails.
+            actual = actual[:60]
+            self.assertEquals(actual, expected)
+        yield checkOriginal()
+        yield self.commit()
+        # Make sure that things go back to normal after a commit of that
+        # transaction.
+        obj = yield self.calendarObjectUnderTest()
+        attachment = yield get()
+        yield checkOriginal()
+
+
</ins><span class="cx">     def test_removeManagedAttachmentWithID(self, refresh=lambda x: x):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         L{ICalendarObject.removeManagedAttachmentWithID} will remove the calendar
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavicalendarstorepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/icalendarstore.py (13318 => 13319)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/icalendarstore.py        2014-04-18 15:01:12 UTC (rev 13318)
+++ CalendarServer/trunk/txdav/caldav/icalendarstore.py        2014-04-18 15:01:49 UTC (rev 13319)
</span><span class="lines">@@ -775,6 +775,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class AttachmentSizeTooLarge(Exception):
+    &quot;&quot;&quot;
+    Unable to store an attachment because it is too large.
+    &quot;&quot;&quot;
+
+
+
</ins><span class="cx"> class AttachmentStoreValidManagedID(Exception):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Specified attachment managed-id is not valid.
</span></span></pre>
</div>
</div>

</body>
</html>