Test executing a command and ensuring the password is not in the stdout/stderr logs.
(caplog)
| 36 | @pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh") |
| 37 | @pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True) |
| 38 | def test_ssh_shell_exec_cmd(caplog): |
| 39 | """ |
| 40 | Test executing a command and ensuring the password |
| 41 | is not in the stdout/stderr logs. |
| 42 | """ |
| 43 | passwd = "12345" |
| 44 | opts = {"_ssh_version": (4, 9)} |
| 45 | host = "" |
| 46 | _shell = shell.Shell(opts=opts, host=host) |
| 47 | _shell.passwd = passwd |
| 48 | with patch.object(_shell, "_split_cmd", return_value=["echo", passwd]): |
| 49 | ret = _shell.exec_cmd(f"echo {passwd}") |
| 50 | assert not any([x for x in ret if passwd in str(x)]) |
| 51 | assert passwd not in caplog.text |
| 52 | |
| 53 | with patch.object(_shell, "_split_cmd", return_value=["ls", passwd]): |
| 54 | ret = _shell.exec_cmd(f"ls {passwd}") |
| 55 | assert not any([x for x in ret if passwd in str(x)]) |
| 56 | assert passwd not in caplog.text |
| 57 | |
| 58 | |
| 59 | @pytest.mark.parametrize( |