Skip to content

Commit d2afa26

Browse files
committed
test: add rpccookieperms test
Tests various perms on non-Windows OSes
1 parent f467aed commit d2afa26

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/functional/rpc_users.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
)
1212

1313
import http.client
14+
import os
15+
import platform
1416
import urllib.parse
1517
import subprocess
1618
from random import SystemRandom
1719
import string
1820
import configparser
1921
import sys
22+
from typing import Optional
2023

2124

2225
def call_with_auth(node, user, password):
@@ -84,6 +87,40 @@ def test_auth(self, node, user, password):
8487
self.log.info('Wrong...')
8588
assert_equal(401, call_with_auth(node, user + 'wrong', password + 'wrong').status)
8689

90+
def test_rpccookieperms(self):
91+
p = {"owner": 0o600, "group": 0o640, "all": 0o644}
92+
93+
if platform.system() == 'Windows':
94+
self.log.info(f"Skip cookie file permissions checks as OS detected as: {platform.system()=}")
95+
return
96+
97+
self.log.info('Check cookie file permissions can be set using -rpccookieperms')
98+
99+
cookie_file_path = self.nodes[1].chain_path / '.cookie'
100+
PERM_BITS_UMASK = 0o777
101+
102+
def test_perm(perm: Optional[str]):
103+
if not perm:
104+
perm = 'owner'
105+
self.restart_node(1)
106+
else:
107+
self.restart_node(1, extra_args=[f"-rpccookieperms={perm}"])
108+
109+
file_stat = os.stat(cookie_file_path)
110+
actual_perms = file_stat.st_mode & PERM_BITS_UMASK
111+
expected_perms = p[perm]
112+
assert_equal(expected_perms, actual_perms)
113+
114+
# Remove any leftover rpc{user|password} config options from previous tests
115+
self.nodes[1].replace_in_config([("rpcuser", "#rpcuser"), ("rpcpassword", "#rpcpassword")])
116+
117+
self.log.info('Check default cookie permission')
118+
test_perm(None)
119+
120+
self.log.info('Check custom cookie permissions')
121+
for perm in ["owner", "group", "all"]:
122+
test_perm(perm)
123+
87124
def run_test(self):
88125
self.conf_setup()
89126
self.log.info('Check correctness of the rpcauth config option')
@@ -115,6 +152,8 @@ def run_test(self):
115152
(self.nodes[0].chain_path / ".cookie.tmp").mkdir()
116153
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
117154

155+
self.test_rpccookieperms()
156+
118157

119158
if __name__ == '__main__':
120159
HTTPBasicsTest().main()

0 commit comments

Comments
 (0)