[CalendarServer-changes] [1055] CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/ directory

source_changes at macosforge.org source_changes at macosforge.org
Wed Jan 17 08:27:14 PST 2007


Revision: 1055
          http://trac.macosforge.org/projects/calendarserver/changeset/1055
Author:   cdaboo at apple.com
Date:     2007-01-17 08:27:13 -0800 (Wed, 17 Jan 2007)

Log Message:
-----------
Read the /Computers record for this server's host machine and extract information relevant to the calendar service from that.
Enable/disable the server based on the service record information.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/appleopendirectory.py

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/test/test_opendirectoryschema.py

Modified: CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/appleopendirectory.py	2007-01-16 22:46:58 UTC (rev 1054)
+++ CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/appleopendirectory.py	2007-01-17 16:27:13 UTC (rev 1055)
@@ -25,6 +25,7 @@
     "OpenDirectoryInitError",
 ]
 
+import os
 import sys
 
 import opendirectory
@@ -38,6 +39,8 @@
 from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
 from twistedcaldav.directory.directory import DirectoryError, UnknownRecordTypeError
 
+from plistlib import readPlistFromString
+
 recordListCacheTimeout = 60 * 30 # 30 minutes
 
 class OpenDirectoryService(DirectoryService):
@@ -49,9 +52,11 @@
     def __repr__(self):
         return "<%s %r: %r>" % (self.__class__.__name__, self.realmName, self.node)
 
-    def __init__(self, node="/Search"):
+    def __init__(self, node="/Search", dosetup=True):
         """
         @param node: an OpenDirectory node name to bind to.
+		@param dosetup: if C{True} then the directory records are initialized,
+			if C{False} they are not. This is only set to C{False} when doing unit tests.
         """
         try:
             directory = opendirectory.odInit(node)
@@ -62,11 +67,12 @@
         self.realmName = node
         self.directory = directory
         self.node = node
+        self.computerRecordName = ""
         self._records = {}
         self._delayedCalls = set()
 
-        for recordType in self.recordTypes():
-            self.recordsForType(recordType)
+        if dosetup:
+            self.setup()
 
     def __cmp__(self, other):
         if not isinstance(other, DirectoryRecord):
@@ -84,6 +90,116 @@
             h = (h + hash(getattr(self, attr))) & sys.maxint
         return h
 
