Skip to content

Commit 7402658

Browse files
committed
test: -norpccookiefile
Both bitcoind and bitcoin-cli.
1 parent 39cbd4f commit 7402658

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
@@ -164,6 +164,9 @@ def run_test(self):
164164
self.log.info("Test connecting with non-existing RPC cookie file")
165165
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo)
166166

167+
self.log.info("Test connecting without RPC cookie file and with password arg")
168+
assert_equal(BLOCKS, self.nodes[0].cli('-norpccookiefile', f'-rpcuser={user}', f'-rpcpassword={password}').getblockcount())
169+
167170
self.log.info("Test -getinfo with arguments fails")
168171
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
169172

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')
@@ -178,6 +197,7 @@ def run_test(self):
178197

179198
self.test_rpccookieperms()
180199

200+
self.test_norpccookiefile(cookie_path)
181201

182202
if __name__ == '__main__':
183203
HTTPBasicsTest(__file__).main()

0 commit comments

Comments
 (0)