mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 20:32:27 +00:00
feat: add fuzz testing harness and fix repost builder
- Created generic fuzzing library `scripts/agent/fuzz-lib.mjs`. - Implemented fuzz targets for `nostrEventSchemas.js`, `dmDecryptor.js`, and `magnetUtils.js`. - Fixed `buildRepostEvent` to allow missing relay URLs for robustness. - Added crash reproducers to `examples/reproducers/`.
This commit is contained in:
1 parent
5726997475
commit
5c2e9cd7f8
26 files changed
+1041
-3
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { Fuzzer } from "./fuzz-lib.mjs";
|
||||
import { normalizeAndAugmentMagnet } from "../../js/magnetUtils.js";
|
||||
|
||||
// Mock global dependencies if needed
|
||||
if (typeof global.window === "undefined") {
|
||||
global.window = {
|
||||
location: { protocol: "https:" }
|
||||
};
|
||||
}
|
||||
|
||||
const fuzzer = new Fuzzer("magnet-utils");
|
||||
|
||||
async function test(fuzzer, state) {
|
||||
const rawValue = fuzzer.randBool() ?
|
||||
`magnet:?xt=urn:btih:${fuzzer.randString(40, "0123456789abcdef")}&dn=${fuzzer.randString(10)}` :
|
||||
fuzzer.randUnicodeString(100);
|
||||
|
||||
const options = {
|
||||
webSeed: fuzzer.randBool() ? fuzzer.randString(50) : fuzzer.randArray(() => fuzzer.randString(50), 0, 3),
|
||||
torrentUrl: fuzzer.randBool() ? fuzzer.randString(50) : undefined,
|
||||
xs: fuzzer.randBool() ? fuzzer.randString(50) : undefined,
|
||||
extraTrackers: fuzzer.randArray(() => fuzzer.randString(30), 0, 5),
|
||||
appProtocol: fuzzer.pick(["http:", "https:", "magnet:", "unknown:"]),
|
||||
logger: () => {} // No-op logger
|
||||
};
|
||||
|
||||
// Sometimes pass garbage options
|
||||
if (fuzzer.randBool()) {
|
||||
options.webSeed = fuzzer.randJSON();
|
||||
}
|
||||
|
||||
state.input = { rawValue, options };
|
||||
normalizeAndAugmentMagnet(rawValue, options);
|
||||
}
|
||||
|
||||
fuzzer.runFuzzLoop(5000, test);
|
||||
Reference in new issue
Block a user