From af906c795edde2a8994102348be581e1a0f225f4 Mon Sep 17 00:00:00 2001 From: twangboy Date: Wed, 16 Oct 2024 15:30:20 -0600 Subject: [PATCH] use whoami in the tests --- salt/platform/win.py | 2 +- tests/pytests/functional/utils/test_win_runas.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/salt/platform/win.py b/salt/platform/win.py index f2f26c14864..a521fdd974c 100644 --- a/salt/platform/win.py +++ b/salt/platform/win.py @@ -187,7 +187,7 @@ class HANDLE(wintypes.HANDLE): if self and not getattr(self, "closed", False): try: CloseHandle(self.Detach()) - except Exception: + except OSError: # Suppress the error when there is no handle (WinError 6) if ctypes.get_last_error() == 6: pass diff --git a/tests/pytests/functional/utils/test_win_runas.py b/tests/pytests/functional/utils/test_win_runas.py index e6f06d6948c..91a30afb736 100644 --- a/tests/pytests/functional/utils/test_win_runas.py +++ b/tests/pytests/functional/utils/test_win_runas.py @@ -18,21 +18,22 @@ def user(): yield account -def test_runas(user): - cmd = "hostname && echo foo" +def test_compound_runas(user): + cmd = "hostname && whoami" result = win_runas.runas( cmdLine=cmd, username=user.username, password=user.password, ) - assert "foo" in result["stdout"] + assert user.username in result["stdout"] -def test_runas_unpriv(user): - cmd = "hostname && echo foo" +def test_compound_runas_unpriv(user): + cmd = "hostname && whoami" + print(user.username) result = win_runas.runas_unpriv( cmd=cmd, username=user.username, password=user.password, ) - assert "foo" in result["stdout"] + assert user.username in result["stdout"]