[CalendarServer-changes] [9378] CalendarServer/trunk/calendarserver/tools
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 20 19:23:32 PDT 2012
Revision: 9378
http://trac.macosforge.org/projects/calendarserver/changeset/9378
Author: cdaboo at apple.com
Date: 2012-06-20 19:23:31 -0700 (Wed, 20 Jun 2012)
Log Message:
-----------
calverify updated to handle recurrence truncation and some cu-address conversion issues.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/calverify.py
CalendarServer/trunk/calendarserver/tools/test/calverify/accounts.xml
CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
Modified: CalendarServer/trunk/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/calverify.py 2012-06-20 18:06:18 UTC (rev 9377)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py 2012-06-21 02:23:31 UTC (rev 9378)
@@ -71,7 +71,7 @@
import traceback
import uuid
-VERSION = "3"
+VERSION = "4"
def usage(e=None):
if e:
@@ -713,9 +713,14 @@
caldata = yield self.getCalendar(resid, self.fix)
if caldata is None:
- returnValue((False, self.parseError))
+ if self.parseError:
+ returnValue((False, self.parseError))
+ else:
+ returnValue((True, "Nothing to scan"))
component = Component(None, pycalendar=caldata)
+ if self.config.MaxInstancesForRRULE:
+ component.truncateRecurrence(self.config.MaxInstancesForRRULE)
result = True
message = ""
try:
@@ -766,12 +771,29 @@
continue
organizer = subcomponent.getProperty("ORGANIZER")
if organizer:
- if organizer.value().startswith("http"):
+ cuaddr = organizer.value()
+
+ # http(s) principals need to be converted to urn:uuid
+ if cuaddr.startswith("http"):
if doFix:
component.normalizeCalendarUserAddresses(lookupFunction, self.directoryService().principalForCalendarUserAddress)
else:
raise InvalidICalendarDataError("iCalendar ORGANIZER starts with 'http(s)'")
- elif organizer.hasParameter("CALENDARSERVER-OLD-CUA"):
+ else:
+ if ("@" in cuaddr) and (":" not in cuaddr) and ("/" not in cuaddr):
+ if doFix:
+ # Add back in mailto: then re-normalize to urn:uuid if possible
+ organizer.setValue("mailto:%s" % (cuaddr,))
+ component.normalizeCalendarUserAddresses(lookupFunction, self.directoryService().principalForCalendarUserAddress)
+
+ # Remove any SCHEDULE-AGENT=NONE
+ if organizer.parameterValue("SCHEDULE-AGENT", "SERVER") == "NONE":
+ organizer.removeParameter("SCHEDULE-AGENT")
+ else:
+ raise InvalidICalendarDataError("iCalendar ORGANIZER missing mailto:")
+
+ # CALENDARSERVER-OLD-CUA needs to be base64 encoded
+ if organizer.hasParameter("CALENDARSERVER-OLD-CUA"):
oldcua = organizer.parameterValue("CALENDARSERVER-OLD-CUA")
if not oldcua.startswith("base64-") and not self.options["nobase64"]:
if doFix:
@@ -780,12 +802,25 @@
raise InvalidICalendarDataError("iCalendar ORGANIZER CALENDARSERVER-OLD-CUA not base64")
for attendee in subcomponent.properties("ATTENDEE"):
- if attendee.value().startswith("http"):
+ cuaddr = attendee.value()
+
+ # http(s) principals need to be converted to urn:uuid
+ if cuaddr.startswith("http"):
if doFix:
component.normalizeCalendarUserAddresses(lookupFunction, self.directoryService().principalForCalendarUserAddress)
else:
raise InvalidICalendarDataError("iCalendar ATTENDEE starts with 'http(s)'")
- elif attendee.hasParameter("CALENDARSERVER-OLD-CUA"):
+ else:
+ if ("@" in cuaddr) and (":" not in cuaddr) and ("/" not in cuaddr):
+ if doFix:
+ # Add back in mailto: then re-normalize to urn:uuid if possible
+ attendee.setValue("mailto:%s" % (cuaddr,))
+ component.normalizeCalendarUserAddresses(lookupFunction, self.directoryService().principalForCalendarUserAddress)
+ else:
+ raise InvalidICalendarDataError("iCalendar ATTENDEE missing mailto:")
+
+ # CALENDARSERVER-OLD-CUA needs to be base64 encoded
+ if attendee.hasParameter("CALENDARSERVER-OLD-CUA"):
oldcua = attendee.parameterValue("CALENDARSERVER-OLD-CUA")
if not oldcua.startswith("base64-") and not self.options["nobase64"]:
if doFix:
@@ -793,6 +828,7 @@
else:
raise InvalidICalendarDataError("iCalendar ATTENDEE CALENDARSERVER-OLD-CUA not base64")
+
@inlineCallbacks
def fixCalendarData(self, resid, isinbox):
"""
@@ -1462,6 +1498,7 @@
self.parseError = "Failed to parse"
returnValue(None)
+ self.parseError = None
returnValue(caldata)
Modified: CalendarServer/trunk/calendarserver/tools/test/calverify/accounts.xml
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/calverify/accounts.xml 2012-06-20 18:06:18 UTC (rev 9377)
+++ CalendarServer/trunk/calendarserver/tools/test/calverify/accounts.xml 2012-06-21 02:23:31 UTC (rev 9378)
@@ -40,4 +40,11 @@
<name>Example User3</name>
<email-address>example3 at example.com</email-address>
</user>
+ <user>
+ <uid>example4</uid>
+ <guid>A89E3A97-1658-4E45-A185-479F3E49D446</guid>
+ <password>example</password>
+ <name>Example User4</name>
+ <email-address>example4 at example.com</email-address>
+ </user>
</accounts>
Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2012-06-20 18:06:18 UTC (rev 9377)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2012-06-21 02:23:31 UTC (rev 9378)
@@ -336,7 +336,31 @@
END:VCALENDAR
""".replace("\n", "\r\n")
+# Non-mailto: Organizer
+BAD10_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:BAD10
+DTEND:20100307T151500Z
+TRANSP:OPAQUE
+SUMMARY:Ancient event
+DTSTART:20100307T111500Z
+DTSTAMP:20100303T181220Z
+ORGANIZER;CN=Example User1;SCHEDULE-AGENT=NONE:example1 at example.com
+ATTENDEE;CN=Example User1:example1 at example.com
+ATTENDEE;CN=Example User2:example2 at example.com
+ATTENDEE;CN=Example User3:/principals/users/example3
+ATTENDEE;CN=Example User4:http://demo.com:8008/principals/users/example4
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+
class CalVerifyDataTests(CommonCommonTests, unittest.TestCase):
"""
Tests calverify for iCalendar data problems.
@@ -363,6 +387,7 @@
"bad7.ics" : (BAD7_ICS, metadata,),
"ok8.ics" : (OK8_ICS, metadata,),
"bad9.ics" : (BAD9_ICS, metadata,),
+ "bad10.ics" : (BAD10_ICS, metadata,),
}
},
}
@@ -383,6 +408,7 @@
os.path.dirname(__file__), "calverify", "resources.xml"
)
)
+
self.rootResource = getRootResource(config, self._sqlCalendarStore)
self.directory = self.rootResource.getDirectory()
@@ -424,6 +450,16 @@
)
+ @inlineCallbacks
+ def calendarObjectUnderTest(self, name, txn=None):
+ """
+ Get the calendar object detailed by C{requirements[home_name][calendar_name][name]}.
+ """
+ returnValue((yield
+ (yield self.calendarUnderTest(txn)).calendarObjectWithName(name))
+ )
+
+
def verifyResultsByUID(self, results, expected):
reported = set([(home, uid) for home, uid, _ignore_resid, _ignore_reason in results])
self.assertEqual(reported, expected)
@@ -449,9 +485,10 @@
}
output = StringIO()
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, False)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
("home1", "BAD1",),
("home1", "BAD2",),
@@ -461,6 +498,7 @@
("home1", "BAD6",),
("home1", "BAD7",),
("home1", "BAD9",),
+ ("home1", "BAD10",),
)))
sync_token_new = (yield (yield self.calendarUnderTest()).syncToken())
@@ -491,9 +529,10 @@
self.patch(config.Scheduling.Options, "PrincipalHostAliases", "demo.com")
self.patch(config, "HTTPPort", 8008)
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, True)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
("home1", "BAD1",),
("home1", "BAD2",),
@@ -503,19 +542,34 @@
("home1", "BAD6",),
("home1", "BAD7",),
("home1", "BAD9",),
+ ("home1", "BAD10",),
)))
# Do scan
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, False)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
("home1", "BAD1",),
)))
sync_token_new = (yield (yield self.calendarUnderTest()).syncToken())
self.assertNotEqual(sync_token_old, sync_token_new)
+
+ # Make sure mailto: fix results in urn:uuid value without SCHEDULE-AGENT
+ obj = yield self.calendarObjectUnderTest("bad10.ics")
+ ical = yield obj.component()
+ org = ical.getOrganizerProperty()
+ self.assertEqual(org.value(), "urn:uuid:D46F3D71-04B7-43C2-A7B6-6F92F92E61D0")
+ self.assertFalse(org.hasParameter("SCHEDULE-AGENT"))
+ for attendee in ical.getAllAttendeeProperties():
+ self.assertTrue(
+ attendee.value().startswith("urn:uuid:") or
+ attendee.value().startswith("/principals")
+ )
+
@inlineCallbacks
def test_scanBadCuaOnly(self):
@@ -538,15 +592,17 @@
}
output = StringIO()
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, False)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
("home1", "BAD4",),
("home1", "BAD5",),
("home1", "BAD6",),
("home1", "BAD7",),
("home1", "BAD9",),
+ ("home1", "BAD10",),
)))
sync_token_new = (yield (yield self.calendarUnderTest()).syncToken())
@@ -577,22 +633,25 @@
self.patch(config.Scheduling.Options, "PrincipalHostAliases", "demo.com")
self.patch(config, "HTTPPort", 8008)
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, True)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
("home1", "BAD4",),
("home1", "BAD5",),
("home1", "BAD6",),
("home1", "BAD7",),
("home1", "BAD9",),
+ ("home1", "BAD10",),
)))
# Do scan
calverify = CalVerifyService(self._sqlCalendarStore, options, output, reactor, config)
+ calverify.emailDomain = "example.com"
yield calverify.doScan(True, False, False)
- self.assertEqual(calverify.results["Number of events to process"], 10)
+ self.assertEqual(calverify.results["Number of events to process"], 11)
self.verifyResultsByUID(calverify.results["Bad iCalendar data"], set((
)))
@@ -788,6 +847,7 @@
"tzid":"",
}
calverifyNo64 = CalVerifyService(self._sqlCalendarStore, optionsNo64, StringIO(), reactor, config)
+ calverifyNo64.emailDomain = "example.com"
options64 = {
"ical":True,
@@ -798,6 +858,7 @@
"tzid":"",
}
calverify64 = CalVerifyService(self._sqlCalendarStore, options64, StringIO(), reactor, config)
+ calverify64.emailDomain = "example.com"
for bad, oknobase64, okbase64 in data:
bad = bad.replace("\r\n ", "")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120620/0f1651dd/attachment-0001.html>
More information about the calendarserver-changes
mailing list