Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions hub/test/m7-core-regressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../src/scrape';
import { executeExtractCall } from '../src/search-index';
import { classifyWafAndChallenge } from '../src/waf';
import { assertFastUnscaledSync } from './perf-budget';
import { postExtractHtml } from './post-fetch-wasm';

test('M7 Task 3: encodeBodyForWire and Hub scrape/extract decode ISO-8859-1 HTML while still rejecting real binary payloads', async () => {
Expand Down Expand Up @@ -1259,22 +1260,18 @@ test('M7 Challenger Iteration 2: linear ReDoS immunity in unhydratedCsrShell, po
['20k <div >', hostileDivsClosed],
['BOM JSON + 50k <', bomJsonHostile],
] as const) {
const t0 = performance.now();
const out = postExtractHtml(payload, 'https://example.com/', '');
const dt = performance.now() - t0;
// Same 5ms budget (unscaled); best of up to 5 samples, like the WAF checks below, so one sample delayed by the
// other test files sharing the runner's CPUs does not fail it, while a super-linear scan fails every sample.
const out = assertFastUnscaledSync(`postExtractHtml(${label})`, 5, () =>
postExtractHtml(payload, 'https://example.com/', ''),
);
assert.equal(out, null, `expected null for ${label}`);
assert.ok(dt < 5, `postExtractHtml(${label}) took ${dt.toFixed(2)}ms (>= 5ms)`);
}

const tJson0 = performance.now();
const sramJsonOut = postExtractHtml(
bomJsonHostile,
'https://docs.sram.com/en-US/publications/7E6x3h',
'',
const sramJsonOut = assertFastUnscaledSync('postExtractHtml(BOM JSON)', 5, () =>
postExtractHtml(bomJsonHostile, 'https://docs.sram.com/en-US/publications/7E6x3h', ''),
);
const dtJson = performance.now() - tJson0;
assert.equal(sramJsonOut, null);
assert.ok(dtJson < 5, `postExtractHtml(BOM JSON) took ${dtJson.toFixed(2)}ms (>= 5ms)`);

for (const [label, body] of [
['20k <style>', hostileStyles20k],
Expand Down