Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇

2.1 KB
Raw Blame
// ©AngelaMos | 2026
// real_reports.rs

use lisdex_core::report::SanitizerReport;
use lisdex_report::advisory::{Provenance, provenance_of};

const FIXTURES: &str = concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/../lisdex-triage/tests/fixtures"
);

const CAPTURED_REPORTS: usize = 19;

fn captured() -> Vec<(String, String)> {
    let mut reports = Vec::new();
    let entries = std::fs::read_dir(FIXTURES)
        .unwrap_or_else(|err| panic!("fixture directory {FIXTURES}: {err}"));
    for entry in entries {
        let path = entry.expect("fixture entry").path();
        if path.extension().is_none_or(|ext| ext != "txt") {
            continue;
        }
        let name = path
            .file_stem()
            .expect("fixture stem")
            .to_string_lossy()
            .into_owned();
        let text = std::fs::read_to_string(&path)
            .unwrap_or_else(|err| panic!("fixture {}: {err}", path.display()));
        reports.push((name, text));
    }
    reports.sort();
    reports
}

#[test]
fn the_captured_corpus_is_present_and_every_report_parses() {
    let reports = captured();
    assert_eq!(
        reports.len(),
        CAPTURED_REPORTS,
        "the provenance control is only worth as much as the corpus behind it, and an empty or shrunken fixture directory would let every assertion below pass vacuously"
    );
    for (name, text) in &reports {
        assert!(
            SanitizerReport::parse(text).is_some(),
            "{name} is a verbatim capture from a running sanitizer; a guard that cannot parse it cannot judge it either"
        );
    }
}

#[test]
fn no_real_captured_report_is_mistaken_for_a_planted_benchmark_bug() {
    let mut marked = Vec::new();
    for (name, text) in captured() {
        let report = SanitizerReport::parse(&text).expect(&name);
        if provenance_of(&report) != Provenance::Field {
            marked.push(name);
        }
    }
    assert!(
        marked.is_empty(),
        "these reports were captured from real sanitizer runs with no benchmark instrumentation anywhere in them; marking one synthetic would silently withhold a genuine finding from disclosure: {marked:#?}"
    );
}