changeset 274:6641ea7990ee

Fix checking for malformed XMPP URI in DeleteResource.
author Ralph Meijer <ralphm@ik.nu>
date Mon, 07 Oct 2013 12:14:54 +0200
parents 6ba0d6def7f5
children 9c74cd2635f6
files sat_pubsub/gateway.py sat_pubsub/test/test_gateway.py
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/gateway.py	Sun Jan 20 13:38:41 2013 +0100
+++ b/sat_pubsub/gateway.py	Mon Oct 07 12:14:54 2013 +0200
@@ -238,15 +238,14 @@
             failure.trap(error.NodeNotFound)
             raise Error(http.NOT_FOUND, "Node not found")
 
-        def trapXMPPURIParseError(failure):
-            failure.trap(XMPPURIParseError)
-            raise Error(http.BAD_REQUEST,
-                        "Malformed XMPP URI: %s" % failure.value)
-
         if not request.args.get('uri'):
             raise Error(http.BAD_REQUEST, "No URI given")
 
-        jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0])
+        try:
+            jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0])
+        except XMPPURIParseError, e:
+            raise Error(http.BAD_REQUEST, "Malformed XMPP URI: %s" % e)
+
 
         data = request.content.read()
         if data:
@@ -259,7 +258,6 @@
                                     redirectURI)
         d.addCallback(toResponse)
         d.addErrback(trapNotFound)
-        d.addErrback(trapXMPPURIParseError)
         return d
 
 
--- a/sat_pubsub/test/test_gateway.py	Sun Jan 20 13:38:41 2013 +0100
+++ b/sat_pubsub/test/test_gateway.py	Mon Oct 07 12:14:54 2013 +0200
@@ -347,6 +347,25 @@
         return d
 
 
+    def test_postMalformedXMPPURI(self):
+        """
+        If the XMPP URI is malformed, Bad Request is returned.
+        """
+        request = DummyRequest([b''])
+        request.method = b'POST'
+
+        def rendered(result):
+            self.assertEqual(http.BAD_REQUEST, request.responseCode)
+
+        uri = 'xmpp:@@@@'
+        request.args[b'uri'] = [uri]
+        request.content = StringIO(b'')
+
+        d = _render(self.resource, request)
+        d.addCallback(rendered)
+        return d
+
+
     def test_postURIMissing(self):
         """
         If no URI is passed, 400 Bad Request is returned.
@@ -364,6 +383,7 @@
         return d
 
 
+
 class CallbackResourceTest(unittest.TestCase):
     """
     Tests for L{gateway.CallbackResource}.