| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use std::path::Path; |
| 21 |
|
| 22 |
const OWNER_SCOPE: &str = "11111111-1111-1111-1111-111111111111"; |
| 23 |
|
| 24 |
fn policy() -> custom_pages::UrlPolicy { |
| 25 |
custom_pages::UrlPolicy::new( |
| 26 |
"https://u.makenot.work/alice/proj", |
| 27 |
[ |
| 28 |
"makenot.work".to_string(), |
| 29 |
"u.makenot.work".to_string(), |
| 30 |
"cdn.makenot.work".to_string(), |
| 31 |
], |
| 32 |
) |
| 33 |
.expect("the fixture policy is well-formed") |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
fn replay(dir: &Path, check: impl Fn(&str) + Copy + Send + 'static) -> usize { |
| 56 |
let Ok(entries) = std::fs::read_dir(dir) else { |
| 57 |
return 0; |
| 58 |
}; |
| 59 |
|
| 60 |
let mut count = 0; |
| 61 |
for entry in entries { |
| 62 |
let path = entry.expect("readable dir entry").path(); |
| 63 |
if !path.is_file() { |
| 64 |
continue; |
| 65 |
} |
| 66 |
|
| 67 |
if path.extension().is_some_and(|e| e == "md") { |
| 68 |
continue; |
| 69 |
} |
| 70 |
|
| 71 |
let bytes = std::fs::read(&path).expect("readable input"); |
| 72 |
|
| 73 |
let Ok(text) = std::str::from_utf8(&bytes) else { |
| 74 |
continue; |
| 75 |
}; |
| 76 |
let owned = text.to_string(); |
| 77 |
|
| 78 |
let handle = std::thread::Builder::new() |
| 79 |
.stack_size(256 * 1024 * 1024) |
| 80 |
.spawn(move || check(&owned)) |
| 81 |
.expect("spawning the replay thread"); |
| 82 |
|
| 83 |
|
| 84 |
assert!(handle.join().is_ok(), "oracle failed on {}", path.display()); |
| 85 |
count += 1; |
| 86 |
} |
| 87 |
count |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
fn replay_both(dir: &Path) -> usize { |
| 95 |
let html = replay(dir, |s: &str| { |
| 96 |
custom_pages::oracle::check_html(s, &policy()); |
| 97 |
}); |
| 98 |
let css = replay(dir, |s: &str| { |
| 99 |
custom_pages::oracle::check_css(s, OWNER_SCOPE, &policy()); |
| 100 |
}); |
| 101 |
assert_eq!(html, css, "the same directory yielded two different counts"); |
| 102 |
html |
| 103 |
} |
| 104 |
|
| 105 |
#[test] |
| 106 |
fn html_seeds_satisfy_the_oracle() { |
| 107 |
let n = replay( |
| 108 |
Path::new(env!("CARGO_MANIFEST_DIR")) |
| 109 |
.join("fuzz/seeds/html") |
| 110 |
.as_path(), |
| 111 |
|s: &str| custom_pages::oracle::check_html(s, &policy()), |
| 112 |
); |
| 113 |
assert!(n > 0, "no HTML seeds found; the corpus is the point"); |
| 114 |
} |
| 115 |
|
| 116 |
#[test] |
| 117 |
fn css_seeds_satisfy_the_oracle() { |
| 118 |
let n = replay( |
| 119 |
Path::new(env!("CARGO_MANIFEST_DIR")) |
| 120 |
.join("fuzz/seeds/css") |
| 121 |
.as_path(), |
| 122 |
|s: &str| custom_pages::oracle::check_css(s, OWNER_SCOPE, &policy()), |
| 123 |
); |
| 124 |
assert!(n > 0, "no CSS seeds found; the corpus is the point"); |
| 125 |
} |
| 126 |
|
| 127 |
#[test] |
| 128 |
fn every_past_crash_stays_fixed() { |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
let n = replay_both( |
| 133 |
Path::new(env!("CARGO_MANIFEST_DIR")) |
| 134 |
.join("fuzz/regressions") |
| 135 |
.as_path(), |
| 136 |
); |
| 137 |
println!("replayed {n} regression inputs"); |
| 138 |
} |
| 139 |
|