aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_posix_fs_permissions.py
blob: c5a543e97ae99f0f3427fb280c0d5f376a382461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# Copyright (c) 2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test file system permissions for POSIX platforms.
"""

import os
import stat

from test_framework.test_framework import BitcoinTestFramework


class PosixFsPermissionsTest(BitcoinTestFramework):
    def set_test_params(self):
        self.setup_clean_chain = True
        self.num_nodes = 1

    def skip_test_if_missing_module(self):
        self.skip_if_platform_not_posix()

    def check_directory_permissions(self, dir):
        mode = os.lstat(dir).st_mode
        self.log.info(f"{stat.filemode(mode)} {dir}")
        assert mode == (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    def check_file_permissions(self, file):
        mode = os.lstat(file).st_mode
        self.log.info(f"{stat.filemode(mode)} {file}")
        assert mode == (stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR)

    def run_test(self):
        self.stop_node(0)
        datadir = os.path.join(self.nodes[0].datadir, self.chain)
        self.check_directory_permissions(datadir)
        walletsdir = os.path.join(datadir, "wallets")
        self.check_directory_permissions(walletsdir)
        debuglog = os.path.join(datadir, "debug.log")
        self.check_file_permissions(debuglog)


if __name__ == '__main__':
    PosixFsPermissionsTest().main()