mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-02-04 12:29:47 +00:00
fix: use effective uid instead of uid
This commit is contained in:
@@ -160,7 +160,7 @@ def test_check_user(repository_id: RepositoryId, mocker: MockerFixture) -> None:
|
||||
must check user correctly
|
||||
"""
|
||||
paths = RepositoryPaths(Path.cwd(), repository_id)
|
||||
mocker.patch("os.getuid", return_value=paths.root_owner[0])
|
||||
mocker.patch("os.geteuid", return_value=paths.root_owner[0])
|
||||
check_user(paths.root, unsafe=False)
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ def test_check_user_exception(repository_id: RepositoryId, mocker: MockerFixture
|
||||
must raise exception if user differs
|
||||
"""
|
||||
paths = RepositoryPaths(Path.cwd(), repository_id)
|
||||
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
|
||||
mocker.patch("os.geteuid", return_value=paths.root_owner[0] + 1)
|
||||
|
||||
with pytest.raises(UnsafeRunError):
|
||||
check_user(paths.root, unsafe=False)
|
||||
@@ -188,7 +188,7 @@ def test_check_user_unsafe(repository_id: RepositoryId, mocker: MockerFixture) -
|
||||
must skip check if unsafe flag is set
|
||||
"""
|
||||
paths = RepositoryPaths(Path.cwd(), repository_id)
|
||||
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
|
||||
mocker.patch("os.geteuid", return_value=paths.root_owner[0] + 1)
|
||||
check_user(paths.root, unsafe=True)
|
||||
|
||||
|
||||
|
||||
@@ -198,8 +198,8 @@ def test_preserve_owner(tmp_path: Path, repository_id: RepositoryId, mocker: Moc
|
||||
"""
|
||||
must preserve file owner during operations
|
||||
"""
|
||||
mocker.patch("os.getuid", return_value=0)
|
||||
mocker.patch("os.getgid", return_value=0)
|
||||
mocker.patch("os.geteuid", return_value=0)
|
||||
mocker.patch("os.getegid", return_value=0)
|
||||
seteuid_mock = mocker.patch("os.seteuid")
|
||||
setegid_mock = mocker.patch("os.setegid")
|
||||
|
||||
@@ -214,8 +214,8 @@ def test_preserve_owner_exception(tmp_path: Path, repository_id: RepositoryId, m
|
||||
"""
|
||||
must return to original uid and gid even during exception
|
||||
"""
|
||||
mocker.patch("os.getuid", return_value=0)
|
||||
mocker.patch("os.getgid", return_value=0)
|
||||
mocker.patch("os.geteuid", return_value=0)
|
||||
mocker.patch("os.getegid", return_value=0)
|
||||
mocker.patch("pathlib.Path.mkdir", side_effect=Exception)
|
||||
seteuid_mock = mocker.patch("os.seteuid")
|
||||
setegid_mock = mocker.patch("os.setegid")
|
||||
@@ -232,8 +232,8 @@ def test_preserve_owner_non_root(tmp_path: Path, repository_id: RepositoryId, mo
|
||||
"""
|
||||
must skip processing if user is not root
|
||||
"""
|
||||
mocker.patch("os.getuid", return_value=42)
|
||||
mocker.patch("os.getgid", return_value=42)
|
||||
mocker.patch("os.geteuid", return_value=42)
|
||||
mocker.patch("os.getegid", return_value=42)
|
||||
repository_paths = RepositoryPaths(tmp_path, repository_id)
|
||||
seteuid_mock = mocker.patch("os.seteuid")
|
||||
setegid_mock = mocker.patch("os.setegid")
|
||||
|
||||
Reference in New Issue
Block a user