From 11dac1ce018cb22dc535249be605c974977287b2 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 20 Sep 2022 17:47:54 +1000 Subject: adding tests of calls to reserved objects. --- test/spec/LibreJSSpec.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js index 73574e1..62a44a0 100644 --- a/test/spec/LibreJSSpec.js +++ b/test/spec/LibreJSSpec.js @@ -36,6 +36,10 @@ describe('LibreJS\' components', () => { let trivial = '1+1'; let nontrivial = 'function nt() { document.documentElement.innerHTML=""; nt(); }'; + // code calling reserved object is nontrivial + const nontrivialCall = 'eval();'; + // code calling anything else is trivial + const trivialCall = 'foo();'; let licensed = `// @license ${license.magnet} ${license.id}\n${nontrivial}\n// @license-end`; let unknownLicensed = `// @license ${unknownLicense.magnet} ${unknownLicense.id}\n${nontrivial}\n// @license-end`; let malformedLicensed = `// @license\n${nontrivial}`; @@ -160,14 +164,17 @@ describe('LibreJS\' components', () => { }); it('should accept trivial scripts', async () => { - let trivialInHtml = addScript(html, trivial); - let processed = await processHtml(trivialInHtml); - expect(extractScripts(processed, trivial)).toContain(trivial); + expect(extractScripts(await processHtml( + addScript(html, trivial)), trivial)).toContain(trivial); + expect(extractScripts(await processHtml( + addScript(html, trivialCall)), trivialCall)).toContain(trivialCall); }); it('should block non-trivial scripts', async () => { - let processed = await processHtml(nontrivialInHtml); - expect(extractScripts(processed, nontrivial)).not.toContain(nontrivial); + expect(extractScripts(await processHtml( + nontrivialInHtml), nontrivial)).not.toContain(nontrivial); + expect(extractScripts(await processHtml( + addScript(html, nontrivialCall)), nontrivialCall)).not.toContain(nontrivialCall); }); it('should accept scripts with known free license tags', async () => { -- cgit v1.2.3