+    def _lookupVHostRecord(self):
+        """
+        Get the OD service record for this host.
+        """
+
+        # Get MAC address
+        macaddr = os.popen('/sbin/ifconfig en0|grep ether').read().replace('\n','').split()[1]
+        
+        # Find a record in /Computers with an ENetAddress attribute value equal to the MAC address
+        # and return some useful attributes.
+        attrs = [
+            dsattributes.kDS1AttrGeneratedUID,
+            dsattributes.kDSNAttrRecordName,
+            dsattributes.kDS1AttrXMLPlist,
+        ]
+
+        try:
+            results = opendirectory.queryRecordsWithAttributes(
+                self.directory,
+                {dsattributes.kDS1AttrENetAddress: macaddr},
+                dsattributes.eDSExact,
+                False,
+                False,
+                dsattributes.kDSStdRecordTypeComputers,
+                attrs)
+        except opendirectory.ODError, ex:
+            log.msg("Open Directory (node=%s) error: %s" % (self.realmName, str(ex)))
+            raise
+        
+        # Must have a single result
+        if len(results) == 0:
+            msg = "Open Directory (node=%s) no /Computers record with EnetAddress: %s" % (self.realmName, macaddr,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        elif len(results) > 1:
+            msg = "Open Directory (node=%s) multiple /Computers records with EnetAddress: %s" % (self.realmName, macaddr,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        else:
+            self.computerRecordName = results.keys()[0]
+            record = results[self.computerRecordName]
+        
+        # Get XMLPlist value
+        plist = record.get(dsattributes.kDS1AttrXMLPlist, None)
+        if not plist:
+            msg = "Open Directory (node=%s) /Computers/%s record does not have an XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        
+        # Parse it and extract useful information
+        self._parseXMLPlist(plist, record[dsattributes.kDS1AttrGeneratedUID])
+    
+    def _parseXMLPlist(self, plist, recordguid):
+        # Parse the plist and look for our special entry
+        plist = readPlistFromString(plist)
+        vhosts = plist.get("com.apple.macosxserver.virtualhosts", None)
+        if not vhosts:
+            msg = "Open Directory (node=%s) /Computers/%s record does not have a com.apple.macosxserver.virtualhosts in its XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        
+        # Iterate over each vhost and find one that is a calendar service
+        hostguid = None
+        for key, value in vhosts.iteritems():
+            serviceTypes = value.get("serviceType", None)
+            if serviceTypes:
+                for type in serviceTypes:
+                    if type == "calendar":
+                        hostguid = key
+                        break
+                    
+        if not hostguid:
+            msg = "Open Directory (node=%s) /Computers/%s record does not have a calendar service in its XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+            
+        # Look at the service data
+        serviceInfos = vhosts[hostguid].get("serviceInfo", None)
+        if not serviceInfos or not serviceInfos.has_key("calendar"):
+            msg = "Open Directory (node=%s) /Computers/%s record does not have a calendar service in its XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        serviceInfo = serviceInfos["calendar"]
+        
+        # Check that this service is enabled
+        enabled = serviceInfo.get("enabled", "YES")
+        if enabled != "YES":
+            msg = "Open Directory (node=%s) /Computers/%s record does not have an enabled calendar service in its XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        
+        # Get useful templates
+        templates = serviceInfo.get("templates", None)
+        if not templates or not templates.has_key("calendarUserAddresses"):
+            msg = "Open Directory (node=%s) /Computers/%s record does not have a template for calendar user addresses in its XMLPlist attribute value" % (self.realmName, self.computerRecordName,)
+            log.msg(msg)
+            raise OpenDirectoryInitError(msg)
+        
+        # Grab the templates we need for calendar user addresses
+        self.cuaddrtemplates = templates["calendarUserAddresses"]
+        
+        # Create the string we will use to match users with accounts on this server
+        self.servicetag = "%s:%s:calendar" % (recordguid, hostguid,)
+    
+    def setup(self):
+        self._lookupVHostRecord()
+
+        for recordType in self.recordTypes():
+            self.recordsForType(recordType)
+        
     def recordTypes(self):
         return (
             DirectoryService.recordType_users,

Added: CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/test/test_opendirectoryschema.py
===================================================================
--- CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/test/test_opendirectoryschema.py	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/od-schema-1044/twistedcaldav/directory/test/test_opendirectoryschema.py	2007-01-17 16:27:13 UTC (rev 1055)
@@ -0,0 +1,578 @@
+##
+# Copyright (c) 2005-2007 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: Wilfredo Sanchez, wsanchez at apple.com
+##
+
+try:
+    from twistedcaldav.directory.appleopendirectory import OpenDirectoryService
+    from twistedcaldav.directory.appleopendirectory import OpenDirectoryInitError
+except ImportError:
+    pass
+else:
+    import twisted.trial.unittest
+
+    class PlistParse (twisted.trial.unittest.TestCase):
+        """
+        Test Open Directory service schema.
+        """
+        
+        plist_nomacosxserver_key = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+    </dict>
+</plist>
+"""
+
+        plist_nocalendarservice = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+
+        <key>com.apple.macosxserver.virtualhosts</key>
+        <dict>
+            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
+            <dict>
+                <key>hostname</key>
+                <string>foo.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>80</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>wiki</string>
+                    <string>webCalendar</string>
+                    <string>webMailingList</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                    <key>wiki</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/wiki</string>
+                    </dict>
+                    <key>webMailingList</key>
+                    <dict>
+                        <key>enabled</key>
+                        <true/>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/mailinglist</string>
+                    </dict>
+                </dict>
+            </dict>
+
+        </dict>
+    </dict>
+</plist>
+"""
+
+        plist_noserviceinfo = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+
+        <key>com.apple.macosxserver.virtualhosts</key>
+        <dict>
+            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
+            <dict>
+                <key>hostname</key>
+                <string>foo.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>80</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>wiki</string>
+                    <string>webCalendar</string>
+                    <string>webMailingList</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                    <key>wiki</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/wiki</string>
+                    </dict>
+                    <key>webMailingList</key>
+                    <dict>
+                        <key>enabled</key>
+                        <true/>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/mailinglist</string>
+                    </dict>
+                </dict>
+            </dict>
+            
+            <key>C18C34AC-3D9E-403C-8A33-BFC303F3840E</key>
+            <dict>
+                <key>hostname</key>
+                <string>calendar.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8008</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>calendar</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                </dict>
+            </dict>
+
+        </dict>
+    </dict>
+</plist>
+"""
+
+        plist_disabledservice = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+
+        <key>com.apple.macosxserver.virtualhosts</key>
+        <dict>
+            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
+            <dict>
+                <key>hostname</key>
+                <string>foo.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>80</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>wiki</string>
+                    <string>webCalendar</string>
+                    <string>webMailingList</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                    <key>wiki</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/wiki</string>
+                    </dict>
+                    <key>webMailingList</key>
+                    <dict>
+                        <key>enabled</key>
+                        <true/>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/mailinglist</string>
+                    </dict>
+                </dict>
+            </dict>
+            
+            <key>C18C34AC-3D9E-403C-8A33-BFC303F3840E</key>
+            <dict>
+                <key>hostname</key>
+                <string>calendar.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8008</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>calendar</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>calendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>NO</string>
+                        <key>templates</key>
+                        <dict>
+                            <key>principalPath</key>
+                            <string>/principals/%(type)s/%(name)s</string>
+                            <key>calendarUserAddresses</key>
+                            <array>
+                                <string>%(principal URI)s</string>
+                                <string>mailto:%(email)s</string>
+                                <string>urn:uuid:%(guid)s</string>
+                            </array>
+                        </dict>
+                    </dict>
+                </dict>
+            </dict>
+
+        </dict>
+    </dict>
+</plist>
+"""
+
+        plist_nocuaddrtemplates = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+
+        <key>com.apple.macosxserver.virtualhosts</key>
+        <dict>
+            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
+            <dict>
+                <key>hostname</key>
+                <string>foo.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>80</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>wiki</string>
+                    <string>webCalendar</string>
+                    <string>webMailingList</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                    <key>wiki</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/wiki</string>
+                    </dict>
+                    <key>webMailingList</key>
+                    <dict>
+                        <key>enabled</key>
+                        <true/>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/mailinglist</string>
+                    </dict>
+                </dict>
+            </dict>
+            
+            <key>C18C34AC-3D9E-403C-8A33-BFC303F3840E</key>
+            <dict>
+                <key>hostname</key>
+                <string>calendar.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8008</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>calendar</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>calendar</key>
+                    <dict>
+                        <key>templates</key>
+                        <dict>
+                            <key>principalPath</key>
+                            <string>/principals/%(type)s/%(name)s</string>
+                        </dict>
+                    </dict>
+                </dict>
+            </dict>
+
+        </dict>
+    </dict>
+</plist>
+"""
+
+        plist_good = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>ReplicaName</key>
+        <string>Master</string>
+
+        <key>com.apple.od.role</key>
+        <string>master</string>
+
+        <key>com.apple.macosxserver.virtualhosts</key>
+        <dict>
+            <key>4F088107-51FD-4DE5-904D-2C0AD9C6C893</key>
+            <dict>
+                <key>hostname</key>
+                <string>foo.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>80</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>wiki</string>
+                    <string>webCalendar</string>
+                    <string>webMailingList</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>webCalendar</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/webcalendar</string>
+                    </dict>
+                    <key>wiki</key>
+                    <dict>
+                        <key>enabled</key>
+                        <string>YES</string>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/wiki</string>
+                    </dict>
+                    <key>webMailingList</key>
+                    <dict>
+                        <key>enabled</key>
+                        <true/>
+                        <key>urlMask</key>
+                        <string>%(scheme)s://%(hostname)s:%(port)s/groups/%(groupname)s/mailinglist</string>
+                    </dict>
+                </dict>
+            </dict>
+            
+            <key>C18C34AC-3D9E-403C-8A33-BFC303F3840E</key>
+            <dict>
+                <key>hostname</key>
+                <string>calendar.apple.com</string>
+
+                <key>hostDetails</key>
+                <dict>
+                    <key>http</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8008</string>
+                    </dict>
+                    <key>https</key>
+                    <dict>
+                        <key>port</key>
+                        <string>8443</string>
+                    </dict>
+                </dict>
+
+                <key>serviceType</key>
+                <array>
+                    <string>calendar</string>
+                </array>
+
+                <key>serviceInfo</key>
+                <dict>
+                    <key>calendar</key>
+                    <dict>
+                        <key>templates</key>
+                        <dict>
+                            <key>principalPath</key>
+                            <string>/principals/%(type)s/%(name)s</string>
+                            <key>calendarUserAddresses</key>
+                            <array>
+                                <string>%(principal URI)s</string>
+                                <string>mailto:%(email)s</string>
+                                <string>urn:uuid:%(guid)s</string>
+                            </array>
+                        </dict>
+                    </dict>
+                </dict>
+            </dict>
+
+        </dict>
+    </dict>
+</plist>
+"""
+
+        def test_plist_errors(self):
+            def _doParse(plist, title):
+                service = OpenDirectoryService(node="/Search", dosetup=False)
+                try:
+                    service._parseXMLPlist(plist, "GUIDIFY")
+                    self.fail(msg="Plist parse should have failed: %s" % (title,))
+                except OpenDirectoryInitError:
+                    pass
+                
+            plists = (
+                (PlistParse.plist_nomacosxserver_key, "nomacosxserver_key"),
+                (PlistParse.plist_nocalendarservice,  "nocalendarservice"),
+                (PlistParse.plist_noserviceinfo,      "noserviceinfo"),
+                (PlistParse.plist_disabledservice,    "disabledservice"),
+                (PlistParse.plist_nocuaddrtemplates,  "nocuaddrtemplates"),
+            )
+            for plist, title in plists:
+                _doParse(plist, title)
+
+        def test_goodplist(self):
+            service = OpenDirectoryService(node="/Search", dosetup=False)
+            service._parseXMLPlist(PlistParse.plist_good, "GUIDIFY")
+            
+            # Verify that we extracted the proper items
+            self.assertEqual(service.servicetag, "GUIDIFY:C18C34AC-3D9E-403C-8A33-BFC303F3840E:calendar")
+            self.assertEqual(service.cuaddrtemplates, ["%(principal URI)s", "mailto:%(email)s", "urn:uuid:%(guid)s"])
+            
+            
\ No newline at end of file

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070117/8e8afc5a/attachment.html


More information about the calendarserver-changes mailing list