mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-12-16 12:13:42 +00:00
disallow to create tree in case of unsafe run
This commit is contained in:
@ -5,8 +5,8 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.core.util import check_output, package_like, pretty_datetime, pretty_size, walk
|
||||
from ahriman.core.exceptions import InvalidOption, UnsafeRun
|
||||
from ahriman.core.util import check_output, check_user, package_like, pretty_datetime, pretty_size, walk
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
@ -51,6 +51,34 @@ def test_check_output_failure_log(mocker: MockerFixture) -> None:
|
||||
logger_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_check_user(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must check user correctly
|
||||
"""
|
||||
cwd = Path.cwd()
|
||||
mocker.patch("os.getuid", return_value=cwd.stat().st_uid)
|
||||
check_user(cwd)
|
||||
|
||||
|
||||
def test_check_user_no_directory(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail in case if no directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
check_user(Path.cwd())
|
||||
|
||||
|
||||
def test_check_user_exception(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if user differs
|
||||
"""
|
||||
cwd = Path.cwd()
|
||||
mocker.patch("os.getuid", return_value=cwd.stat().st_uid + 1)
|
||||
|
||||
with pytest.raises(UnsafeRun):
|
||||
check_user(cwd)
|
||||
|
||||
|
||||
def test_package_like(package_ahriman: Package) -> None:
|
||||
"""
|
||||
package_like must return true for archives
|
||||
|
||||
Reference in New Issue
Block a user