virnetsockettest: Increase coverage

Add test cases for quotes appearing in the netcat parameter,
for the default behavior of proxy=auto where virt-ssh-helper
is used if available, and for proxy=native.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2022-02-09 19:32:49 +01:00
parent 5068a76493
commit 6901d92ec4

View File

@ -678,10 +678,71 @@ mymain(void)
"'''\\''n c'\\'''' $ARG -U /tmp/socket"
"'\n",
};
VIR_WARNINGS_RESET
if (virTestRun("SSH test 7", testSocketSSH, &sshData7) < 0)
ret = -1;
struct testSSHData sshData8 = {
.nodename = "somehost",
.netcat = "n'c",
.path = "/tmp/socket",
.expectOut = "-T -e none -- somehost sh -c '"
"if '''\\''n'\\''\\'\\'''\\''c'\\'''' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;"
"else "
"ARG=;"
"fi;"
"'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U /tmp/socket"
"'\n",
};
if (virTestRun("SSH test 8", testSocketSSH, &sshData8) < 0)
ret = -1;
struct testSSHData sshData9 = {
.nodename = "somehost",
.netcat = "n\"c",
.path = "/tmp/socket",
.expectOut = "-T -e none -- somehost sh -c '"
"if '''\\''n\"c'\\'''' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;"
"else "
"ARG=;"
"fi;"
"'''\\''n\"c'\\'''' $ARG -U /tmp/socket"
"'\n",
};
if (virTestRun("SSH test 9", testSocketSSH, &sshData9) < 0)
ret = -1;
struct testSSHData sshData10 = {
.nodename = "somehost",
.path = "/tmp/socket",
.expectOut = "-T -e none -- somehost sh -c '"
"which virt-ssh-helper 1>/dev/null 2>&1; "
"if test $? = 0; then "
" virt-ssh-helper -r 'qemu:///session'; "
"else"
" if 'nc' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;"
"else "
"ARG=;"
"fi;"
"'nc' $ARG -U /tmp/socket; "
"fi"
"'\n"
};
if (virTestRun("SSH test 10", testSocketSSH, &sshData10) < 0)
ret = -1;
struct testSSHData sshData11 = {
.nodename = "somehost",
.proxy = VIR_NET_CLIENT_PROXY_NATIVE,
.expectOut = "-T -e none -- somehost sh -c '"
"virt-ssh-helper -r 'qemu:///session'"
"'\n"
};
if (virTestRun("SSH test 11", testSocketSSH, &sshData11) < 0)
ret = -1;
VIR_WARNINGS_RESET
#endif
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;