test: -norpccookiefile

Both bitcoind and bitcoin-cli.
This commit is contained in:
Hodlinator
2024-11-25 10:50:40 +01:00
parent 39cbd4f37c
commit 7402658bc2
2 changed files with 25 additions and 2 deletions

View File

@@ -22,13 +22,13 @@ import sys
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)
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
conn = http.client.HTTPConnection(url.hostname, url.port)
conn.connect()
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
conn.request('POST', '/', f'{{"method": "{method}"}}', headers)
resp = conn.getresponse()
conn.close()
return resp
@@ -121,6 +121,25 @@ class HTTPBasicsTest(BitcoinTestFramework):
for perm in ["owner", "group", "all"]:
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):
self.conf_setup()
self.log.info('Check correctness of the rpcauth config option')
@@ -178,6 +197,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
self.test_rpccookieperms()
self.test_norpccookiefile(cookie_path)
if __name__ == '__main__':
HTTPBasicsTest(__file__).main()