mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add tests for _getgrall and local vs remote group handling
This commit is contained in:
parent
0be8c475d9
commit
0af4490c0f
2 changed files with 65 additions and 0 deletions
36
tests/pytests/functional/utils/user/test__getgrall.py
Normal file
36
tests/pytests/functional/utils/user/test__getgrall.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("grp")
|
||||
|
||||
import grp
|
||||
|
||||
import salt.utils.user
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def etc_group(tmp_path):
|
||||
etcgrp = tmp_path / "etc" / "group"
|
||||
etcgrp.parent.mkdir()
|
||||
etcgrp.write_text(
|
||||
dedent(
|
||||
"""games:x:50:
|
||||
docker:x:959:debian,salt
|
||||
salt:x:1000:"""
|
||||
)
|
||||
)
|
||||
return etcgrp
|
||||
|
||||
|
||||
def test__getgrall(etc_group):
|
||||
group_lines = [
|
||||
["games", "x", 50, []],
|
||||
["docker", "x", 959, ["debian", "salt"]],
|
||||
["salt", "x", 1000, []],
|
||||
]
|
||||
expected_grall = [grp.struct_group(comps) for comps in group_lines]
|
||||
|
||||
grall = salt.utils.user._getgrall(root=str(etc_group.parent.parent))
|
||||
|
||||
assert grall == expected_grall
|
29
tests/pytests/unit/utils/test_user.py
Normal file
29
tests/pytests/unit/utils/test_user.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
pytest.importorskip("grp")
|
||||
|
||||
import grp
|
||||
|
||||
import salt.utils.user
|
||||
|
||||
|
||||
def test_get_group_list():
|
||||
getpwname = SimpleNamespace(pw_gid=1000)
|
||||
getgrgid = MagicMock(side_effect=[SimpleNamespace(gr_name="remote")])
|
||||
group_lines = [
|
||||
["games", "x", 50, []],
|
||||
["salt", "x", 1000, []],
|
||||
]
|
||||
getgrall = [grp.struct_group(comps) for comps in group_lines]
|
||||
with patch("os.getgrouplist", MagicMock(return_value=[50, 1000, 12000])), patch(
|
||||
"pwd.getpwnam", MagicMock(return_value=getpwname)
|
||||
), patch("salt.utils.user._getgrall", MagicMock(return_value=getgrall)), patch(
|
||||
"grp.getgrgid", getgrgid
|
||||
):
|
||||
group_list = salt.utils.user.get_group_list("salt")
|
||||
assert group_list == ["games", "remote", "salt"]
|
||||
getgrgid.assert_called_once()
|
Loading…
Add table
Reference in a new issue