# HG changeset patch # User Ralph Meijer # Date 1381140894 -7200 # Node ID 6641ea7990eeca1f52a0ffeb5979e7db6587c226 # Parent 6ba0d6def7f5ae7e3d6058978a417ed1ce27462f Fix checking for malformed XMPP URI in DeleteResource. diff -r 6ba0d6def7f5 -r 6641ea7990ee sat_pubsub/gateway.py --- 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 diff -r 6ba0d6def7f5 -r 6641ea7990ee sat_pubsub/test/test_gateway.py --- 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}.