Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_bind.py
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | def run_bind_test(self, allow_ips, connect_to, addresses, expected): | ||||
self.stop_nodes() | self.stop_nodes() | ||||
def run_allowip_test(self, allow_ips, rpchost, rpcport): | def run_allowip_test(self, allow_ips, rpchost, rpcport): | ||||
''' | ''' | ||||
Start a node with rpcallow IP, and request getnetworkinfo | Start a node with rpcallow IP, and request getnetworkinfo | ||||
at a non-localhost IP. | at a non-localhost IP. | ||||
''' | ''' | ||||
self.log.info("Allow IP test for {}:{}".format(rpchost, rpcport)) | self.log.info("Allow IP test for {}:{}".format(rpchost, rpcport)) | ||||
base_args = ['-disablewallet', '-nolisten'] + \ | node_args = \ | ||||
['-rpcallowip=' + x for x in allow_ips] | ['-disablewallet', '-nolisten'] + \ | ||||
['-rpcallowip=' + x for x in allow_ips] + \ | |||||
['-rpcbind=' + addr for addr in ['127.0.0.1', | |||||
"{}:{}".format(rpchost, | |||||
rpcport)]] # Bind to localhost as well so start_nodes doesn't hang | |||||
self.nodes[0].host = None | self.nodes[0].host = None | ||||
self.start_nodes([base_args]) | self.start_nodes([node_args]) | ||||
# connect to node through non-loopback interface | # connect to node through non-loopback interface | ||||
url = rpc_url(self.nodes[0].datadir, rpchost, rpcport) | url = rpc_url(self.nodes[0].datadir, rpchost, rpcport) | ||||
node = get_rpc_proxy(url, 0, coveragedir=self.options.coveragedir) | node = get_rpc_proxy(url, 0, coveragedir=self.options.coveragedir) | ||||
node.getnetworkinfo() | node.getnetworkinfo() | ||||
self.stop_nodes() | self.stop_nodes() | ||||
def run_test(self): | def run_test(self): | ||||
# due to OS-specific network stats queries, this test works only on | # due to OS-specific network stats queries, this test works only on | ||||
Show All 27 Lines | def run_test(self): | ||||
self.log.info("Using interface {} for testing".format(non_loopback_ip)) | self.log.info("Using interface {} for testing".format(non_loopback_ip)) | ||||
defaultport = rpc_port(0) | defaultport = rpc_port(0) | ||||
# check default without rpcallowip (IPv4 and IPv6 localhost) | # check default without rpcallowip (IPv4 and IPv6 localhost) | ||||
self.run_bind_test(None, '127.0.0.1', [], | self.run_bind_test(None, '127.0.0.1', [], | ||||
[('127.0.0.1', defaultport), ('::1', defaultport)]) | [('127.0.0.1', defaultport), ('::1', defaultport)]) | ||||
# check default with rpcallowip (IPv6 any) | # check default with rpcallowip (IPv4 and IPv6 localhost) | ||||
self.run_bind_test(['127.0.0.1'], '127.0.0.1', [], | self.run_bind_test(['127.0.0.1'], '127.0.0.1', [], | ||||
[('::0', defaultport)]) | [('127.0.0.1', defaultport), ('::1', defaultport)]) | ||||
# check only IPv4 localhost (explicit) | # check only IPv4 localhost (explicit) | ||||
self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'], | self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'], | ||||
[('127.0.0.1', defaultport)]) | [('127.0.0.1', defaultport)]) | ||||
# check only IPv4 localhost (explicit) with alternative port | # check only IPv4 localhost (explicit) with alternative port | ||||
self.run_bind_test( | self.run_bind_test( | ||||
['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'], | ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'], | ||||
[('127.0.0.1', 32171)]) | [('127.0.0.1', 32171)]) | ||||
# check only IPv4 localhost (explicit) with multiple alternative ports | # check only IPv4 localhost (explicit) with multiple alternative ports | ||||
Show All 24 Lines |