/ test / functional / feature_posix_fs_permissions.py
feature_posix_fs_permissions.py
 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 = self.nodes[0].chain_path
35          self.check_directory_permissions(datadir)
36          walletsdir = self.nodes[0].wallets_path
37          self.check_directory_permissions(walletsdir)
38          debuglog = self.nodes[0].debug_log_path
39          self.check_file_permissions(debuglog)
40  
41  
42  if __name__ == '__main__':
43      PosixFsPermissionsTest().main()