Skip to content

Commit c9ba4f9

Browse files
committed
test: Add test for file system permissions
1 parent 581f16e commit c9ba4f9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test file system permissions for POSIX platforms.
6+
"""
7+
8+
import os
9+
import stat
10+
11+
from test_framework.test_framework import BitcoinTestFramework
12+
13+
14+
class PosixFsPermissionsTest(BitcoinTestFramework):
15+
def set_test_params(self):
16+
self.setup_clean_chain = True
17+
self.num_nodes = 1
18+
19+
def skip_test_if_missing_module(self):
20+
self.skip_if_platform_not_posix()
21+
22+
def check_directory_permissions(self, dir):
23+
mode = os.lstat(dir).st_mode
24+
self.log.info(f"{stat.filemode(mode)} {dir}")
25+
assert mode == (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
26+
27+
def check_file_permissions(self, file):
28+
mode = os.lstat(file).st_mode
29+
self.log.info(f"{stat.filemode(mode)} {file}")
30+
assert mode == (stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR)
31+
32+
def run_test(self):
33+
self.stop_node(0)
34+
datadir = os.path.join(self.nodes[0].datadir, self.chain)
35+
self.check_directory_permissions(datadir)
36+
walletsdir = os.path.join(datadir, "wallets")
37+
self.check_directory_permissions(walletsdir)
38+
debuglog = os.path.join(datadir, "debug.log")
39+
self.check_file_permissions(debuglog)
40+
41+
42+
if __name__ == '__main__':
43+
PosixFsPermissionsTest().main()

test/functional/test_framework/test_framework.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,11 @@ def skip_if_platform_not_linux(self):
880880
if platform.system() != "Linux":
881881
raise SkipTest("not on a Linux system")
882882

883+
def skip_if_platform_not_posix(self):
884+
"""Skip the running test if we are not on a POSIX platform"""
885+
if os.name != 'posix':
886+
raise SkipTest("not on a POSIX system")
887+
883888
def skip_if_no_bitcoind_zmq(self):
884889
"""Skip the running test if bitcoind has not been compiled with zmq support."""
885890
if not self.is_zmq_compiled():

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
'p2p_addrv2_relay.py',
212212
'p2p_compactblocks_hb.py',
213213
'p2p_disconnect_ban.py',
214+
'feature_posix_fs_permissions.py',
214215
'rpc_decodescript.py',
215216
'rpc_blockchain.py',
216217
'rpc_deprecated.py',

0 commit comments

Comments
 (0)