18 Start a node with requested rpcallowip and rpcbind parameters, 19 then try to connect, and check if the set of bound addresses 20 matches the expected set. 22 expected = [(
addr_to_hex(addr), port)
for (addr, port)
in expected]
23 base_args = [
'-disablewallet',
'-nolisten']
25 base_args += [
'-rpcallowip=' + x
for x
in allow_ips]
26 binds = [
'-rpcbind='+addr
for addr
in addresses]
27 nodes =
start_nodes(1, tmpdir, [base_args + binds], connect_to)
29 pid = bitcoind_processes[0].pid
37 Start a node with rpcwallow IP, and request getinfo 38 at a non-localhost IP. 40 base_args = [
'-disablewallet',
'-nolisten'] + [
'-rpcallowip='+x
for x
in allow_ips]
44 url =
"http://rt:rt@%s:%d" % (rpchost, rpcport,)
54 assert(sys.platform ==
'linux2')
56 non_loopback_ip =
None 61 if non_loopback_ip
is None:
62 assert(
not 'This test requires at least one non-loopback IPv4 interface')
63 print(
"Using interface %s for testing" % non_loopback_ip)
69 [(
'127.0.0.1', defaultport), (
'::1', defaultport)])
72 [(
'::0', defaultport)])
74 run_bind_test(tmpdir, [
'127.0.0.1'],
'127.0.0.1', [
'127.0.0.1'],
75 [(
'127.0.0.1', defaultport)])
77 run_bind_test(tmpdir, [
'127.0.0.1'],
'127.0.0.1:32171', [
'127.0.0.1:32171'],
78 [(
'127.0.0.1', 32171)])
80 run_bind_test(tmpdir, [
'127.0.0.1'],
'127.0.0.1:32171', [
'127.0.0.1:32171',
'127.0.0.1:32172'],
81 [(
'127.0.0.1', 32171), (
'127.0.0.1', 32172)])
84 [(
'::1', defaultport)])
86 run_bind_test(tmpdir, [
'127.0.0.1'],
'127.0.0.1', [
'127.0.0.1',
'[::1]'],
87 [(
'127.0.0.1', defaultport), (
'::1', defaultport)])
89 run_bind_test(tmpdir, [non_loopback_ip], non_loopback_ip, [non_loopback_ip],
90 [(non_loopback_ip, defaultport)])
96 assert(
not 'Connection not denied by rpcallowip as expected')
103 parser = optparse.OptionParser(usage=
"%prog [options]")
104 parser.add_option(
"--nocleanup", dest=
"nocleanup", default=
False, action=
"store_true",
105 help=
"Leave bitcoinds and test.* datadir on exit or error")
106 parser.add_option(
"--srcdir", dest=
"srcdir", default=
"../../src",
107 help=
"Source directory containing bitcoind/bitcoin-cli (default: %default%)")
108 parser.add_option(
"--tmpdir", dest=
"tmpdir", default=tempfile.mkdtemp(prefix=
"test"),
109 help=
"Root directory for datadirs")
110 (options, args) = parser.parse_args()
112 os.environ[
'PATH'] = options.srcdir+
":"+os.environ[
'PATH']
119 print(
"Initializing test directory "+options.tmpdir)
120 if not os.path.isdir(options.tmpdir):
121 os.makedirs(options.tmpdir)
128 except AssertionError
as e:
129 print(
"Assertion failed: "+e.message)
130 except Exception
as e:
131 print(
"Unexpected exception caught during testing: "+str(e))
132 traceback.print_tb(sys.exc_info()[2])
134 if not options.nocleanup:
137 shutil.rmtree(options.tmpdir)
140 print(
"Tests successful")
146 if __name__ ==
'__main__':
def get_rpc_proxy(url, node_number, timeout=None)
def initialize_chain(test_dir)
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
def check_json_precision()
def run_bind_test(tmpdir, allow_ips, connect_to, addresses, expected)
def run_allowip_test(tmpdir, allow_ips, rpchost, rpcport)
def assert_equal(thing1, thing2)