[CalendarServer-changes] [7084] CalendarServer/trunk/contrib/migration

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 25 13:06:10 PST 2011


Revision: 7084
          http://trac.macosforge.org/projects/calendarserver/changeset/7084
Author:   sagen at apple.com
Date:     2011-02-25 13:06:10 -0800 (Fri, 25 Feb 2011)
Log Message:
-----------
Migrate previous CalDAV/CardDAV SSL+Port settings together

Modified Paths:
--------------
    CalendarServer/trunk/contrib/migration/calendarmigrator.py

Added Paths:
-----------
    CalendarServer/trunk/contrib/migration/test/
    CalendarServer/trunk/contrib/migration/test/__init__.py
    CalendarServer/trunk/contrib/migration/test/test_migrator.py

Modified: CalendarServer/trunk/contrib/migration/calendarmigrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/calendarmigrator.py	2011-02-25 20:57:06 UTC (rev 7083)
+++ CalendarServer/trunk/contrib/migration/calendarmigrator.py	2011-02-25 21:06:10 UTC (rev 7084)
@@ -152,6 +152,7 @@
 MaxAddressBookMultigetHrefs
 MaxAddressBookQueryResults
 RedirectHTTPToHTTPS
+SSLPort
 """.split()
 
 ignoredKkeys = """
@@ -163,7 +164,6 @@
 PythonDirector
 ResponseCacheTimeout
 SSLPassPhraseDialog
