Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit fda3e0e4f1d2a365e0e390bd783fe7d75619d25b 1 parent 899c087
Chris Allan chris-allan authored committed

Showing 2 changed files with 20 additions and 4 deletions. Show diff stats Hide diff stats

  1. +13 2 tests/xml.py
  2. +7 2 tornadorpc/base.py
15 tests/xml.py
... ... @@ -1,5 +1,6 @@
1 1 import unittest
2 2 import xmlrpclib
  3 +import urllib2
3 4 import time
4 5 import threading
5 6 from tornadorpc.xml import XMLRPCHandler
@@ -73,9 +74,12 @@ class RPCTests(object):
73 74
74 75 def setUp(self):
75 76 server = TestServer.start(self.handler, self.port)
76   -
  77 +
  78 + def get_url(self):
  79 + return 'http://localhost:%d' % self.port
  80 +
77 81 def get_client(self):
78   - client = xmlrpclib.ServerProxy('http://localhost:%d' % self.port)
  82 + client = xmlrpclib.ServerProxy(self.get_url())
79 83 return client
80 84
81 85 def test_tree(self):
@@ -128,6 +132,13 @@ def test_internal_error(self):
128 132 except xmlrpclib.Fault, f:
129 133 self.assertEqual(-32603, f.faultCode)
130 134
  135 + def test_parse_error(self):
  136 + try:
  137 + print self.get_url()
  138 + urllib2.urlopen(self.get_url(), '<garbage/>')
  139 + except xmlrpclib.Fault, f:
  140 + self.assertEqual(-32700, f.faultCode)
  141 +
131 142 def test_handler_return_fault(self):
132 143 client = self.get_client()
133 144 fault_code = 100
9 tornadorpc/base.py
@@ -79,16 +79,21 @@ def run(self, handler, request_body):
79 79 requests = self.parse_request(request_body)
80 80 except:
81 81 self.traceback()
82   - return self.faults.parse_error()
  82 + return self.handler.result(self.faults.parse_error())
83 83 if type(requests) is not types.TupleType:
84 84 # SHOULD be the result of a fault call,
85 85 # according tothe parse_request spec below.
86 86 if type(requests) in types.StringTypes:
87 87 # Should be the response text of a fault
88 88 return requests
89   - elif 'response' in dir(requests):
  89 + elif hasattr(requests, 'response'):
90 90 # Fault types should have a 'response' method
91 91 return requests.response()
  92 + elif hasattr(requests, 'faultCode'):
  93 + # XML-RPC fault types need to be properly dispatched. This
  94 + # should only happen if there was an error parsing the
  95 + # request above.
  96 + return self.handler.result(requests)
92 97 else:
93 98 # No idea, hopefully the handler knows what it
94 99 # is doing.

0 comments on commit fda3e0e

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