From e725dfc3f65d39599314a4ae267ff3e4366c4b1e Mon Sep 17 00:00:00 2001 From: Barney Sowood Date: Tue, 14 Jan 2025 15:54:14 +0000 Subject: [PATCH 1/5] Run failing test with runneradmin rather than administrator as user --- tests/pytests/unit/modules/test_win_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytests/unit/modules/test_win_file.py b/tests/pytests/unit/modules/test_win_file.py index 19924c398737..a87a4cd95d1f 100644 --- a/tests/pytests/unit/modules/test_win_file.py +++ b/tests/pytests/unit/modules/test_win_file.py @@ -127,8 +127,8 @@ def test_uid_to_user_empty(): def test_user_to_uid(): - result = win_file.user_to_uid("Administrator") - expected = salt.utils.win_dacl.get_sid_string("Administrator") + result = win_file.user_to_uid("runneradmin") + expected = salt.utils.win_dacl.get_sid_string("runneradmin") assert result == expected From 2d923ec7895eada450c73731fb84f2e1bf9131b8 Mon Sep 17 00:00:00 2001 From: Barney Sowood Date: Tue, 14 Jan 2025 17:22:46 +0000 Subject: [PATCH 2/5] Revert and check for failure --- tests/pytests/unit/modules/test_win_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytests/unit/modules/test_win_file.py b/tests/pytests/unit/modules/test_win_file.py index a87a4cd95d1f..19924c398737 100644 --- a/tests/pytests/unit/modules/test_win_file.py +++ b/tests/pytests/unit/modules/test_win_file.py @@ -127,8 +127,8 @@ def test_uid_to_user_empty(): def test_user_to_uid(): - result = win_file.user_to_uid("runneradmin") - expected = salt.utils.win_dacl.get_sid_string("runneradmin") + result = win_file.user_to_uid("Administrator") + expected = salt.utils.win_dacl.get_sid_string("Administrator") assert result == expected From 062eefbfc3c65ba0d42e546160c0ff3b266059ae Mon Sep 17 00:00:00 2001 From: Barney Sowood Date: Tue, 14 Jan 2025 17:46:57 +0000 Subject: [PATCH 3/5] add comment to actually make tests run? --- tests/pytests/unit/modules/test_win_file.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pytests/unit/modules/test_win_file.py b/tests/pytests/unit/modules/test_win_file.py index 19924c398737..32a27e4ab199 100644 --- a/tests/pytests/unit/modules/test_win_file.py +++ b/tests/pytests/unit/modules/test_win_file.py @@ -127,6 +127,7 @@ def test_uid_to_user_empty(): def test_user_to_uid(): + # Add change to ensure tests run result = win_file.user_to_uid("Administrator") expected = salt.utils.win_dacl.get_sid_string("Administrator") assert result == expected From 5be1db3f58809eb27d53e14197456315834ef2d4 Mon Sep 17 00:00:00 2001 From: Barney Sowood Date: Tue, 14 Jan 2025 19:06:17 +0000 Subject: [PATCH 4/5] testing to check user status --- noxfile.py | 15 ++++----------- tests/pytests/test_get_users.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 tests/pytests/test_get_users.py diff --git a/noxfile.py b/noxfile.py index 3d39c7438777..c3d90bbbc4cc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1063,19 +1063,12 @@ def _ci_test(session, transport, onedir=False): if onedir: env["ONEDIR_TESTRUN"] = "1" chunks = { - "pkg": [ - "tests/pytests/pkg", - ], + "pkg": [], "unit": [ - "tests/unit", - "tests/pytests/unit", - ], - "functional": [ - "tests/pytests/functional", - ], - "scenarios": [ - "tests/pytests/scenarios", + "tests/pytests/test_get_users.py", ], + "functional": [], + "scenarios": [], } test_group_number = os.environ.get("TEST_GROUP") or "1" diff --git a/tests/pytests/test_get_users.py b/tests/pytests/test_get_users.py new file mode 100644 index 000000000000..0832be6e747a --- /dev/null +++ b/tests/pytests/test_get_users.py @@ -0,0 +1,25 @@ +import json +import subprocess +import sys + +import pytest + + +def test_get_local_users(): + if sys.platform != "win32": + pytest.skip("This test only runs on Windows") + + ps_command = "Get-LocalUser | Select-Object Name, Enabled | ConvertTo-Json" + result = subprocess.run( + ["powershell", "-Command", ps_command], capture_output=True, text=True + ) + + print(result.stdout) + assert result.returncode == 0, f"PowerShell command failed: {result.stderr}" + + # Parse the JSON output + users = json.loads(result.stdout) + + # Make test fail by asserting there are no disabled users + disabled_users = [user for user in users if not user["Enabled"]] + assert not disabled_users, f"Found disabled users: {disabled_users}" From 6e15e6f61151e26fe195ea006b29eaeb569c02c4 Mon Sep 17 00:00:00 2001 From: Barney Sowood Date: Tue, 14 Jan 2025 20:04:04 +0000 Subject: [PATCH 5/5] Force test failure --- tests/pytests/test_get_users.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/pytests/test_get_users.py b/tests/pytests/test_get_users.py index 0832be6e747a..caf316299055 100644 --- a/tests/pytests/test_get_users.py +++ b/tests/pytests/test_get_users.py @@ -1,4 +1,3 @@ -import json import subprocess import sys @@ -15,11 +14,4 @@ def test_get_local_users(): ) print(result.stdout) - assert result.returncode == 0, f"PowerShell command failed: {result.stderr}" - - # Parse the JSON output - users = json.loads(result.stdout) - - # Make test fail by asserting there are no disabled users - disabled_users = [user for user in users if not user["Enabled"]] - assert not disabled_users, f"Found disabled users: {disabled_users}" + assert False