MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / test_rpccookieperms

Method test_rpccookieperms

test/functional/rpc_users.py:86–119  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

84 assert_equal(401, call_with_auth(node, user + 'wrong', password + 'wrong').status)
85
86 def test_rpccookieperms(self):
87 p = {"owner": 0o600, "group": 0o640, "all": 0o644}
88
89 if platform.system() == 'Windows':
90 self.log.info(f"Skip cookie file permissions checks as OS detected as: {platform.system()=}")
91 return
92
93 self.log.info('Check cookie file permissions can be set using -rpccookieperms')
94
95 cookie_file_path = self.nodes[1].chain_path / '.cookie'
96 PERM_BITS_UMASK = 0o777
97
98 def test_perm(perm: Optional[str]):
99 if not perm:
100 perm = 'owner'
101 self.restart_node(1)
102 else:
103 self.restart_node(1, extra_args=[f"-rpccookieperms={perm}"])
104
105 file_stat = os.stat(cookie_file_path)
106 actual_perms = file_stat.st_mode & PERM_BITS_UMASK
107 expected_perms = p[perm]
108 assert_equal(expected_perms, actual_perms)
109
110 # Remove any leftover rpc{user|password} config options from previous tests
111 self.stop_node(1)
112 self.nodes[1].replace_in_config([("rpcuser", "#rpcuser"), ("rpcpassword", "#rpcpassword")])
113
114 self.log.info('Check default cookie permission')
115 test_perm(None)
116
117 self.log.info('Check custom cookie permissions')
118 for perm in ["owner", "group", "all"]:
119 test_perm(perm)
120
121 def test_norpccookiefile(self, node0_cookie_path):
122 assert self.nodes[0].is_node_stopped(), "We expect previous test to stopped the node"

Callers 1

run_testMethod · 0.95

Calls 3

infoMethod · 0.80
replace_in_configMethod · 0.80
stop_nodeMethod · 0.45

Tested by

no test coverage detected