Skip to content

Commit d5b2e98

Browse files
committed
Merge #12510: test: Add rpc_bind test to default-run tests
e87fefc test: Add rpc_bind test to default-run tests (Wladimir J. van der Laan) Pull request description: Skip the parts that cannot be run on the host due to lack of IPv6 support or a second interface to bind on, and warn appropriately. Without no strong requirements (besides being Linux only, which will skip the test) left, add this test to the default in test_runner. ~~(the non-IPv6 parts of the two dual-IPv4/6 tests could also be enabled, but first going to look what Travis does here to see if there wasn't another reason it was disabled)~~ done, it only makes sense for the first Tree-SHA512: 724259b14f59dccc7e61ef071359336adb0f76a63db392b6ce6940e21c8ee0470c35374e82970681261685ef299cd70b0c1372598cea85d341f64c2c40ea28ee
2 parents 4741ca5 + e87fefc commit d5b2e98

File tree

2 files changed

+64
-44
lines changed

2 files changed

+64
-44
lines changed

test/functional/rpc_bind.py

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test running bitcoind with the -rpcbind and -rpcallowip options."""
66

7-
import socket
87
import sys
98

109
from test_framework.test_framework import BitcoinTestFramework, SkipTest
@@ -20,6 +19,11 @@ def set_test_params(self):
2019
def setup_network(self):
2120
self.add_nodes(self.num_nodes, None)
2221

22+
def add_options(self, parser):
23+
parser.add_option("--ipv4", action='store_true', dest="run_ipv4", help="Run ipv4 tests only", default=False)
24+
parser.add_option("--ipv6", action='store_true', dest="run_ipv6", help="Run ipv6 tests only", default=False)
25+
parser.add_option("--nonloopback", action='store_true', dest="run_nonloopback", help="Run non-loopback tests only", default=False)
26+
2327
def run_bind_test(self, allow_ips, connect_to, addresses, expected):
2428
'''
2529
Start a node with requested rpcallowip and rpcbind parameters,
@@ -54,55 +58,69 @@ def run_allowip_test(self, allow_ips, rpchost, rpcport):
5458

5559
def run_test(self):
5660
# due to OS-specific network stats queries, this test works only on Linux
61+
if sum([self.options.run_ipv4, self.options.run_ipv6, self.options.run_nonloopback]) > 1:
62+
raise AssertionError("Only one of --ipv4, --ipv6 and --nonloopback can be set")
63+
64+
self.log.info("Check for linux")
5765
if not sys.platform.startswith('linux'):
58-
raise SkipTest("This test can only be run on Linux.")
59-
# find the first non-loopback interface for testing
60-
non_loopback_ip = None
66+
raise SkipTest("This test can only be run on linux.")
67+
68+
self.log.info("Check for ipv6")
69+
have_ipv6 = test_ipv6_local()
70+
if not have_ipv6 and not self.options.run_ipv4:
71+
raise SkipTest("This test requires ipv6 support.")
72+
73+
self.log.info("Check for non-loopback interface")
74+
self.non_loopback_ip = None
6175
for name,ip in all_interfaces():
6276
if ip != '127.0.0.1':
63-
non_loopback_ip = ip
77+
self.non_loopback_ip = ip
6478
break
65-
if non_loopback_ip is None:
66-
raise SkipTest("This test requires at least one non-loopback IPv4 interface.")
67-
try:
68-
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
69-
s.connect(("::1",1))
70-
s.close
71-
except OSError:
72-
raise SkipTest("This test requires IPv6 support.")
73-
74-
self.log.info("Using interface %s for testing" % non_loopback_ip)
75-
76-
defaultport = rpc_port(0)
77-
78-
# check default without rpcallowip (IPv4 and IPv6 localhost)
79-
self.run_bind_test(None, '127.0.0.1', [],
80-
[('127.0.0.1', defaultport), ('::1', defaultport)])
81-
# check default with rpcallowip (IPv6 any)
82-
self.run_bind_test(['127.0.0.1'], '127.0.0.1', [],
83-
[('::0', defaultport)])
84-
# check only IPv4 localhost (explicit)
85-
self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
86-
[('127.0.0.1', defaultport)])
87-
# check only IPv4 localhost (explicit) with alternative port
88-
self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
89-
[('127.0.0.1', 32171)])
90-
# check only IPv4 localhost (explicit) with multiple alternative ports on same host
91-
self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171', '127.0.0.1:32172'],
92-
[('127.0.0.1', 32171), ('127.0.0.1', 32172)])
93-
# check only IPv6 localhost (explicit)
94-
self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
95-
[('::1', defaultport)])
96-
# check both IPv4 and IPv6 localhost (explicit)
97-
self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
98-
[('127.0.0.1', defaultport), ('::1', defaultport)])
79+
if self.non_loopback_ip is None and self.options.run_nonloopback:
80+
raise SkipTest("This test requires a non-loopback ip address.")
81+
82+
self.defaultport = rpc_port(0)
83+
84+
if not self.options.run_nonloopback:
85+
self._run_loopback_tests()
86+
if not self.options.run_ipv4 and not self.options.run_ipv6:
87+
self._run_nonloopback_tests()
88+
89+
def _run_loopback_tests(self):
90+
if self.options.run_ipv4:
91+
# check only IPv4 localhost (explicit)
92+
self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
93+
[('127.0.0.1', self.defaultport)])
94+
# check only IPv4 localhost (explicit) with alternative port
95+
self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
96+
[('127.0.0.1', 32171)])
97+
# check only IPv4 localhost (explicit) with multiple alternative ports on same host
98+
self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171', '127.0.0.1:32172'],
99+
[('127.0.0.1', 32171), ('127.0.0.1', 32172)])
100+
else:
101+
# check default without rpcallowip (IPv4 and IPv6 localhost)
102+
self.run_bind_test(None, '127.0.0.1', [],
103+
[('127.0.0.1', self.defaultport), ('::1', self.defaultport)])
104+
# check default with rpcallowip (IPv6 any)
105+
self.run_bind_test(['127.0.0.1'], '127.0.0.1', [],
106+
[('::0', self.defaultport)])
107+
# check only IPv6 localhost (explicit)
108+
self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
109+
[('::1', self.defaultport)])
110+
# check both IPv4 and IPv6 localhost (explicit)
111+
self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
112+
[('127.0.0.1', self.defaultport), ('::1', self.defaultport)])
113+
114+
def _run_nonloopback_tests(self):
115+
self.log.info("Using interface %s for testing" % self.non_loopback_ip)
116+
99117
# check only non-loopback interface
100-
self.run_bind_test([non_loopback_ip], non_loopback_ip, [non_loopback_ip],
101-
[(non_loopback_ip, defaultport)])
118+
self.run_bind_test([self.non_loopback_ip], self.non_loopback_ip, [self.non_loopback_ip],
119+
[(self.non_loopback_ip, self.defaultport)])
102120

103121
# Check that with invalid rpcallowip, we are denied
104-
self.run_allowip_test([non_loopback_ip], non_loopback_ip, defaultport)
105-
assert_raises_rpc_error(-342, "non-JSON HTTP response with '403 Forbidden' from server", self.run_allowip_test, ['1.1.1.1'], non_loopback_ip, defaultport)
122+
self.run_allowip_test([self.non_loopback_ip], self.non_loopback_ip, self.defaultport)
123+
assert_raises_rpc_error(-342, "non-JSON HTTP response with '403 Forbidden' from server", self.run_allowip_test, ['1.1.1.1'], self.non_loopback_ip, self.defaultport)
106124

107125
if __name__ == '__main__':
108126
RPCBindTest().main()

test/functional/test_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
'feature_nulldummy.py',
121121
'mempool_accept.py',
122122
'wallet_import_rescan.py',
123+
'rpc_bind.py --ipv4',
124+
'rpc_bind.py --ipv6',
125+
'rpc_bind.py --nonloopback',
123126
'mining_basic.py',
124127
'wallet_bumpfee.py',
125128
'rpc_named_arguments.py',
@@ -160,7 +163,6 @@
160163
'p2p_timeouts.py',
161164
# vv Tests less than 60s vv
162165
'p2p_feefilter.py',
163-
'rpc_bind.py',
164166
# vv Tests less than 30s vv
165167
'feature_assumevalid.py',
166168
'example_test.py',

0 commit comments

Comments
 (0)