in libazureinit/src/provision/ssh.rs [353:389]
fn test_get_authorized_keys_path_from_sshd_success() {
let test_cases = vec![
(
"authorizedkeysfile .ssh/authorized_keys",
Some(".ssh/authorized_keys"),
),
(
"authorizedkeysfile .ssh/other_authorized_keys",
Some(".ssh/other_authorized_keys"),
),
(
"authorizedkeysfile /custom/path/to/keys",
Some("/custom/path/to/keys"),
),
("# No authorizedkeysfile line here", None), // Case with no match
];
for (stdout, expected_path) in test_cases {
let mock_runner = || Ok(create_output(0, stdout, "some stderr"));
let result: Option<Output> = run_sshd_command(mock_runner);
assert!(result.is_some(), "Expected a successful command output");
let output: Output = result.unwrap();
let stdout_str = String::from_utf8_lossy(&output.stdout);
assert_eq!(stdout_str, stdout);
let extracted_path: Option<String> =
extract_authorized_keys_file_path(&output.stdout);
assert_eq!(
extracted_path,
expected_path.map(|s| s.to_string()),
"Expected path extraction to match for stdout: {}",
stdout
);
}
}