use super::*;
#[tokio::test]
async fn it_should_execute_remote_command_on_real_ssh_server() {
let ssh_container = match RealSshServerContainer::start().await {
Ok(container) => container,
Err(e) => {
println!("Skipping real SSH command execution test - Docker/image not available: {e}");
return;
}
};
let client = SshTestBuilder::new()
.with_real_container(&ssh_container)
.build_client();
match client.wait_for_connectivity().await {
Ok(()) => {
println!("SSH connectivity established successfully");
}
Err(e) => {
println!("SSH connectivity failed - skipping command execution test: {e}");
return;
}
}
let test_message = "Hello SSH Integration Test";
let echo_command = format!("echo '{test_message}'");
let echo_result = client.execute(&echo_command);
let whoami_result = client.execute("whoami");
match echo_result {
Ok(output) => {
let trimmed_output = output.trim();
assert_eq!(
trimmed_output, test_message,
"Echo command output should match expected message"
);
}
Err(e) => {
panic!("Echo command execution should succeed with real server: {e}");
}
}
match whoami_result {
Ok(output) => {
let username = output.trim();
assert_eq!(
username,
ssh_container.username(),
"whoami should return the test username"
);
}
Err(e) => {
panic!("whoami command should succeed: {e}");
}
}
}
#[tokio::test]
async fn it_should_allow_users_to_override_default_options() {
let ssh_container = match RealSshServerContainer::start().await {
Ok(container) => container,
Err(e) => {
println!("Skipping SSH option override test - Docker/image not available: {e}");
return;
}
};
let client = SshTestBuilder::new()
.with_real_container(&ssh_container)
.build_client();
match client.wait_for_connectivity().await {
Ok(()) => {
println!("SSH connectivity established for option override test");
}
Err(e) => {
println!("SSH connectivity failed - skipping option override test: {e}");
return;
}
}
let result = client.execute_with_options(
"echo 'testing option override'",
&["ConnectTimeout=10"], );
match result {
Ok(output) => {
let trimmed = output.trim();
assert_eq!(
trimmed, "testing option override",
"Command should execute successfully with user-provided timeout"
);
println!("✓ User options override defaults - custom ConnectTimeout was used");
}
Err(e) => {
panic!("Command should succeed with user-provided options: {e}");
}
}
}
#[tokio::test]
async fn it_should_allow_users_to_override_strict_host_key_checking() {
let ssh_container = match RealSshServerContainer::start().await {
Ok(container) => container,
Err(e) => {
println!("Skipping default precedence test - Docker/image not available: {e}");
return;
}
};
let client = SshTestBuilder::new()
.with_real_container(&ssh_container)
.build_client();
match client.wait_for_connectivity().await {
Ok(()) => {
println!("SSH connectivity established for precedence test");
}
Err(e) => {
println!("SSH connectivity failed - skipping precedence test: {e}");
return;
}
}
let result = client.execute_with_options(
"echo 'testing strict host key override'",
&["StrictHostKeyChecking=yes"], );
match result {
Ok(output) => {
let trimmed = output.trim();
assert_eq!(
trimmed, "testing strict host key override",
"Command executes with user-provided StrictHostKeyChecking=yes"
);
println!("✓ User options override defaults - StrictHostKeyChecking=yes was used");
}
Err(e) => {
println!(
"Note: Command may fail with StrictHostKeyChecking=yes in some environments: {e}"
);
println!("This demonstrates that user overrides are respected by SSH");
}
}
}
#[tokio::test]
async fn it_should_allow_users_to_add_non_conflicting_ssh_options() {
let ssh_container = match RealSshServerContainer::start().await {
Ok(container) => container,
Err(e) => {
println!("Skipping non-conflicting options test - Docker/image not available: {e}");
return;
}
};
let client = SshTestBuilder::new()
.with_real_container(&ssh_container)
.build_client();
match client.wait_for_connectivity().await {
Ok(()) => {
println!("SSH connectivity established for non-conflicting options test");
}
Err(e) => {
println!("SSH connectivity failed - skipping non-conflicting options test: {e}");
return;
}
}
let result = client.execute_with_options(
"echo 'testing additional options'",
&[
"ServerAliveInterval=60", "ServerAliveCountMax=3", ],
);
match result {
Ok(output) => {
let trimmed = output.trim();
assert_eq!(
trimmed, "testing additional options",
"Command should succeed with additional non-conflicting options"
);
println!("✓ Non-conflicting options work correctly");
}
Err(e) => {
panic!("Command should succeed with non-conflicting options: {e}");
}
}
}