-SSLPort
 ServerStatsFile
 Verbose
 """.split()
@@ -383,30 +383,62 @@
     writePlist(newCalDAVDPlist, newCalDAVDPlistPath)
 
 
-def mergePlist(oldCalDAVDPlist, oldCardDAVDPlist, newCalDAVDPlist):
+def mergePlist(caldav, carddav, combined):
 
     # These keys are copied verbatim:
     for key in verbatimKeys:
-        if key in oldCardDAVDPlist:
-            newCalDAVDPlist[key] = oldCardDAVDPlist[key]
-        if key in oldCalDAVDPlist:
-            newCalDAVDPlist[key] = oldCalDAVDPlist[key]
+        if key in carddav:
+            combined[key] = carddav[key]
+        if key in caldav:
+            combined[key] = caldav[key]
 
     # "Wiki" is a new authentication in v2.x; copy all "Authentication" sub-keys    # over, and "Wiki" will be picked up from the new plist:
-    if "Authentication" in oldCalDAVDPlist:
-        for key in oldCalDAVDPlist["Authentication"]:
-            newCalDAVDPlist["Authentication"][key] = oldCalDAVDPlist["Authentication"][key]
+    if "Authentication" in caldav:
+        for key in caldav["Authentication"]:
+            combined["Authentication"][key] = caldav["Authentication"][key]
 
     # Strip out any unknown params from the DirectoryService:
-    if "DirectoryService" in oldCalDAVDPlist:
-        newCalDAVDPlist["DirectoryService"] = oldCalDAVDPlist["DirectoryService"]
-        for key in newCalDAVDPlist["DirectoryService"]["params"].keys():
+    if "DirectoryService" in caldav:
+        combined["DirectoryService"] = caldav["DirectoryService"]
+        for key in combined["DirectoryService"]["params"].keys():
             if key not in ("node", "cacheTimeout", "xmlFile"):
-                del newCalDAVDPlist["DirectoryService"]["params"][key]
+                del combined["DirectoryService"]["params"][key]
 
+    # Merge ports
+    if not caldav["SSLPort"]:
+        caldav["SSLPort"] = 8443
+    if not carddav["SSLPort"]:
+        carddav["SSLPort"] = 8843
+    for portType in ["HTTPPort", "SSLPort"]:
+        bindPorts = list(set(caldav["Bind%ss" % (portType,)]).union(set(carddav["Bind%ss" % (portType,)])))
+        if caldav[portType] and caldav[portType] not in bindPorts:
+            bindPorts.append(caldav[portType])
+        if carddav[portType] and carddav[portType] not in bindPorts:
+            bindPorts.append(carddav[portType])
+        bindPorts.sort()
+        combined["Bind%ss" % (portType,)] = bindPorts
+    combined["HTTPPort"] = caldav["HTTPPort"]
+    combined["SSLPort"] = caldav["SSLPort"]
+
+    # Was SSL enabled?
+    sslAuthorityChain = ""
+    sslCertificate = ""
+    sslPrivateKey = ""
+    enableSSL = False
+    for prev in (carddav, caldav):
+        if (prev["SSLPort"] and prev["SSLCertificate"]):
+            sslAuthorityChain = prev["SSLAuthorityChain"]
+            sslCertificate = prev["SSLCertificate"]
+            sslPrivateKey = prev["SSLPrivateKey"]
+            enableSSL = True
+
+    combined["SSLAuthorityChain"] = sslAuthorityChain
+    combined["SSLCertificate"] = sslCertificate
+    combined["SSLPrivateKey"] = sslPrivateKey
+    combined["EnableSSL"] = enableSSL
+
     # If SSL is enabled, redirect HTTP to HTTPS.
-    enableSSL = newCalDAVDPlist.get("EnableSSL", False)
-    newCalDAVDPlist["RedirectHTTPToHTTPS"] = enableSSL
+    combined["RedirectHTTPToHTTPS"] = enableSSL
 
 
 def isServiceDisabled(source, service):

Added: CalendarServer/trunk/contrib/migration/test/__init__.py
===================================================================
--- CalendarServer/trunk/contrib/migration/test/__init__.py	                        (rev 0)
+++ CalendarServer/trunk/contrib/migration/test/__init__.py	2011-02-25 21:06:10 UTC (rev 7084)
@@ -0,0 +1,20 @@
+# -*- test-case-name: twistedcaldav.test -*-
+##
+# 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.
+##
+
+"""
+Tests for the twistedcaldav module.
+"""

Added: CalendarServer/trunk/contrib/migration/test/test_migrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/test/test_migrator.py	                        (rev 0)
+++ CalendarServer/trunk/contrib/migration/test/test_migrator.py	2011-02-25 21:06:10 UTC (rev 7084)
@@ -0,0 +1,208 @@
+##
+# Copyright (c) 2011 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.
+##
+
+import twistedcaldav.test.util
+from contrib.migration.calendarmigrator import mergePlist
+
+class MigrationTests(twistedcaldav.test.util.TestCase):
+    """
+    Calendar Server Migration Tests
+    """
+
+    def test_mergeSSL(self):
+
+        # SSL on for both services
+        oldCalDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        oldCardDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8800,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8843,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        expected = {
+            "BindHTTPPorts": [8008, 8800],
+            "BindSSLPorts": [8443, 8843],
+            "EnableSSL" : True,
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        newCombined = { }
+        mergePlist(oldCalDAV, oldCardDAV, newCombined)
+        self.assertEquals(newCombined, expected)
+
+        # SSL off for both services
+        oldCalDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "",
+            "SSLCertificate": "",
+            "SSLPort": 0,
+            "SSLPrivateKey": "",
+        }
+        oldCardDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8800,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "",
+            "SSLCertificate": "",
+            "SSLPort": 0,
+            "SSLPrivateKey": "",
+        }
+        expected = {
+            "BindHTTPPorts": [8008, 8800],
+            "BindSSLPorts": [8443, 8843],
+            "EnableSSL" : False,
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "",
+            "SSLCertificate": "",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "",
+        }
+        newCombined = { }
+        mergePlist(oldCalDAV, oldCardDAV, newCombined)
+        self.assertEquals(newCombined, expected)
+
+        # SSL on for only caldav
+        oldCalDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        oldCardDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8800,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "",
+            "SSLCertificate": "",
+            "SSLPort": 0,
+            "SSLPrivateKey": "",
+        }
+        expected = {
+            "BindHTTPPorts": [8008, 8800],
+            "BindSSLPorts": [8443, 8843],
+            "EnableSSL" : True,
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        newCombined = { }
+        mergePlist(oldCalDAV, oldCardDAV, newCombined)
+        self.assertEquals(newCombined, expected)
+
+        # SSL on for only carddav
+        oldCalDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "",
+            "SSLCertificate": "",
+            "SSLPort": 0,
+            "SSLPrivateKey": "",
+        }
+        oldCardDAV = {
+            "BindHTTPPorts": [],
+            "BindSSLPorts": [],
+            "HTTPPort": 8800,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8843,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        expected = {
+            "BindHTTPPorts": [8008, 8800],
+            "BindSSLPorts": [8443, 8843],
+            "EnableSSL" : True,
+            "HTTPPort": 8008,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 8443,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        newCombined = { }
+        mergePlist(oldCalDAV, oldCardDAV, newCombined)
+        self.assertEquals(newCombined, expected)
+
+        # Non standard ports
+        oldCalDAV = {
+            "BindHTTPPorts": [1111, 2222],
+            "BindSSLPorts": [3333],
+            "HTTPPort": 8888,
+            "RedirectHTTPToHTTPS": False,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 9999,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        oldCardDAV = {
+            "BindHTTPPorts": [4444, 5555],
+            "BindSSLPorts": [6666],
+            "HTTPPort": 7777,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 11111,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        expected = {
+            "BindHTTPPorts": [1111, 2222, 4444, 5555, 7777, 8888],
+            "BindSSLPorts": [3333, 6666, 9999, 11111],
+            "EnableSSL" : True,
+            "HTTPPort": 8888,
+            "RedirectHTTPToHTTPS": True,
+            "SSLAuthorityChain": "/etc/certificates/test.chain.pem",
+            "SSLCertificate": "/etc/certificates/test.cert.pem",
+            "SSLPort": 9999,
+            "SSLPrivateKey": "/etc/certificates/test.key.pem",
+        }
+        newCombined = { }
+        mergePlist(oldCalDAV, oldCardDAV, newCombined)
+        self.assertEquals(newCombined, expected)
+
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110225/48bc573c/attachment-0001.html>


More information about the calendarserver-changes mailing list