fix: handle invalid rpcbind port earlier

Previously, when an invalid port was specified
in `-rpcbind`, the `SplitHostPort()` return value
in `HTTPBindAddresses()` was ignored and attempt
would be made to bind to the default rpcbind port
(with the host/port treated as a host).

This rearranges port checking code in
`AppInitMain()` to handle the invalid
port before reaching `HTTPBindAddresses()`.

Also adjusts associated functional tests.
This commit is contained in:
tdb3
2024-08-21 20:19:13 -04:00
parent 83b67f2e6d
commit d38e3aed89
2 changed files with 5 additions and 6 deletions

View File

@@ -6,7 +6,6 @@
from test_framework.netutil import all_interfaces, addr_to_hex, get_bind_addrs, test_ipv6_local
from test_framework.test_framework import BitcoinTestFramework, SkipTest
from test_framework.test_node import ErrorMatch
from test_framework.util import assert_equal, assert_raises_rpc_error, get_rpc_proxy, rpc_port, rpc_url
class RPCBindTest(BitcoinTestFramework):
@@ -55,9 +54,9 @@ class RPCBindTest(BitcoinTestFramework):
base_args = ['-disablewallet', '-nolisten']
if allow_ips:
base_args += ['-rpcallowip=' + x for x in allow_ips]
init_error = 'Error' # generic error will be adjusted in next commit
init_error = 'Error: Invalid port specified in -rpcbind: '
for addr in addresses:
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error, ErrorMatch.PARTIAL_REGEX)
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error + f"'{addr}'")
def run_allowip_test(self, allow_ips, rpchost, rpcport):
'''