|
22 | 22 | from typing import Optional
|
23 | 23 |
|
24 | 24 |
|
25 |
| -def call_with_auth(node, user, password): |
| 25 | +def call_with_auth(node, user, password, method="getbestblockhash"): |
26 | 26 | url = urllib.parse.urlparse(node.url)
|
27 | 27 | headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
|
28 | 28 |
|
29 | 29 | conn = http.client.HTTPConnection(url.hostname, url.port)
|
30 | 30 | conn.connect()
|
31 |
| - conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) |
| 31 | + conn.request('POST', '/', f'{{"method": "{method}"}}', headers) |
32 | 32 | resp = conn.getresponse()
|
33 | 33 | conn.close()
|
34 | 34 | return resp
|
@@ -121,6 +121,25 @@ def test_perm(perm: Optional[str]):
|
121 | 121 | for perm in ["owner", "group", "all"]:
|
122 | 122 | test_perm(perm)
|
123 | 123 |
|
| 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 | + |
124 | 143 | def run_test(self):
|
125 | 144 | self.conf_setup()
|
126 | 145 | self.log.info('Check correctness of the rpcauth config option')
|
@@ -178,6 +197,7 @@ def run_test(self):
|
178 | 197 |
|
179 | 198 | self.test_rpccookieperms()
|
180 | 199 |
|
| 200 | + self.test_norpccookiefile(cookie_path) |
181 | 201 |
|
182 | 202 | if __name__ == '__main__':
|
183 | 203 | HTTPBasicsTest(__file__).main()
|
0 commit comments