コード例 #1
0
    def test_check_permissions(self):
        self.assertTrue(filesystem.check_permissions(self.probe_path, 0o744))

        with mock.patch('certbot.compat.filesystem.check_mode') as mock_mode:
            mock_mode.return_value = False
            self.assertFalse(filesystem.check_permissions(self.probe_path, 0o744))

        with mock.patch('certbot.compat.filesystem.check_owner') as mock_owner:
            mock_owner.return_value = False
            self.assertFalse(filesystem.check_permissions(self.probe_path, 0o744))
コード例 #2
0
def make_or_verify_dir(directory, mode=0o755, strict=False):
    """Make sure directory exists with proper permissions.

    :param str directory: Path to a directory.
    :param int mode: Directory mode.
    :param bool strict: require directory to be owned by current user

    :raises .errors.Error: if a directory already exists,
        but has wrong permissions or owner

    :raises OSError: if invalid or inaccessible file names and
        paths, or other arguments that have the correct type,
        but are not accepted by the operating system.

    """
    try:
        filesystem.makedirs(directory, mode)
    except OSError as exception:
        if exception.errno == errno.EEXIST:
            if strict and not filesystem.check_permissions(directory, mode):
                raise errors.Error(
                    "%s exists, but it should be owned by current user with"
                    " permissions %s" % (directory, oct(mode)))
        else:
            raise
コード例 #3
0
ファイル: log_test.py プロジェクト: saelinklaw/certbot
 def test_permissions(self):
     self.assertTrue(filesystem.check_permissions(self.handler.path, 0o600))