Skip to content

Commit

Permalink
Clear the environment in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Jan 24, 2025
1 parent 0d114f4 commit fcc8003
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
58 changes: 27 additions & 31 deletions salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2943,38 +2943,34 @@ def _cleanup_tempfile(path):
cmd_path = _cmd_quote(path, escape=False)
else:
cmd_path = path
if not env:
env = {}
if shell.lower() == "powershell":
mod_paths = [
pathlib.Path(
rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules'
),
pathlib.Path(
rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules'
),
]
else:
mod_paths = [
pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\Modules'),
pathlib.Path(
rf'{os.getenv("ProgramFiles")}\PowerShell\6.0.0\Modules'
),
pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\7\Modules'),
]
ps_module_path = [
pathlib.Path(x) for x in os.getenv("PSModulePath", "").split(";")
]
for mod_path in mod_paths:
if mod_path.exists():
if mod_path not in ps_module_path:
ps_module_path.append(mod_path)
mod_paths = ""
for mod_path in ps_module_path:
if mod_path:
mod_paths += f"{str(path)};"
# if not env:
# env = {}
# if shell.lower() == "powershell":
# mod_paths = [
# pathlib.Path(
# rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules'
# ),
# pathlib.Path(rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules'),
# ]
# else:
# mod_paths = [
# pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\Modules'),
# pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\6.0.0\Modules'),
# pathlib.Path(rf'{os.getenv("ProgramFiles")}\PowerShell\7\Modules'),
# ]
# ps_module_path = [
# pathlib.Path(x) for x in os.getenv("PSModulePath", "").split(";")
# ]
# for mod_path in mod_paths:
# if mod_path.exists():
# if mod_path not in ps_module_path:
# ps_module_path.append(mod_path)
# mod_paths = ""
# for mod_path in ps_module_path:
# if mod_path:
# mod_paths += f"{str(path)};"
# env.update({"PSModulePath": mod_paths})
env.update({"PSModulePath": ""})
# env.update({"PSModulePath": ""})
else:
cmd_path = _cmd_quote(path)

Expand Down
3 changes: 2 additions & 1 deletion tests/pytests/functional/modules/cmd/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_windows_script_args_powershell(cmd, shell, issue_56195):
)
script = "salt://issue-56195/test.ps1"

ret = cmd.script(source=script, args=args, shell=shell, saltenv="base")
ps_path = {"PSModulePath": ""}
ret = cmd.script(source=script, args=args, shell=shell, saltenv="base", env=ps_path)

import_result = cmd.run("Import-Module Microsoft.PowerShell.Security", shell=shell)
powershell_version = cmd.run("$PSVersionTable", shell=shell)
Expand Down

0 comments on commit fcc8003

Please sign in to comment.