use std::path::PathBuf;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn test_bssh_verbose_shows_agent_status() {
let output = Command::new("cargo")
.args(["build", "--release"])
.output()
.expect("Failed to build bssh");
assert!(
output.status.success(),
"Build should succeed: {:?}",
String::from_utf8_lossy(&output.stderr)
);
}
#[test]
fn test_fallback_when_no_agent_socket() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let key_path = temp_dir.path().join("id_ed25519");
std::fs::write(&key_path, mock_ed25519_private_key()).expect("Failed to write mock key");
assert!(key_path.exists(), "Key file should exist at {:?}", key_path);
}
#[test]
fn test_agent_socket_scenarios() {
let sock_not_set = std::env::var("SSH_AUTH_SOCK").is_err();
let _ = sock_not_set;
}
#[test]
fn test_use_agent_flag_with_empty_agent_fallback() {
let build_output = Command::new("cargo")
.args(["build"])
.output()
.expect("Failed to build");
if !build_output.status.success() {
eprintln!(
"Build failed: {}",
String::from_utf8_lossy(&build_output.stderr)
);
return;
}
let binary_path = PathBuf::from("target/debug/bssh");
assert!(
binary_path.exists(),
"Binary should exist at {:?}",
binary_path
);
let help_output = Command::new(&binary_path)
.args(["--help"])
.output()
.expect("Failed to run help");
assert!(
help_output.status.success(),
"Help should succeed: {:?}",
String::from_utf8_lossy(&help_output.stderr)
);
let help_text = String::from_utf8_lossy(&help_output.stdout);
assert!(
help_text.contains("--use-agent"),
"Help should mention --use-agent flag"
);
}
#[test]
fn test_auth_fallback_chain_documentation() {
let expected_fallback_order = [
"SSH agent (if SSH_AUTH_SOCK set AND agent has identities)",
"Specified key file (if -i flag provided)",
"SSH agent fallback (if available and has identities)",
"Default key files (~/.ssh/id_ed25519, id_rsa, id_ecdsa, id_dsa)",
];
assert_eq!(
expected_fallback_order.len(),
4,
"There should be 4 authentication fallback stages"
);
}
fn mock_ed25519_private_key() -> &'static str {
r#"-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACBTZXN0IG9ubHkga2V5IC0gbm90IHJlYWwAAAAAAAAAAAAAAAABAAAAgHRl
c3Qgb25seSBrZXkgLSBub3QgcmVhbAAAAEBTZXN0IG9ubHkga2V5IC0gbm90IHJlYWxUZX
N0IG9ubHkga2V5IC0gbm90IHJlYWwAAAALc3NoLWVkMjU1MTkAAAAgU2VzdCBvbmx5IGtl
eSAtIG5vdCByZWFsAAAAAAAAAAAAAA==
-----END OPENSSH PRIVATE KEY-----"#
}
#[test]
fn test_agent_check_timeout_behavior() {
}
#[test]
#[ignore] fn test_manual_empty_agent_scenario() {
println!("This test should be run manually with an empty SSH agent.");
println!("See the test documentation for setup instructions.");
}