Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpcbind_test.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
# Test for -rpcbind, as well as -rpcallowip and -rpcconnect | # Test for -rpcbind, as well as -rpcallowip and -rpcconnect | ||||
import socket | |||||
import sys | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.netutil import * | from test_framework.netutil import * | ||||
class RPCBindTest(BitcoinTestFramework): | class RPCBindTest(BitcoinTestFramework): | ||||
def __init__(self): | def __init__(self): | ||||
Show All 34 Lines | def run_allowip_test(self, allow_ips, rpchost, rpcport): | ||||
self.nodes = start_nodes( | self.nodes = start_nodes( | ||||
self.num_nodes, self.options.tmpdir, [base_args]) | self.num_nodes, self.options.tmpdir, [base_args]) | ||||
# connect to node through non-loopback interface | # connect to node through non-loopback interface | ||||
node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0) | node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0) | ||||
node.getnetworkinfo() | node.getnetworkinfo() | ||||
stop_nodes(self.nodes) | stop_nodes(self.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 Linux | ||||
# Linux | if not sys.platform.startswith('linux'): | ||||
assert(sys.platform.startswith('linux')) | self.log.warning( | ||||
"This test can only be run on linux. Skipping test.") | |||||
sys.exit(self.TEST_EXIT_SKIPPED) | |||||
# find the first non-loopback interface for testing | # find the first non-loopback interface for testing | ||||
non_loopback_ip = None | non_loopback_ip = None | ||||
for name, ip in all_interfaces(): | for name, ip in all_interfaces(): | ||||
if ip != '127.0.0.1': | if ip != '127.0.0.1': | ||||
non_loopback_ip = ip | non_loopback_ip = ip | ||||
break | break | ||||
if non_loopback_ip is None: | if non_loopback_ip is None: | ||||
assert( | self.log.warning( | ||||
not 'This test requires at least one non-loopback IPv4 interface') | "This test requires at least one non-loopback IPv4 interface. Skipping test.") | ||||
sys.exit(self.TEST_EXIT_SKIPPED) | |||||
try: | |||||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) | |||||
s.connect(("::1", 1)) | |||||
s.close | |||||
except OSError: | |||||
self.log.warning("This test requires IPv6 support. Skipping test.") | |||||
sys.exit(self.TEST_EXIT_SKIPPED) | |||||
self.log.info("Using interface %s for testing" % non_loopback_ip) | self.log.info("Using interface %s for testing" % 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 (IPv6 any) | ||||
Show All 34 Lines |