mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
fixes saltstack/salt#62377 groups with duplicate GIDs are not returned by get_group_list
This commit is contained in:
parent
fc7d0a9296
commit
eaa004dd64
3 changed files with 42 additions and 5 deletions
|
@ -294,8 +294,9 @@ def get_group_list(user, include_default=True):
|
|||
log.trace("Trying os.getgrouplist for '%s'", user)
|
||||
try:
|
||||
group_names = [
|
||||
grp.getgrgid(grpid).gr_name
|
||||
for grpid in os.getgrouplist(user, pwd.getpwnam(user).pw_gid)
|
||||
_group.gr_name
|
||||
for _group in grp.getgrall()
|
||||
if _group.gr_gid in os.getgrouplist(user, pwd.getpwnam(user).pw_gid)
|
||||
]
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
|
|
31
tests/pytests/functional/utils/user/test_get_group_list.py
Normal file
31
tests/pytests/functional/utils/user/test_get_group_list.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import logging
|
||||
|
||||
import pytest
|
||||
import salt.utils.user
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.destructive_test,
|
||||
pytest.mark.skip_if_not_root,
|
||||
pytest.mark.skip_on_windows,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def user():
|
||||
with pytest.helpers.create_account(create_group=True) as _account:
|
||||
yield _account
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def dupegroup(user):
|
||||
grpid = user.group.info.gid
|
||||
with pytest.helpers.create_group(name="dupegroup", gid=grpid) as _group:
|
||||
yield _group
|
||||
|
||||
|
||||
def test_get_group_list_with_duplicate_gid_group(user, dupegroup):
|
||||
group_list = salt.utils.user.get_group_list(user)
|
||||
assert user.group.info.name in group_list
|
||||
assert dupegroup.name in group_list
|
|
@ -192,6 +192,7 @@ def remove_stale_proxy_minion_cache_file(proxy_minion, minion_id=None):
|
|||
class TestGroup:
|
||||
sminion = attr.ib(repr=False)
|
||||
name = attr.ib()
|
||||
gid = attr.ib()
|
||||
_delete_group = attr.ib(init=False, repr=False, default=False)
|
||||
|
||||
@sminion.default
|
||||
|
@ -202,6 +203,10 @@ class TestGroup:
|
|||
def _default_name(self):
|
||||
return random_string("group-", uppercase=False)
|
||||
|
||||
@gid.default
|
||||
def _default_gid(self):
|
||||
return None
|
||||
|
||||
@property
|
||||
def info(self):
|
||||
return types.SimpleNamespace(**self.sminion.functions.group.info(self.name))
|
||||
|
@ -209,7 +214,7 @@ class TestGroup:
|
|||
def __enter__(self):
|
||||
group = self.sminion.functions.group.info(self.name)
|
||||
if not group:
|
||||
ret = self.sminion.functions.group.add(self.name)
|
||||
ret = self.sminion.functions.group.add(self.name, gid=self.gid)
|
||||
assert ret
|
||||
self._delete_group = True
|
||||
log.debug("Created system group: %s", self)
|
||||
|
@ -231,8 +236,8 @@ class TestGroup:
|
|||
|
||||
@pytest.helpers.register
|
||||
@contextmanager
|
||||
def create_group(name=attr.NOTHING, sminion=attr.NOTHING):
|
||||
with TestGroup(sminion=sminion, name=name) as group:
|
||||
def create_group(name=attr.NOTHING, sminion=attr.NOTHING, gid=attr.NOTHING):
|
||||
with TestGroup(sminion=sminion, name=name, gid=gid) as group:
|
||||
yield group
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue