mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-24 18:23:26 -03:00
test: -norpccookiefile
Both bitcoind and bitcoin-cli.
This commit is contained in:
parent
39cbd4f37c
commit
7402658bc2
2 changed files with 25 additions and 2 deletions
|
@ -164,6 +164,9 @@ class TestBitcoinCli(BitcoinTestFramework):
|
||||||
self.log.info("Test connecting with non-existing RPC cookie file")
|
self.log.info("Test connecting with non-existing RPC cookie file")
|
||||||
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo)
|
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo)
|
||||||
|
|
||||||
|
self.log.info("Test connecting without RPC cookie file and with password arg")
|
||||||
|
assert_equal(BLOCKS, self.nodes[0].cli('-norpccookiefile', f'-rpcuser={user}', f'-rpcpassword={password}').getblockcount())
|
||||||
|
|
||||||
self.log.info("Test -getinfo with arguments fails")
|
self.log.info("Test -getinfo with arguments fails")
|
||||||
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
|
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,13 @@ import sys
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
def call_with_auth(node, user, password):
|
def call_with_auth(node, user, password, method="getbestblockhash"):
|
||||||
url = urllib.parse.urlparse(node.url)
|
url = urllib.parse.urlparse(node.url)
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
|
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
|
||||||
|
|
||||||
conn = http.client.HTTPConnection(url.hostname, url.port)
|
conn = http.client.HTTPConnection(url.hostname, url.port)
|
||||||
conn.connect()
|
conn.connect()
|
||||||
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
|
conn.request('POST', '/', f'{{"method": "{method}"}}', headers)
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
conn.close()
|
conn.close()
|
||||||
return resp
|
return resp
|
||||||
|
@ -121,6 +121,25 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
for perm in ["owner", "group", "all"]:
|
for perm in ["owner", "group", "all"]:
|
||||||
test_perm(perm)
|
test_perm(perm)
|
||||||
|
|
||||||
|
def test_norpccookiefile(self, node0_cookie_path):
|
||||||
|
assert self.nodes[0].is_node_stopped(), "We expect previous test to stopped the node"
|
||||||
|
assert not node0_cookie_path.exists()
|
||||||
|
|
||||||
|
self.log.info('Starting with -norpccookiefile')
|
||||||
|
# Start, but don't wait for RPC connection as TestNode.wait_for_rpc_connection() requires the cookie.
|
||||||
|
with self.nodes[0].busy_wait_for_debug_log([b'init message: Done loading']):
|
||||||
|
self.nodes[0].start(extra_args=["-norpccookiefile"])
|
||||||
|
assert not node0_cookie_path.exists()
|
||||||
|
|
||||||
|
self.log.info('Testing user/password authentication still works without cookie file')
|
||||||
|
assert_equal(200, call_with_auth(self.nodes[0], "rt", self.rtpassword).status)
|
||||||
|
# After confirming that we could log in, check that cookie file does not exist.
|
||||||
|
assert not node0_cookie_path.exists()
|
||||||
|
|
||||||
|
# Need to shut down in slightly unorthodox way since cookie auth can't be used
|
||||||
|
assert_equal(200, call_with_auth(self.nodes[0], "rt", self.rtpassword, method="stop").status)
|
||||||
|
self.nodes[0].wait_until_stopped()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.conf_setup()
|
self.conf_setup()
|
||||||
self.log.info('Check correctness of the rpcauth config option')
|
self.log.info('Check correctness of the rpcauth config option')
|
||||||
|
@ -178,6 +197,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.test_rpccookieperms()
|
self.test_rpccookieperms()
|
||||||
|
|
||||||
|
self.test_norpccookiefile(cookie_path)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
HTTPBasicsTest(__file__).main()
|
HTTPBasicsTest(__file__).main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue