|
6 | 6 |
|
7 | 7 | from test_framework.netutil import all_interfaces, addr_to_hex, get_bind_addrs, test_ipv6_local
|
8 | 8 | from test_framework.test_framework import BitcoinTestFramework, SkipTest
|
| 9 | +from test_framework.test_node import ErrorMatch |
9 | 10 | from test_framework.util import assert_equal, assert_raises_rpc_error, get_rpc_proxy, rpc_port, rpc_url
|
10 | 11 |
|
11 | 12 | class RPCBindTest(BitcoinTestFramework):
|
@@ -45,6 +46,19 @@ def run_bind_test(self, allow_ips, connect_to, addresses, expected):
|
45 | 46 | assert_equal(set(get_bind_addrs(pid)), set(expected))
|
46 | 47 | self.stop_nodes()
|
47 | 48 |
|
| 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 | + |
48 | 62 | def run_allowip_test(self, allow_ips, rpchost, rpcport):
|
49 | 63 | '''
|
50 | 64 | Start a node with rpcallow IP, and request getnetworkinfo
|
@@ -84,6 +98,10 @@ def run_test(self):
|
84 | 98 |
|
85 | 99 | if not self.options.run_nonloopback:
|
86 | 100 | 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']) |
87 | 105 | if not self.options.run_ipv4 and not self.options.run_ipv6:
|
88 | 106 | self._run_nonloopback_tests()
|
89 | 107 |
|
|
0 commit comments