Lines
100 %
Functions
Branches
use super::*;
#[test]
fn cli_parses_defaults() {
let cli = Cli::try_parse_from(["nomisync-sshd"]).expect("defaults should parse");
assert!(
cli.bind.is_none(),
"bind unset on CLI falls through to env/default"
);
assert!(cli.host_key.is_none());
assert_eq!(cli.max_auth_attempts_per_ip, 6);
assert_eq!(cli.max_pubkey_attempts_per_ip, 30);
assert_eq!(cli.lockout_threshold, 3);
assert_eq!(cli.lockout_duration_secs, 900);
assert!(cli.public_hostname.is_none());
assert!(cli.public_port.is_none());
assert!(cli.host_fingerprint.is_none());
}
fn cli_accepts_explicit_bind_and_key_path() {
let cli = Cli::try_parse_from([
"nomisync-sshd",
"--bind",
"0.0.0.0:22",
"--host-key",
"/tmp/k",
])
.unwrap();
assert_eq!(cli.bind.unwrap().to_string(), "0.0.0.0:22");
assert_eq!(cli.host_key.unwrap().to_string_lossy(), "/tmp/k");
fn bind_defaults_to_loopback_without_cli_or_env() {
assert_eq!(pick_bind(None, None).unwrap().to_string(), DEFAULT_BIND);
fn bind_falls_back_to_env() {
let resolved = pick_bind(None, Some("127.0.0.1:9999".to_owned())).unwrap();
assert_eq!(resolved.to_string(), "127.0.0.1:9999");
fn bind_prefers_cli_over_env() {
let explicit: SocketAddr = "10.0.0.1:22".parse().unwrap();
let resolved = pick_bind(Some(explicit), Some("127.0.0.1:9999".to_owned())).unwrap();
assert_eq!(resolved, explicit);
assert_eq!(resolve_bind(Some(explicit)).unwrap(), explicit);
fn malformed_env_bind_is_an_error() {
assert!(pick_bind(None, Some("not-an-address".to_owned())).is_err());
fn host_key_defaults_without_cli_or_env() {
assert_eq!(pick_host_key(None, None), PathBuf::from(DEFAULT_HOST_KEY));
fn host_key_falls_back_to_env() {
let resolved = pick_host_key(None, Some(OsString::from("/tmp/env-key")));
assert_eq!(resolved, PathBuf::from("/tmp/env-key"));
fn host_key_prefers_cli_over_env() {
let explicit = PathBuf::from("/tmp/cli-key");
let resolved = pick_host_key(Some(explicit.clone()), Some(OsString::from("/tmp/env-key")));
assert_eq!(resolve_host_key(Some(explicit.clone())), explicit);