Skip to content

Commit 0f71679

Browse files
committed
Merge #12482: [tests] bind functional test nodes to 127.0.0.1
b156ff7 [tests] bind functional test nodes to 127.0.0.1 (Sjors Provoost) Pull request description: Replaces #12200 which broke `rpc_bind.py`. Prevents OSX firewall allow-this-application-to-accept-inbound-connections permission popups and is generally safer. To prevent binding to `127.0.0.1`, set `self.bind_to_localhost_only = False`. cc @jnewbery Tree-SHA512: 5e700124c91bd0cbdee83ca44910071d71d61d8842334755b685d14fbff6454d75de1ea7de67340370386f58b41361e80e90bb4dca5c4d5992f9d2b27985f999
2 parents 8a709fb + b156ff7 commit 0f71679

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

test/functional/rpc_bind.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class RPCBindTest(BitcoinTestFramework):
1515
def set_test_params(self):
1616
self.setup_clean_chain = True
17+
self.bind_to_localhost_only = False
1718
self.num_nodes = 1
1819

1920
def setup_network(self):

test/functional/test_framework/test_framework.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self):
6363
self.nodes = []
6464
self.mocktime = 0
6565
self.supports_cli = False
66+
self.bind_to_localhost_only = True
6667
self.set_test_params()
6768

6869
assert hasattr(self, "num_nodes"), "Test must set self.num_nodes in set_test_params()"
@@ -215,15 +216,19 @@ def run_test(self):
215216

216217
def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
217218
"""Instantiate TestNode objects"""
218-
219+
if self.bind_to_localhost_only:
220+
extra_confs = [["bind=127.0.0.1"]] * num_nodes
221+
else:
222+
extra_confs = [[]] * num_nodes
219223
if extra_args is None:
220224
extra_args = [[]] * num_nodes
221225
if binary is None:
222226
binary = [None] * num_nodes
227+
assert_equal(len(extra_confs), num_nodes)
223228
assert_equal(len(extra_args), num_nodes)
224229
assert_equal(len(binary), num_nodes)
225230
for i in range(num_nodes):
226-
self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, use_cli=self.options.usecli))
231+
self.nodes.append(TestNode(i, self.options.tmpdir, rpchost=rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
227232

228233
def start_node(self, i, *args, **kwargs):
229234
"""Start a bitcoind"""
@@ -395,7 +400,7 @@ def _initialize_chain(self):
395400
args = [os.getenv("BITCOIND", "bitcoind"), "-datadir=" + datadir]
396401
if i > 0:
397402
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
398-
self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
403+
self.nodes.append(TestNode(i, self.options.cachedir, extra_conf=["bind=127.0.0.1"], extra_args=[],rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
399404
self.nodes[i].args = args
400405
self.start_node(i)
401406

test/functional/test_framework/test_node.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .authproxy import JSONRPCException
1818
from .util import (
19+
append_config,
1920
assert_equal,
2021
get_rpc_proxy,
2122
rpc_url,
@@ -42,7 +43,7 @@ class TestNode():
4243
To make things easier for the test writer, any unrecognised messages will
4344
be dispatched to the RPC connection."""
4445

45-
def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mocktime, coverage_dir, use_cli=False):
46+
def __init__(self, i, dirname, rpchost, timewait, binary, stderr, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
4647
self.index = i
4748
self.datadir = os.path.join(dirname, "node" + str(i))
4849
self.rpchost = rpchost
@@ -57,6 +58,8 @@ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mo
5758
self.binary = binary
5859
self.stderr = stderr
5960
self.coverage_dir = coverage_dir
61+
if extra_conf != None:
62+
append_config(dirname, i, extra_conf)
6063
# Most callers will just need to add extra args to the standard list below.
6164
# For those callers that need more flexibity, they can just set the args property directly.
6265
# Note that common args are set in the config file (see initialize_datadir)

test/functional/test_framework/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ def initialize_datadir(dirname, n):
300300
def get_datadir_path(dirname, n):
301301
return os.path.join(dirname, "node" + str(n))
302302

303+
def append_config(dirname, n, options):
304+
datadir = get_datadir_path(dirname, n)
305+
with open(os.path.join(datadir, "bitcoin.conf"), 'a', encoding='utf8') as f:
306+
for option in options:
307+
f.write(option + "\n")
308+
303309
def get_auth_cookie(datadir):
304310
user = None
305311
password = None

test/functional/wallet_dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def setup_network(self, split=False):
8484
# longer than the default 30 seconds due to an expensive
8585
# CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
8686
# the test often takes even longer.
87-
self.add_nodes(self.num_nodes, self.extra_args, timewait=60)
87+
self.add_nodes(self.num_nodes, extra_args=self.extra_args, timewait=60)
8888
self.start_nodes()
8989

9090
def run_test (self):

test/functional/wallet_import_rescan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def setup_network(self):
124124
if import_node.prune:
125125
extra_args[i] += ["-prune=1"]
126126

127-
self.add_nodes(self.num_nodes, extra_args)
127+
self.add_nodes(self.num_nodes, extra_args=extra_args)
128128
self.start_nodes()
129129
for i in range(1, self.num_nodes):
130130
connect_nodes(self.nodes[i], 0)

0 commit comments

Comments
 (0)