|
11 | 11 | )
|
12 | 12 |
|
13 | 13 | import http.client
|
| 14 | +import os |
| 15 | +import platform |
14 | 16 | import urllib.parse
|
15 | 17 | import subprocess
|
16 | 18 | from random import SystemRandom
|
17 | 19 | import string
|
18 | 20 | import configparser
|
19 | 21 | import sys
|
| 22 | +from typing import Optional |
20 | 23 |
|
21 | 24 |
|
22 | 25 | def call_with_auth(node, user, password):
|
@@ -84,6 +87,40 @@ def test_auth(self, node, user, password):
|
84 | 87 | self.log.info('Wrong...')
|
85 | 88 | assert_equal(401, call_with_auth(node, user + 'wrong', password + 'wrong').status)
|
86 | 89 |
|
| 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 | + |
87 | 124 | def run_test(self):
|
88 | 125 | self.conf_setup()
|
89 | 126 | self.log.info('Check correctness of the rpcauth config option')
|
@@ -115,6 +152,8 @@ def run_test(self):
|
115 | 152 | (self.nodes[0].chain_path / ".cookie.tmp").mkdir()
|
116 | 153 | self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
|
117 | 154 |
|
| 155 | + self.test_rpccookieperms() |
| 156 | + |
118 | 157 |
|
119 | 158 | if __name__ == '__main__':
|
120 | 159 | HTTPBasicsTest().main()
|
0 commit comments