mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-15 04:17:41 +00:00
[PR #12163/f9d4f0ad backport][stable-13] Fix incus Windows modules with ansible-core 2.21 (#12179)
Fix incus Windows modules with ansible-core 2.21 (#12163)
* Fix incus Windows modules with ansible-core 2.21
* strip wrapper quotes for payload flags (-enc, -encodedcommand, -command, -c, -file, -f) before incus exec argv handoff, added changelogs
* Fixed some edge cases for powershell parsing
* Fixed changelogs
* Fixed pep8 format
* Added warning message when modifying direct commands
* Fixed changelogs fragement
(cherry picked from commit f9d4f0ad6b)
Co-authored-by: Simon Bouchard <simon.bouchard23@gmail.com>
This commit is contained in:
parent
1642519493
commit
06f2bf2aee
3 changed files with 186 additions and 11 deletions
|
|
@ -104,6 +104,156 @@ BUILD_CMD_TEST_CASES: list[dict[str, t.Any]] = [
|
|||
),
|
||||
output=[r"C:\CMD", "/c", "some-command /flag1 /flag2"],
|
||||
),
|
||||
dict(
|
||||
id="powershell encoded command strips quotes",
|
||||
input=dict(
|
||||
cmd="""powershell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -EncodedCommand 'cABhAHIAYQBtAA=='""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-ExecutionPolicy",
|
||||
"Unrestricted",
|
||||
"-EncodedCommand",
|
||||
"cABhAHIAYQBtAA==",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell encoded command strips double quotes",
|
||||
input=dict(
|
||||
cmd='''powershell -NoProfile -EncodedCommand "cABhAHIAYQBtAA=="''',
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-EncodedCommand",
|
||||
"cABhAHIAYQBtAA==",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell encoded command case-insensitive keyword",
|
||||
input=dict(
|
||||
cmd="""powershell -NoProfile -eNcOdEdCoMmAnD 'cABhAHIAYQBtAA=='""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-eNcOdEdCoMmAnD",
|
||||
"cABhAHIAYQBtAA==",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell encoded command keeps surrounding flags",
|
||||
input=dict(
|
||||
cmd="""powershell -NoProfile -EncodedCommand 'cABhAHIAYQBtAA==' -InputFormat None""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-EncodedCommand",
|
||||
"cABhAHIAYQBtAA==",
|
||||
"-InputFormat",
|
||||
"None",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -enc alias strips quotes",
|
||||
input=dict(
|
||||
cmd="""powershell -NoProfile -enc 'cABhAHIAYQBtAA=='""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-enc",
|
||||
"cABhAHIAYQBtAA==",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -Command with spaces in path",
|
||||
input=dict(
|
||||
cmd="""powershell.exe -NonInteractive -Command 'Write-Host "hello"; & \\'C:\\My Scripts\\run me.ps1\\''""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NonInteractive",
|
||||
"-Command",
|
||||
"""Write-Host "hello"; & \\'C:\\My Scripts\\run me.ps1\\'""",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -File with spaces in path",
|
||||
input=dict(
|
||||
cmd='''powershell.exe -NonInteractive -File "C:\\My Scripts\\run me.ps1"''',
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NonInteractive",
|
||||
"-File",
|
||||
r"C:\My Scripts\run me.ps1",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -File single quoted path with trailing args",
|
||||
input=dict(
|
||||
cmd="""powershell.exe -NoProfile -File 'C:\\My Scripts\\run me.ps1' -Arg1 value""",
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-File",
|
||||
r"C:\My Scripts\run me.ps1",
|
||||
"-Arg1",
|
||||
"value",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -F alias with spaces in path",
|
||||
input=dict(
|
||||
cmd='''powershell.exe -NoProfile -F "C:\\My Scripts\\run me.ps1"''',
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-F",
|
||||
r"C:\My Scripts\run me.ps1",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -Command outer double quotes",
|
||||
input=dict(
|
||||
cmd='''powershell.exe -NoProfile -Command "Write-Host 'hello world'"''',
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
"Write-Host 'hello world'",
|
||||
],
|
||||
),
|
||||
dict(
|
||||
id="powershell -Command empty quoted payload",
|
||||
input=dict(
|
||||
cmd='''powershell.exe -NoProfile -Command ""''',
|
||||
shell="powershell",
|
||||
),
|
||||
output=[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
"",
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue