[CalendarServer-changes] [7414] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu May 5 10:45:32 PDT 2011


Revision: 7414
          http://trac.macosforge.org/projects/calendarserver/changeset/7414
Author:   sagen at apple.com
Date:     2011-05-05 10:45:32 -0700 (Thu, 05 May 2011)
Log Message:
-----------
If we're configured for push but can't actually communicate with the XMPP server, return 404 for the push-related DAV properties instead of empty values. 9355478

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/twistedcaldav/test/test_resource.py

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2011-05-04 20:16:35 UTC (rev 7413)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2011-05-05 17:45:32 UTC (rev 7414)
@@ -2262,18 +2262,15 @@
                             )
 
                         returnValue(customxml.PubSubPushTransportsProperty(*children))
+            returnValue(None)
 
-
-            returnValue(customxml.PubSubPushTransportsProperty())
-
         elif qname == (customxml.calendarserver_namespace, "pushkey"):
             if config.Notifications.Services.XMPPNotifier.Enabled:
                 nodeName = (yield self._newStoreHome.nodeName())
                 if nodeName:
                     returnValue(customxml.PubSubXMPPPushKeyProperty(nodeName))
-            returnValue(customxml.PubSubXMPPPushKeyProperty())
+            returnValue(None)
 
-
         elif qname == (customxml.calendarserver_namespace, "xmpp-uri"):
             if config.Notifications.Services.XMPPNotifier.Enabled:
                 nodeName = (yield self._newStoreHome.nodeName())
@@ -2284,29 +2281,40 @@
                         returnValue(customxml.PubSubXMPPURIProperty(
                             getPubSubXMPPURI(notifierID, pubSubConfiguration)))
 
-            returnValue(customxml.PubSubXMPPURIProperty())
+            returnValue(None)
 
         elif qname == (customxml.calendarserver_namespace, "xmpp-heartbeat-uri"):
             if config.Notifications.Services.XMPPNotifier.Enabled:
