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. |
| 13 | import { writeFileSync } from 'node:fs'; |
| 14 | import { dirname, join } from 'node:path'; |
| 15 | import { fileURLToPath } from 'node:url'; |
| 16 | import { scrubText } from '../redact.js'; |
| 17 | import { LEAKS, TEMPLATES, expand } from './scrub_corpus.mjs'; |
| 18 | |
| 19 | const OUT = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'tests', 'data', 'lens_scrub.tsv'); |
| 20 | const rows = TEMPLATES.map(([t, id]) => JSON.stringify(t) + '\t' + JSON.stringify(scrubText(expand(t), id === 1)) + '\t' + id); |
| 21 | writeFileSync(OUT, rows.join('\n') + '\n'); |
| 22 | console.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. |
| 25 | const LEAK_OUT = join(dirname(OUT), 'lens_scrub_leaks.tsv'); |
| 26 | writeFileSync(LEAK_OUT, LEAKS.map(([t, g]) => JSON.stringify(t) + '\t' + JSON.stringify(g)).join('\n') + '\n'); |
| 27 | console.log('wrote ' + LEAKS.length + ' leaks to ' + LEAK_OUT); |