Skip to content

Commit 73c2439

Browse files
committed
test: add tests for invalid rpcbind ports
1 parent 6fc4692 commit 73c2439

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/functional/rpc_bind.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from test_framework.netutil import all_interfaces, addr_to_hex, get_bind_addrs, test_ipv6_local
88
from test_framework.test_framework import BitcoinTestFramework, SkipTest
9+
from test_framework.test_node import ErrorMatch
910
from test_framework.util import assert_equal, assert_raises_rpc_error, get_rpc_proxy, rpc_port, rpc_url
1011

1112
class RPCBindTest(BitcoinTestFramework):
@@ -45,6 +46,19 @@ def run_bind_test(self, allow_ips, connect_to, addresses, expected):
4546
assert_equal(set(get_bind_addrs(pid)), set(expected))
4647
self.stop_nodes()
4748

49+
def run_invalid_bind_test(self, allow_ips, addresses):
50+
'''
51+
Attempt to start a node with requested rpcallowip and rpcbind
52+
parameters, expecting that the node will fail.
53+
'''
54+
self.log.info(f'Invalid bind test for {addresses}')
55+
base_args = ['-disablewallet', '-nolisten']
56+
if allow_ips:
57+
base_args += ['-rpcallowip=' + x for x in allow_ips]
58+
init_error = 'Error' # generic error will be adjusted in next commit
59+
for addr in addresses:
60+
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error, ErrorMatch.PARTIAL_REGEX)
61+
4862
def run_allowip_test(self, allow_ips, rpchost, rpcport):
4963
'''
5064
Start a node with rpcallow IP, and request getnetworkinfo
@@ -84,6 +98,10 @@ def run_test(self):
8498

8599
if not self.options.run_nonloopback:
86100
self._run_loopback_tests()
101+
if self.options.run_ipv4:
102+
self.run_invalid_bind_test(['127.0.0.1'], ['127.0.0.1:notaport', '127.0.0.1:-18443', '127.0.0.1:0', '127.0.0.1:65536'])
103+
if self.options.run_ipv6:
104+
self.run_invalid_bind_test(['[::1]'], ['[::1]:notaport', '[::1]:-18443', '[::1]:0', '[::1]:65536'])
87105
if not self.options.run_ipv4 and not self.options.run_ipv6:
88106
self._run_nonloopback_tests()
89107

0 commit comments

Comments
 (0)