-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2355 from kamil-certat/fix_root_priviledges
FIX: intelmqsetup - never take ownership of /
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Tests for the intelmqsetup | ||
SPDX-FileCopyrightText: 2023 CERT.at GmbH <https://cert.at/> | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
""" | ||
|
||
import unittest | ||
from unittest import mock | ||
|
||
from intelmq.bin import intelmqsetup | ||
|
||
|
||
class TestOwnership(unittest.TestCase): | ||
@mock.patch("shutil.chown") | ||
def test_skip_changing_root_path_ownership(self, chown_mock): | ||
with mock.patch.object(intelmqsetup.Path, 'owner') as owner_mock: | ||
with mock.patch.object(intelmqsetup.Path, 'group') as group_mock: | ||
owner_mock.return_value = 'root' | ||
group_mock.return_value = 'root' | ||
intelmqsetup.change_owner('/', 'intelmq', 'intelmq') | ||
intelmqsetup.change_owner('//', 'intelmq', 'intelmq') | ||
intelmqsetup.change_owner('///', 'intelmq', 'intelmq') | ||
|
||
chown_mock.assert_not_called() | ||
|
||
@mock.patch("shutil.chown") | ||
def test_change_file_ownership(self, chown_mock): | ||
with mock.patch.object(intelmqsetup.Path, 'owner') as owner_mock: | ||
with mock.patch.object(intelmqsetup.Path, 'group') as group_mock: | ||
owner_mock.return_value = 'root' | ||
group_mock.return_value = 'root' | ||
intelmqsetup.change_owner('/the/path', 'intelmq', 'intelmq') | ||
|
||
chown_mock.assert_any_call('/the/path', user='intelmq') | ||
chown_mock.assert_any_call('/the/path', group='intelmq') |