#[test]
fn test_timeout_wrapper_formatting() {
use ssh_mcp::ssh::command::wrap_command_with_timeout;
let cmd = wrap_command_with_timeout("echo hello", 10.0);
assert!(cmd.contains("timeout -k 2s 10s"));
assert!(cmd.contains("sh -lc")); assert!(cmd.contains("echo hello"));
let cmd = wrap_command_with_timeout("sleep 30", 2.0);
assert!(cmd.contains("timeout -k 2s 2s"));
assert!(cmd.contains("sh -lc"));
assert!(cmd.contains("sleep 30"));
}
#[test]
fn test_wrap_command_with_zero_duration() {
use ssh_mcp::ssh::command::wrap_command_with_timeout;
let cmd = wrap_command_with_timeout("echo test", 0.0);
assert!(cmd.contains("timeout -k 2s 0s"));
assert!(cmd.contains("sh -lc"));
}
#[test]
fn test_wrap_command_with_fractional_duration() {
use ssh_mcp::ssh::command::wrap_command_with_timeout;
let cmd = wrap_command_with_timeout("sleep 1", 0.5);
assert!(cmd.contains("timeout -k 2s 0.5s"));
assert!(cmd.contains("sh -lc"));
let cmd = wrap_command_with_timeout("sleep 1", 1.5);
assert!(cmd.contains("timeout -k 2s 1.5s"));
assert!(cmd.contains("sh -lc"));
}
#[test]
fn test_escape_for_timeout_wrapper() {
use ssh_mcp::ssh::sanitize::escape_for_timeout_wrapper;
assert_eq!(
escape_for_timeout_wrapper("echo 'hello'"),
"echo '\"'\"'hello'\"'\"'"
);
assert_eq!(escape_for_timeout_wrapper(r"echo \$HOME"), r"echo \$HOME");
assert_eq!(escape_for_timeout_wrapper("echo `date`"), "echo `date`");
}
#[test]
fn test_escape_command_for_shell() {
use ssh_mcp::ssh::sanitize::escape_command_for_shell;
assert_eq!(escape_command_for_shell("echo $HOME"), r"echo \$HOME");
assert_eq!(escape_command_for_shell("echo `date`"), r"echo \`date\`");
assert_eq!(escape_command_for_shell("echo (test)"), r"echo \(test\)");
}
#[tokio::test]
#[ignore = "requires real SSH server with configured credentials"]
async fn test_ssh_connection_timeout_wrapper() {
unreachable!("This test requires SSH server setup");
}
#[tokio::test]
#[ignore = "requires SSH server with su password configured"]
async fn test_su_shell_timeout_wrapper() {
unreachable!("This test requires SSH server with root access");
}
#[tokio::test]
#[ignore = "requires SSH server without timeout command"]
async fn test_timeout_wrapper_fallback_to_pkill() {
unreachable!("This test requires SSH server without timeout command");
}