Skip to content
Browse files

Added test case for parsing errors during XML-RPC request decode. Fixed

problems with XML-RPC dispatch after request parsing errors; the previous
implementation never dispatched a result causing clients to block until
their timeout and potential resource exhaustion in the server.
  • Loading branch information...
1 parent 899c087 commit fda3e0e4f1d2a365e0e390bd783fe7d75619d25b @chris-allan chris-allan committed with joshmarshall
Showing with 20 additions and 4 deletions.
  1. +13 −2 tests/xml.py
  2. +7 −2 tornadorpc/base.py
View
15 tests/xml.py
@@ -1,5 +1,6 @@
import unittest
import xmlrpclib
+import urllib2
import time
import threading
from tornadorpc.xml import XMLRPCHandler
@@ -73,9 +74,12 @@ class RPCTests(object):
def setUp(self):
server = TestServer.start(self.handler, self.port)
-
+
+ def get_url(self):
+ return 'http://localhost:%d' % self.port
+
def get_client(self):
- client = xmlrpclib.ServerProxy('http://localhost:%d' % self.port)
+ client = xmlrpclib.ServerProxy(self.get_url())
return client
def test_tree(self):
@@ -128,6 +132,13 @@ def test_internal_error(self):
except xmlrpclib.Fault, f:
self.assertEqual(-32603, f.faultCode)
+ def test_parse_error(self):
+ try:
+ print self.get_url()
+ urllib2.urlopen(self.get_url(), '<garbage/>')
+ except xmlrpclib.Fault, f:
+ self.assertEqual(-32700, f.faultCode)
+
def test_handler_return_fault(self):
client = self.get_client()
fault_code = 100
View
9 tornadorpc/base.py
@@ -79,16 +79,21 @@ def run(self, handler, request_body):
requests = self.parse_request(request_body)
except:
self.traceback()
- return self.faults.parse_error()
+ return self.handler.result(self.faults.parse_error())
if type(requests) is not types.TupleType:
# SHOULD be the result of a fault call,
# according tothe parse_request spec below.
if type(requests) in types.StringTypes:
# Should be the response text of a fault
return requests
- elif 'response' in dir(requests):
+ elif hasattr(requests, 'response'):
# Fault types should have a 'response' method
return requests.response()
+ elif hasattr(requests, 'faultCode'):
+ # XML-RPC fault types need to be properly dispatched. This
+ # should only happen if there was an error parsing the
+ # request above.
+ return self.handler.result(requests)
else:
# No idea, hopefully the handler knows what it
# is doing.

0 comments on commit fda3e0e

Please sign in to comment.
Something went wrong with that request. Please try again.