use std::{fs, path::Path};
const TLS_FEATURES: &[&str] = &[
"tls-rustls",
"tls-rustls-ring",
"tls-rustls-ring-webpki",
"tls-rustls-ring-native-roots",
"tls-rustls-aws-lc-rs",
"tls-native-tls",
"runtime-tokio-rustls",
"runtime-tokio-native-tls",
];
#[test]
fn workspace_sqlx_dependency_enables_tls() {
let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("postrust-server should live under crates/postrust-server");
let manifest: toml::Value = fs::read_to_string(workspace_root.join("Cargo.toml"))
.expect("failed to read workspace Cargo.toml")
.parse()
.expect("workspace Cargo.toml is not valid TOML");
let features = manifest
.get("workspace")
.and_then(|w| w.get("dependencies"))
.and_then(|d| d.get("sqlx"))
.expect("workspace Cargo.toml should declare the sqlx dependency")
.get("features")
.and_then(toml::Value::as_array)
.expect("the sqlx dependency should declare a features list");
let enabled: Vec<&str> = features.iter().filter_map(toml::Value::as_str).collect();
assert!(
enabled.iter().any(|f| TLS_FEATURES.contains(f)),
"the workspace sqlx dependency must enable a TLS feature, or `sslmode=require` \
database URLs stop working and `sslmode=prefer` silently connects in cleartext.\n\
enabled: {enabled:?}\n\
expected one of: {TLS_FEATURES:?}"
);
}