File: test_cmd.py

package info (click to toggle)
ansible-core 2.20.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,760 kB
  • sloc: python: 175,447; cs: 4,929; sh: 4,732; xml: 34; makefile: 21
file content (18 lines) | stat: -rw-r--r-- 495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from __future__ import annotations

import pytest

from ansible.plugins.shell.cmd import ShellModule


@pytest.mark.parametrize('s, expected', [
    ['arg1', 'arg1'],
    [None, '""'],
    ['arg1 and 2', '^"arg1 and 2^"'],
    ['malicious argument\\"&whoami', '^"malicious argument\\\\^"^&whoami^"'],
    ['C:\\temp\\some ^%file% > nul', '^"C:\\temp\\some ^^^%file^% ^> nul^"']
])
def test_quote_args(s, expected):
    cmd = ShellModule()
    actual = cmd.quote(s)
    assert actual == expected