jsonrpc: Give explicit error if calling method without object path
This commit is contained in:
parent
8f604204da
commit
160626b364
@ -187,10 +187,12 @@ class JsonRpcWrapper(object):
|
||||
|
||||
# The mounted object contains the callable
|
||||
|
||||
if '.' in method_path:
|
||||
mount, method_name = method_path.rsplit('.', 1)
|
||||
else:
|
||||
mount, method_name = '', method_path
|
||||
if '.' not in method_path:
|
||||
raise JsonRpcMethodNotFoundError(
|
||||
data='Could not find object mount in method name "%s"' % (
|
||||
method_path))
|
||||
|
||||
mount, method_name = method_path.rsplit('.', 1)
|
||||
|
||||
if method_name.startswith('_'):
|
||||
raise JsonRpcMethodNotFoundError(
|
||||
|
||||
@ -387,6 +387,21 @@ class JsonRpcSingleCommandErrorTest(JsonRpcTestBase):
|
||||
self.assertEqual(
|
||||
error['data'], '"params", if given, must be an array or an object')
|
||||
|
||||
def test_method_on_without_object_causes_unknown_method_error(self):
|
||||
request = {
|
||||
'jsonrpc': '2.0',
|
||||
'method': 'bogus',
|
||||
'id': 1,
|
||||
}
|
||||
response = self.jrw.handle_data(request)
|
||||
|
||||
error = response['error']
|
||||
self.assertEqual(error['code'], -32601)
|
||||
self.assertEqual(error['message'], 'Method not found')
|
||||
self.assertEqual(
|
||||
error['data'],
|
||||
'Could not find object mount in method name "bogus"')
|
||||
|
||||
def test_method_on_unknown_object_causes_unknown_method_error(self):
|
||||
request = {
|
||||
'jsonrpc': '2.0',
|
||||
@ -417,7 +432,7 @@ class JsonRpcSingleCommandErrorTest(JsonRpcTestBase):
|
||||
def test_private_method_causes_unknown_method_error(self):
|
||||
request = {
|
||||
'jsonrpc': '2.0',
|
||||
'method': '_secret',
|
||||
'method': 'core._secret',
|
||||
'id': 1,
|
||||
}
|
||||
response = self.jrw.handle_data(request)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user