Files
bitvid/scripts/agent/fuzz-magnet-utils.mjs
T
google-labs-jules[bot] 5c2e9cd7f8 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/`.
2026-01-20 16:42:46 +00:00

37 lines
1.2 KiB
JavaScript

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);