use super::{probe_zone_dir, ready_check_label};
#[test]
fn test_ready_check_label_is_non_sensitive() {
assert_eq!(ready_check_label("zone_dir", true), "zone_dir: ok");
assert_eq!(ready_check_label("zone_dir", false), "zone_dir: error");
assert_eq!(ready_check_label("rndc", true), "rndc: ok");
assert_eq!(ready_check_label("rndc", false), "rndc: error");
for ok in [true, false] {
let label = ready_check_label("zone_dir", ok);
assert!(!label.contains('/'), "label leaked a path: {label}");
}
}
#[tokio::test]
async fn test_probe_zone_dir_rejects_non_normalized_paths() {
assert!(!probe_zone_dir("relative/zones").await);
assert!(!probe_zone_dir("").await);
assert!(!probe_zone_dir("/var/lib/bind/../../etc").await);
assert!(!probe_zone_dir("/var/lib/bind/..").await);
assert!(!probe_zone_dir("/var/lib/./bind").await);
}
#[tokio::test]
async fn test_probe_zone_dir_rejects_missing_directory() {
assert!(!probe_zone_dir("/nonexistent-bindcar-zone-dir-for-tests").await);
}
#[tokio::test]
async fn test_probe_zone_dir_rejects_regular_file() {
let file = tempfile::NamedTempFile::new().expect("create temp file");
let path = file.path().to_str().expect("temp path is valid utf-8");
assert!(!probe_zone_dir(path).await);
}
#[tokio::test]
async fn test_probe_zone_dir_accepts_existing_directory() {
let dir = tempfile::tempdir().expect("create temp dir");
let path = dir.path().to_str().expect("temp path is valid utf-8");
assert!(probe_zone_dir(path).await);
}
#[test]
fn test_check_tls_support_rejects_configured_tls_in_a_build_without_it() {
let err = super::check_tls_support(true, false)
.expect_err("configured TLS on a non-TLS build must be refused");
let msg = err.to_string();
assert!(
msg.contains("tls"),
"the error must name the missing feature: {msg}"
);
assert!(
msg.contains("--features tls") || msg.contains("feature"),
"the error must say how to fix it: {msg}"
);
}
#[test]
fn test_check_tls_support_allows_the_supported_combinations() {
assert!(super::check_tls_support(true, true).is_ok());
assert!(super::check_tls_support(false, true).is_ok());
assert!(super::check_tls_support(false, false).is_ok());
}
#[test]
fn test_tls_supported_reflects_the_build() {
assert_eq!(super::TLS_SUPPORTED, cfg!(feature = "tls"));
}