feature_posix_fs_permissions.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2022-present 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  from test_framework.util import assert_equal
  13  
  14  
  15  class PosixFsPermissionsTest(BitcoinTestFramework):
  16      def set_test_params(self):
  17          self.setup_clean_chain = True
  18          self.num_nodes = 1
  19  
  20      def skip_test_if_missing_module(self):
  21          self.skip_if_platform_not_posix()
  22  
  23      def check_directory_permissions(self, dir):
  24          mode = os.lstat(dir).st_mode
  25          self.log.info(f"{stat.filemode(mode)} {dir}")
  26          assert_equal(mode, (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR))
  27  
  28      def check_file_permissions(self, file):
  29          mode = os.lstat(file).st_mode
  30          self.log.info(f"{stat.filemode(mode)} {file}")
  31          assert_equal(mode, (stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR))
  32  
  33      def run_test(self):
  34          self.stop_node(0)
  35          datadir = self.nodes[0].chain_path
  36          self.check_directory_permissions(datadir)
  37          walletsdir = self.nodes[0].wallets_path
  38          self.check_directory_permissions(walletsdir)
  39          debuglog = self.nodes[0].debug_log_path
  40          self.check_file_permissions(debuglog)
  41  
  42  
  43  if __name__ == '__main__':
  44      PosixFsPermissionsTest(__file__).main()
  45