Skip to content

Commit 56c374d

Browse files
hodlinatorluke-jr
authored andcommitted
test: -norpccookiefile
Both bitcoind and bitcoin-cli. Github-Pull: bitcoin#31212 Rebased-From: 7402658
1 parent 88ae15b commit 56c374d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

test/functional/interface_bitcoin_cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def run_test(self):
159159
self.log.info("Test connecting with non-existing RPC cookie file")
160160
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo)
161161

162+
self.log.info("Test connecting without RPC cookie file and with password arg")
163+
assert_equal(BLOCKS, self.nodes[0].cli('-norpccookiefile', f'-rpcuser={user}', f'-rpcpassword={password}').getblockcount())
164+
162165
self.log.info("Test -getinfo with arguments fails")
163166
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
164167

test/functional/rpc_users.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
from typing import Optional
2323

2424

25-
def call_with_auth(node, user, password):
25+
def call_with_auth(node, user, password, method="getbestblockhash"):
2626
url = urllib.parse.urlparse(node.url)
2727
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
2828

2929
conn = http.client.HTTPConnection(url.hostname, url.port)
3030
conn.connect()
31-
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
31+
conn.request('POST', '/', f'{{"method": "{method}"}}', headers)
3232
resp = conn.getresponse()
3333
conn.close()
3434
return resp
@@ -121,6 +121,25 @@ def test_perm(perm: Optional[str]):
121121
for perm in ["owner", "group", "all"]:
122122
test_perm(perm)
123123

124+
def test_norpccookiefile(self, node0_cookie_path):
125+
assert self.nodes[0].is_node_stopped(), "We expect previous test to stopped the node"
126+
assert not node0_cookie_path.exists()
127+
128+
self.log.info('Starting with -norpccookiefile')
129+
# Start, but don't wait for RPC connection as TestNode.wait_for_rpc_connection() requires the cookie.
130+
with self.nodes[0].busy_wait_for_debug_log([b'init message: Done loading']):
131+
self.nodes[0].start(extra_args=["-norpccookiefile"])
132+
assert not node0_cookie_path.exists()
133+
134+
self.log.info('Testing user/password authentication still works without cookie file')
135+
assert_equal(200, call_with_auth(self.nodes[0], "rt", self.rtpassword).status)
136+
# After confirming that we could log in, check that cookie file does not exist.
137+
assert not node0_cookie_path.exists()
138+
139+
# Need to shut down in slightly unorthodox way since cookie auth can't be used
140+
assert_equal(200, call_with_auth(self.nodes[0], "rt", self.rtpassword, method="stop").status)
141+
self.nodes[0].wait_until_stopped()
142+
124143
def run_test(self):
125144
self.conf_setup()
126145
self.log.info('Check correctness of the rpcauth config option')
@@ -161,6 +180,7 @@ def run_test(self):
161180

162181
self.test_rpccookieperms()
163182

183+
self.test_norpccookiefile(cookie_path)
164184

165185
if __name__ == '__main__':
166186
HTTPBasicsTest(__file__).main()

0 commit comments

Comments
 (0)