[CalendarServer-changes] [3656] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/ directory
source_changes at macosforge.org
source_changes at macosforge.org
Tue Feb 10 21:23:12 PST 2009
Revision: 3656
http://trac.macosforge.org/projects/calendarserver/changeset/3656
Author: wsanchez at apple.com
Date: 2009-02-10 21:23:09 -0800 (Tue, 10 Feb 2009)
Log Message:
-----------
Skip OD records with invalid plist XML
Modified Paths:
--------------
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_opendirectoryschema.py
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py 2009-02-10 18:46:39 UTC (rev 3655)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py 2009-02-11 05:23:09 UTC (rev 3656)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2006-2007 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2009 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@
from random import random
from uuid import UUID
+from xml.parsers.expat import ExpatError
+
import opendirectory
import dsattributes
import dsquery
@@ -355,7 +357,7 @@
return result
- def _parseResourceInfo(self, plist, guid, shortname):
+ def _parseResourceInfo(self, plist, guid, recordType, shortname):
"""
Parse OD ResourceInfo attribute and extract information that the server needs.
@@ -373,14 +375,12 @@
autoaccept = wpframework.get("AutoAcceptsInvitation", False)
proxy = wpframework.get("CalendaringDelegate", None)
read_only_proxy = wpframework.get("ReadOnlyCalendaringDelegate", None)
- except AttributeError:
+ except (ExpatError, AttributeError), e:
self.log_error(
- "Failed to parse ResourceInfo attribute of record %s (%s): %s" %
- (shortname, guid, plist,)
+ "Failed to parse ResourceInfo attribute of record (%s)%s (guid=%s): %s\n%s" %
+ (recordType, shortname, guid, e, plist,)
)
- autoaccept = False
- proxy = None
- read_only_proxy = None
+ raise ValueError("Invalid ResourceInfo")
return (autoaccept, proxy, read_only_proxy,)
@@ -699,7 +699,10 @@
if recordType in (DirectoryService.recordType_resources, DirectoryService.recordType_locations):
resourceInfo = value.get(dsattributes.kDSNAttrResourceInfo)
if resourceInfo is not None:
- autoSchedule, proxy, read_only_proxy = self._parseResourceInfo(resourceInfo, recordGUID, recordShortName)
+ try:
+ autoSchedule, proxy, read_only_proxy = self._parseResourceInfo(resourceInfo, recordGUID, recordType, recordShortName)
+ except ValueError:
+ continue
if proxy:
proxyGUIDs = (proxy,)
if read_only_proxy:
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_opendirectoryschema.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_opendirectoryschema.py 2009-02-10 18:46:39 UTC (rev 3655)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_opendirectoryschema.py 2009-02-11 05:23:09 UTC (rev 3656)
@@ -1265,20 +1265,34 @@
</plist>
"""
+ plist_invalid_xml = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.WhitePagesFramework</key>
+ <string>R&D</string>
+</dict>
+</plist>
+"""
+
test_bool = (
- (plist_good_false, False, "1234-GUID-5678", "1234-GUID-5679"),
- (plist_good_true, True, "", ""),
- (plist_good_missing, False, None, None),
- (plist_wrong, False, None, None),
- (plist_bad, False, None, None),
- (plist_invalid, False, None, None),
+ (plist_good_false, False, "1234-GUID-5678", "1234-GUID-5679", None),
+ (plist_good_true, True, "", "", None),
+ (plist_good_missing, False, None, None, None),
+ (plist_wrong, False, None, None, None),
+ (plist_bad, False, None, None, ValueError),
+ (plist_invalid, False, None, None, ValueError),
+ (plist_invalid_xml, False, None, None, ValueError),
)
def test_plists(self):
service = OpenDirectoryService(node="/Search", dosetup=False)
for item in ODResourceInfoParse.test_bool:
- item1, item2, item3 = service._parseResourceInfo(item[0], "guid", "name")
- self.assertEqual(item1, item[1])
- self.assertEqual(item2, item[2])
- self.assertEqual(item3, item[3])
+ if item[4] is None:
+ item1, item2, item3 = service._parseResourceInfo(item[0], "guid", "locations", "name")
+ self.assertEqual(item1, item[1])
+ self.assertEqual(item2, item[2])
+ self.assertEqual(item3, item[3])
+ else:
+ self.assertRaises(item[4], service._parseResourceInfo, item[0], "guid", "locations", "name")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090210/fa61bcce/attachment.html>
More information about the calendarserver-changes
mailing list