mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 05:54:48 +02:00
RPC: Delete cookie file before replacing it
Unclear if this is the best thing to do, but due to v26.1.knots20240325 creating it read-only, it is somewhat necessary for now
This commit is contained in:
parent
c04e29bc3a
commit
6cd206d331
@ -106,6 +106,11 @@ bool GenerateAuthCookie(std::string* cookie_out, const std::pair<std::optional<f
|
|||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
fs::path filepath = GetAuthCookieFile(false);
|
fs::path filepath = GetAuthCookieFile(false);
|
||||||
|
try {
|
||||||
|
fs::remove(filepath);
|
||||||
|
} catch (const fs::filesystem_error& e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
if (!RenameOver(filepath_tmp, filepath)) {
|
if (!RenameOver(filepath_tmp, filepath)) {
|
||||||
LogInfo("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
|
LogInfo("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
|
||||||
return false;
|
return false;
|
||||||
|
@ -257,6 +257,18 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
|||||||
(self.nodes[0].chain_path / ".cookie.tmp").mkdir()
|
(self.nodes[0].chain_path / ".cookie.tmp").mkdir()
|
||||||
(self.nodes[0].chain_path / ".cookie.tmp/subdir").mkdir()
|
(self.nodes[0].chain_path / ".cookie.tmp/subdir").mkdir()
|
||||||
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
|
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
|
||||||
|
(self.nodes[0].chain_path / ".cookie.tmp/subdir").rmdir()
|
||||||
|
(self.nodes[0].chain_path / ".cookie.tmp").rmdir()
|
||||||
|
|
||||||
|
(self.nodes[0].chain_path / ".cookie").mkdir()
|
||||||
|
(self.nodes[0].chain_path / ".cookie/subdir").mkdir()
|
||||||
|
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
|
||||||
|
(self.nodes[0].chain_path / ".cookie/subdir").rmdir()
|
||||||
|
(self.nodes[0].chain_path / ".cookie").rmdir()
|
||||||
|
|
||||||
|
self.log.info('Check that a non-writable cookie file will get replaced gracefully')
|
||||||
|
(self.nodes[0].chain_path / ".cookie").mkdir(mode=1)
|
||||||
|
self.restart_node(0)
|
||||||
|
|
||||||
self.test_rpccookieperms()
|
self.test_rpccookieperms()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user