use dsfb_database::live_mysql::AllowedMySqlQuery;
use sha2::{Digest, Sha256};
const PINNED_SHA256: &str =
"f6581d915ba6707669f839e317beaa13d6cf06cbc672a07b8dae3226de12a7f1";
fn sha256_hex(bytes: &[u8]) -> String {
let mut h = Sha256::new();
h.update(bytes);
let d = h.finalize();
d.iter().map(|b| format!("{:02x}", b)).collect()
}
#[test]
fn allow_list_is_pinned() {
let concat = AllowedMySqlQuery::sql_concat_for_lock();
let got = sha256_hex(concat.as_bytes());
assert_eq!(
got, PINNED_SHA256,
"AllowedMySqlQuery allow-list drifted from pinned SHA-256. \
Expected {}, got {}. Update the paper's §Live-Eval MySQL \
subsection and spec/permissions.mysql.sql together with the \
new hash.",
PINNED_SHA256, got
);
}
#[test]
fn allow_list_cardinality_is_four() {
assert_eq!(
AllowedMySqlQuery::ALL.len(),
4,
"AllowedMySqlQuery variant count drifted; update the paper §Live-Eval MySQL table"
);
}
#[test]
fn every_variant_is_unique() {
let mut seen = std::collections::HashSet::new();
for q in AllowedMySqlQuery::ALL {
assert!(
seen.insert(q),
"duplicate variant in AllowedMySqlQuery::ALL: {:?}",
q
);
}
}