add negative tests for _getgrall

This commit is contained in:
nicholasmhughes 2023-08-30 19:44:50 -04:00 committed by Gareth J. Greenaway
parent 0af4490c0f
commit 165621c166
2 changed files with 17 additions and 1 deletions

1
changelog/64888.fixed.md Normal file
View file

@ -0,0 +1 @@
Fixed grp.getgrall() in utils/user.py causing performance issues

View file

@ -9,7 +9,7 @@ import grp
import salt.utils.user
@pytest.fixture()
@pytest.fixture(scope="function")
def etc_group(tmp_path):
etcgrp = tmp_path / "etc" / "group"
etcgrp.parent.mkdir()
@ -34,3 +34,18 @@ def test__getgrall(etc_group):
grall = salt.utils.user._getgrall(root=str(etc_group.parent.parent))
assert grall == expected_grall
def test__getgrall_permission_denied(etc_group):
etc_group.chmod(0o000)
with pytest.raises(PermissionError):
salt.utils.user._getgrall(root=str(etc_group.parent.parent))
def test__getgrall_bad_format(etc_group):
with etc_group.open("a") as _fp:
_fp.write("\n# some comment here\n")
with pytest.raises(IndexError):
salt.utils.user._getgrall(root=str(etc_group.parent.parent))