aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/rpcbind_test.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-09-26 15:45:18 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-09-26 16:22:51 +0200
commit254e990ce5c380d328da4db4646bd7fb4b37e864 (patch)
tree09ebf058a0e58a98eed87796ec6a41ae5d2edec5 /qa/rpc-tests/rpcbind_test.py
parent8d9e8adc05f42fc5bf99ad499a01d9f9ab6d2311 (diff)
parentb70b4a24e645e4602df310263390964ceda64a8f (diff)
downloadbitcoin-254e990ce5c380d328da4db4646bd7fb4b37e864.tar.xz
Merge #8772: [0.13] Backports
b70b4a2 Trivial: Fix typo (Marty Jones) 702fd2e [copyright] add MIT license headers to .sh scripts where missing (isle2983) a60d7cc [copyright] Add missing copyright headers (isle2983) ea2a6be [copyright] add MIT License copyright header to remaining Python files (isle2983) 9a903f9 [copyright] add MIT License copyright header to zmq_sub.py (isle2983) 084cae9 UndoReadFromDisk works on undo files (rev), not on block files. (Pavel Janík) e34374e [qa] wallet: Check legacy wallet as well (MarcoFalke) d31ac72 Specify Protobuf version 2 in paymentrequest.proto (fanquake) 5e15fce Minor change in section name (Anders Øyvind Urke-Sætre) 0e2c6bd [Doc] Target protobuf 2.6 in OS X build notes. (Michael Ford) da94272 [qa] walletbackup: Sync blocks inside the loop (MarcoFalke) 42ea51a net: No longer send local address in addrMe (Wladimir J. van der Laan) ea51b0f Berkeley DB v6 compatibility fix (Alexey Vesnin) 0a35573 [doc] - clarify statement about parallel jobs in rpc-tests.py (isle2983) 752fbae contrib: Make fix-copyright-headers.py more portable (MarcoFalke) 486650a [doc] Fix typos in comments, doxygen: Fix comment syntax (MarcoFalke) c18a9ca [qa] pull-tester: Don't mute zmq ImportError (MarcoFalke) 9556745 init: Fix typo in help message for -whitelistforcerelay (Wladimir J. van der Laan) 4f84082 Set jonasschnellis dns-seeder filter flag (Jonas Schnelli) 863ae74 [doc] Update git-subtree-check.sh README (MarcoFalke) c493f43 Trivial: Fix two VarInt examples in serialize.h (Christian Barcenas) cb07f19 CDB: fix debug output (crowning-) 75d5484 Add copyright header to wallet_text_fixture.cpp (Wladimir J. van der Laan) 305d8ac Use __func__ to get function name for output printing (MarcoFalke) 464dedd [Wallet] Trivial cleanup of HD wallet changes (Jonas Schnelli) b17a3f9 document return value of networkhashps for getmininginfo RPC endpoint (Jameson Lopp) a27cdd8 [qa] abandonconflict: Use assert_equal (MarcoFalke) befe654 various typos (leijurv) 4e5fc31 Fix a type error that would not compile on Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) (Jeremy Rubin) 156e305 Corrected JSON typo on setban of net.cpp (Sev) fa5b249 Bugfix: Allow building libbitcoinconsensus without any univalue (Luke Dashjr) 8b0bdd3 configure: Allow building bench_bitcoin by itself (Luke Dashjr) 749c8a5 [doc] typos, READMEs, comments (Justin Camarena) fc34928 Do diskspace check before import thread is started (Pieter Wuille) 3b354d2 Add extra message to avoid a long 'Loading banlist' (Pieter Wuille) 30eac2d Use a signal to continue init after genesis activation (Pieter Wuille) 9b00979 Update README.md (Chris Stewart) 8bb1efd [qa] Rework hd wallet dump test (MarcoFalke) a7aa3cc Enable size accounting in mining unit tests (Suhas Daftuar) bea02dc [qa]: enable rpcbind_test (whythat) e111904 [qa]: add parsing for '<host>:<port>' argument form to rpc_url() (whythat) 69d1cd2 net: Ignore `notfound` P2P messages (Wladimir J. van der Laan) f70be14 [QA] Add walletdump RPC test (including HD- & encryption-tests) (Jonas Schnelli) 1f21d16 prepend license statement to indirectmap (Kaz Wesley) 03b0196 Fix obvious assignment/equality error in test (Jeremy Rubin) 8a7d7ff update name of file bitcoin.qrc (Gaurav Rana) 147003c Add configure check for -latomic (Anthony Towns) 091cdeb Clear witness with vin/vout in CWallet::CreateTransaction() (Suhas Daftuar) 8e03382 [Qt][CoinControl] fix UI bug that could result in paying unexpected fee (Jonas Schnelli) 6b07362 Fix SIGHASH_SINGLE bug in test_framework SignatureHash (Johnson Lau) a114a02 p2psegwit.py transaction is rejected due to premature witness not size (instagibbs) 3606b6b Update p2p-segwit.py to reflect correct AskFor behavior (instagibbs) 733760a Update btcdrak signing key (BtcDrak) c6a6291 add witness address to address book (instagibbs)
Diffstat (limited to 'qa/rpc-tests/rpcbind_test.py')
-rwxr-xr-xqa/rpc-tests/rpcbind_test.py219
1 files changed, 92 insertions, 127 deletions
diff --git a/qa/rpc-tests/rpcbind_test.py b/qa/rpc-tests/rpcbind_test.py
index 572273566b..bf1cc87126 100755
--- a/qa/rpc-tests/rpcbind_test.py
+++ b/qa/rpc-tests/rpcbind_test.py
@@ -5,143 +5,108 @@
# Test for -rpcbind, as well as -rpcallowip and -rpcconnect
-# TODO extend this test from the test framework (like all other tests)
-
import tempfile
import traceback
+from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.netutil import *
-def run_bind_test(tmpdir, allow_ips, connect_to, addresses, expected):
- '''
- Start a node with requested rpcallowip and rpcbind parameters,
- then try to connect, and check if the set of bound addresses
- matches the expected set.
- '''
- expected = [(addr_to_hex(addr), port) for (addr, port) in expected]
- base_args = ['-disablewallet', '-nolisten']
- if allow_ips:
- base_args += ['-rpcallowip=' + x for x in allow_ips]
- binds = ['-rpcbind='+addr for addr in addresses]
- nodes = start_nodes(self.num_nodes, tmpdir, [base_args + binds], connect_to)
- try:
- pid = bitcoind_processes[0].pid
- assert_equal(set(get_bind_addrs(pid)), set(expected))
- finally:
- stop_nodes(nodes)
- wait_bitcoinds()
-
-def run_allowip_test(tmpdir, allow_ips, rpchost, rpcport):
- '''
- Start a node with rpcwallow IP, and request getinfo
- at a non-localhost IP.
- '''
- base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]
- nodes = start_nodes(self.num_nodes, tmpdir, [base_args])
- try:
- # connect to node through non-loopback interface
- url = "http://rt:rt@%s:%d" % (rpchost, rpcport,)
- node = get_rpc_proxy(url, 1)
- node.getinfo()
- finally:
- node = None # make sure connection will be garbage collected and closed
- stop_nodes(nodes)
- wait_bitcoinds()
-
-
-def run_test(tmpdir):
- assert(sys.platform.startswith('linux')) # due to OS-specific network stats queries, this test works only on Linux
- # find the first non-loopback interface for testing
- non_loopback_ip = None
- for name,ip in all_interfaces():
- if ip != '127.0.0.1':
- non_loopback_ip = ip
- break
- if non_loopback_ip is None:
- assert(not 'This test requires at least one non-loopback IPv4 interface')
- print("Using interface %s for testing" % non_loopback_ip)
+class RPCBindTest(BitcoinTestFramework):
- defaultport = rpc_port(0)
+ def __init__(self):
+ super().__init__()
+ self.setup_clean_chain = True
+ self.num_nodes = 1
- # check default without rpcallowip (IPv4 and IPv6 localhost)
- run_bind_test(tmpdir, None, '127.0.0.1', [],
- [('127.0.0.1', defaultport), ('::1', defaultport)])
- # check default with rpcallowip (IPv6 any)
- run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', [],
- [('::0', defaultport)])
- # check only IPv4 localhost (explicit)
- run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
- [('127.0.0.1', defaultport)])
- # check only IPv4 localhost (explicit) with alternative port
- run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
- [('127.0.0.1', 32171)])
- # check only IPv4 localhost (explicit) with multiple alternative ports on same host
- run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171', '127.0.0.1:32172'],
- [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
- # check only IPv6 localhost (explicit)
- run_bind_test(tmpdir, ['[::1]'], '[::1]', ['[::1]'],
- [('::1', defaultport)])
- # check both IPv4 and IPv6 localhost (explicit)
- run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
- [('127.0.0.1', defaultport), ('::1', defaultport)])
- # check only non-loopback interface
- run_bind_test(tmpdir, [non_loopback_ip], non_loopback_ip, [non_loopback_ip],
- [(non_loopback_ip, defaultport)])
-
- # Check that with invalid rpcallowip, we are denied
- run_allowip_test(tmpdir, [non_loopback_ip], non_loopback_ip, defaultport)
- try:
- run_allowip_test(tmpdir, ['1.1.1.1'], non_loopback_ip, defaultport)
- assert(not 'Connection not denied by rpcallowip as expected')
- except ValueError:
+ def setup_network(self):
pass
-def main():
- import optparse
-
- parser = optparse.OptionParser(usage="%prog [options]")
- parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
- help="Leave bitcoinds and test.* datadir on exit or error")
- parser.add_option("--srcdir", dest="srcdir", default="../../src",
- help="Source directory containing bitcoind/bitcoin-cli (default: %default%)")
- parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"),
- help="Root directory for datadirs")
- (options, args) = parser.parse_args()
-
- os.environ['PATH'] = options.srcdir+":"+os.environ['PATH']
-
- check_json_precision()
-
- success = False
- nodes = []
- try:
- print("Initializing test directory "+options.tmpdir)
- if not os.path.isdir(options.tmpdir):
- os.makedirs(options.tmpdir)
- initialize_chain(options.tmpdir)
-
- run_test(options.tmpdir)
-
- success = True
-
- except AssertionError as e:
- print("Assertion failed: "+e.message)
- except Exception as e:
- print("Unexpected exception caught during testing: "+str(e))
- traceback.print_tb(sys.exc_info()[2])
-
- if not options.nocleanup:
- print("Cleaning up")
- wait_bitcoinds()
- shutil.rmtree(options.tmpdir)
+ def setup_nodes(self):
+ pass
- if success:
- print("Tests successful")
- sys.exit(0)
- else:
- print("Failed")
- sys.exit(1)
+ def run_bind_test(self, allow_ips, connect_to, addresses, expected):
+ '''
+ Start a node with requested rpcallowip and rpcbind parameters,
+ then try to connect, and check if the set of bound addresses
+ matches the expected set.
+ '''
+ expected = [(addr_to_hex(addr), port) for (addr, port) in expected]
+ base_args = ['-disablewallet', '-nolisten']
+ if allow_ips:
+ base_args += ['-rpcallowip=' + x for x in allow_ips]
+ binds = ['-rpcbind='+addr for addr in addresses]
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [base_args + binds], connect_to)
+ try:
+ pid = bitcoind_processes[0].pid
+ assert_equal(set(get_bind_addrs(pid)), set(expected))
+ finally:
+ stop_nodes(self.nodes)
+ wait_bitcoinds()
+
+ def run_allowip_test(self, allow_ips, rpchost, rpcport):
+ '''
+ Start a node with rpcwallow IP, and request getinfo
+ at a non-localhost IP.
+ '''
+ base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [base_args])
+ try:
+ # connect to node through non-loopback interface
+ node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0)
+ node.getinfo()
+ finally:
+ node = None # make sure connection will be garbage collected and closed
+ stop_nodes(self.nodes)
+ wait_bitcoinds()
+
+ def run_test(self):
+ # due to OS-specific network stats queries, this test works only on Linux
+ assert(sys.platform.startswith('linux'))
+ # find the first non-loopback interface for testing
+ non_loopback_ip = None
+ for name,ip in all_interfaces():
+ if ip != '127.0.0.1':
+ non_loopback_ip = ip
+ break
+ if non_loopback_ip is None:
+ assert(not 'This test requires at least one non-loopback IPv4 interface')
+ print("Using interface %s for testing" % non_loopback_ip)
+
+ defaultport = rpc_port(0)
+
+ # check default without rpcallowip (IPv4 and IPv6 localhost)
+ self.run_bind_test(None, '127.0.0.1', [],
+ [('127.0.0.1', defaultport), ('::1', defaultport)])
+ # check default with rpcallowip (IPv6 any)
+ self.run_bind_test(['127.0.0.1'], '127.0.0.1', [],
+ [('::0', defaultport)])
+ # check only IPv4 localhost (explicit)
+ self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
+ [('127.0.0.1', defaultport)])
+ # check only IPv4 localhost (explicit) with alternative port
+ self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
+ [('127.0.0.1', 32171)])
+ # check only IPv4 localhost (explicit) with multiple alternative ports on same host
+ self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171', '127.0.0.1:32172'],
+ [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
+ # check only IPv6 localhost (explicit)
+ self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
+ [('::1', defaultport)])
+ # check both IPv4 and IPv6 localhost (explicit)
+ self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
+ [('127.0.0.1', defaultport), ('::1', defaultport)])
+ # check only non-loopback interface
+ self.run_bind_test([non_loopback_ip], non_loopback_ip, [non_loopback_ip],
+ [(non_loopback_ip, defaultport)])
+
+ # Check that with invalid rpcallowip, we are denied
+ self.run_allowip_test([non_loopback_ip], non_loopback_ip, defaultport)
+ try:
+ self.run_allowip_test(['1.1.1.1'], non_loopback_ip, defaultport)
+ assert(not 'Connection not denied by rpcallowip as expected')
+ except JSONRPCException:
+ pass
if __name__ == '__main__':
- main()
+ RPCBindTest ().main ()