-                pubSubConfiguration = getPubSubConfiguration(config)
-                returnValue(
-                    customxml.PubSubHeartbeatProperty(
-                        customxml.PubSubHeartbeatURIProperty(
-                            getPubSubHeartbeatURI(pubSubConfiguration)
-                        ),
-                        customxml.PubSubHeartbeatMinutesProperty(
-                            str(pubSubConfiguration['heartrate'])
+                # Look up node name not because we want to return it, but
+                # to see if XMPP server is actually responding.  If it comes
+                # back with an empty nodeName, don't advertise
+                # xmpp-heartbeat-uri
+                nodeName = (yield self._newStoreHome.nodeName())
+                if nodeName:
+                    pubSubConfiguration = getPubSubConfiguration(config)
+                    returnValue(
+                        customxml.PubSubHeartbeatProperty(
+                            customxml.PubSubHeartbeatURIProperty(
+                                getPubSubHeartbeatURI(pubSubConfiguration)
+                            ),
+                            customxml.PubSubHeartbeatMinutesProperty(
+                                str(pubSubConfiguration['heartrate'])
+                            )
                         )
                     )
-                )
-            returnValue(customxml.PubSubHeartbeatURIProperty())
+            returnValue(None)
 
         elif qname == (customxml.calendarserver_namespace, "xmpp-server"):
             if config.Notifications.Services.XMPPNotifier.Enabled:
-                pubSubConfiguration = getPubSubConfiguration(config)
-                returnValue(customxml.PubSubXMPPServerProperty(
-                    pubSubConfiguration['xmpp-server']))
-            returnValue(customxml.PubSubXMPPServerProperty())
+                # Look up node name not because we want to return it, but
+                # to see if XMPP server is actually responding.  If it comes
+                # back with an empty nodeName, don't advertise xmpp-server
+                nodeName = (yield self._newStoreHome.nodeName())
+                if nodeName:
+                    pubSubConfiguration = getPubSubConfiguration(config)
+                    returnValue(customxml.PubSubXMPPServerProperty(
+                        pubSubConfiguration['xmpp-server']))
+            returnValue(None)
 
         returnValue((yield super(CommonHomeResource, self).readProperty(property, request)))
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_resource.py	2011-05-04 20:16:35 UTC (rev 7413)
+++ CalendarServer/trunk/twistedcaldav/test/test_resource.py	2011-05-05 17:45:32 UTC (rev 7414)
@@ -18,8 +18,11 @@
 
 from twistedcaldav.test.util import InMemoryPropertyStore
 from twistedcaldav.test.util import TestCase
+from twistedcaldav.config import config
 
+from twisted.internet.defer import inlineCallbacks
 
+
 class StubProperty(object):
     def qname(self):
         return "StubQnamespace", "StubQname"
@@ -31,7 +34,15 @@
     def addNotifier(self, notifier):
         pass
 
+    def nodeName(self):
+        return "xyzzy" if self.pushWorking else None
 
+    def notifierID(self):
+        return "xyzzy"
+
+    def setPushWorking(self, status):
+        self.pushWorking = status
+
 class CalDAVResourceTests(TestCase):
     def setUp(self):
         TestCase.setUp(self)
@@ -66,3 +77,43 @@
         self.assertTrue(('http://calendarserver.org/ns/', 'xmpp-uri') not in resource.liveProperties())
         self.assertTrue(('http://calendarserver.org/ns/', 'xmpp-heartbeat-uri') not in resource.liveProperties())
         self.assertTrue(('http://calendarserver.org/ns/', 'xmpp-server') not in resource.liveProperties())
+
+    @inlineCallbacks
+    def test_push404(self):
+        """
+        If push is configured, yet we can't communicate with the XMPP server
+        for whatever reason, readProperty on the various push-related properties
+        should return None
+        """
+        resource = CalendarHomeResource(None, None, None, StubHome())
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'push-transports'), None)), None)
+
+        self.patch(config, "ServerHostName", "cal.example.com")
+        self.patch(config, "SSLPort", 8443)
+        self.patch(config.Notifications, "Enabled", True)
+        self.patch(config.Notifications.Services, "XMPPNotifier", 
+            {
+                "Enabled" : True,
+                "Host" : "xmpp.example.com",
+                "Port" : 5218,
+                "ServiceAddress" : "pubsub.xmpp.example.com",
+                "Service" : "twistedcaldav.notify.XMPPNotifierService",
+                "HeartbeatMinutes" : 30,
+            }
+        )
+
+        # Verify that when push is "working" we get a value
+        resource._newStoreHome.setPushWorking(True)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'push-transports'), None)).toxml(), "<?xml version='1.0' encoding='UTF-8'?>\n<push-transports xmlns='http://calendarserver.org/ns/'>\r\n  <transport type='XMPP'>\r\n    <xmpp-server>xmpp.example.com:5218</xmpp-server>\r\n    <xmpp-uri>xmpp:pubsub.xmpp.example.com?pubsub;node=/cal.example.com/xyzzy/</xmpp-uri>\r\n  </transport>\r\n</push-transports>")
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'pushkey'), None)).toxml(), "<?xml version='1.0' encoding='UTF-8'?>\n<pushkey xmlns='http://calendarserver.org/ns/'>xyzzy</pushkey>")
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-uri'), None)).toxml(), "<?xml version='1.0' encoding='UTF-8'?>\n<xmpp-uri xmlns='http://calendarserver.org/ns/'>xmpp:pubsub.xmpp.example.com?pubsub;node=/cal.example.com/xyzzy/</xmpp-uri>")
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-heartbeat-uri'), None)).toxml(), "<?xml version='1.0' encoding='UTF-8'?>\n<xmpp-heartbeat xmlns='http://calendarserver.org/ns/'>\r\n  <xmpp-heartbeat-uri>xmpp:pubsub.xmpp.example.com?pubsub;node=/cal.example.com/</xmpp-heartbeat-uri>\r\n  <xmpp-heartbeat-minutes>30</xmpp-heartbeat-minutes>\r\n</xmpp-heartbeat>")
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-server'), None)).toxml(), "<?xml version='1.0' encoding='UTF-8'?>\n<xmpp-server xmlns='http://calendarserver.org/ns/'>xmpp.example.com:5218</xmpp-server>")
+
+        # Verify that when push is "not working" we get None
+        resource._newStoreHome.setPushWorking(False)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'push-transports'), None)), None)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'pushkey'), None)), None)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-uri'), None)), None)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-heartbeat-uri'), None)), None)
+        self.assertEqual((yield resource.readProperty(('http://calendarserver.org/ns/', 'xmpp-server'), None)), None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110505/d24838aa/attachment.html>


More information about the calendarserver-changes mailing list