Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/lens/js/test/gen_scrub_oracle.mjs

1.8 KiB, 6 runs

created by r1870400018:65618, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// gen_scrub_oracle.mjs -- writes `fe2o3_net/tests/data/lens_scrub.tsv`, the table that holds the
2// content scrubber of `redact.js` to the same answers in Rust (`lens::Shapes`) and anywhere else.
3//
4// node test/gen_scrub_oracle.mjs
5//
6// It writes `lens_scrub_leaks.tsv` beside it, the corpus's `LEAKS`.
7//
8// One line a case: `template <TAB> output <TAB> isId`. The template and the output are JSON
9// strings. A template is expanded by the rule in `scrub_corpus.mjs` (the table holds no credential,
10// only the recipe for one), the expansion is scrubbed by the base scrubber of `redact.js` (no
11// caller shapes, pairs or id fields), and `isId` is 1 where the entropy catch is suppressed. A
12// reader holds itself to the table by expanding each template, scrubbing it, and comparing.
13import { writeFileSync } from 'node:fs';
14import { dirname, join } from 'node:path';
15import { fileURLToPath } from 'node:url';
16import { scrubText } from '../redact.js';
17import { LEAKS, TEMPLATES, expand } from './scrub_corpus.mjs';
18
19const OUT = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'tests', 'data', 'lens_scrub.tsv');
20const rows = TEMPLATES.map(([t, id]) => JSON.stringify(t) + '\t' + JSON.stringify(scrubText(expand(t), id === 1)) + '\t' + id);
21writeFileSync(OUT, rows.join('\n') + '\n');
22console.log('wrote ' + rows.length + ' cases to ' + OUT);
23// The leaks: `template <TAB> gone`, both JSON strings, `gone` a template too. Its expansion must not
24// stand in the scrubbed expansion of the template, and a second scrub must change nothing.
25const LEAK_OUT = join(dirname(OUT), 'lens_scrub_leaks.tsv');
26writeFileSync(LEAK_OUT, LEAKS.map(([t, g]) => JSON.stringify(t) + '\t' + JSON.stringify(g)).join('\n') + '\n');
27console.log('wrote ' + LEAKS.length + ' leaks to ' + LEAK_OUT);