aboutsummaryrefslogtreecommitdiff
path: root/test/spec/LibreJSSpec.js
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-09-20 17:47:54 +1000
committerYuchen Pei <hi@ypei.me>2022-09-20 17:47:54 +1000
commit11dac1ce018cb22dc535249be605c974977287b2 (patch)
tree735ba9ef5ccd94bb2064ca61be02bffdf6b5c0f5 /test/spec/LibreJSSpec.js
parent4ea410b28eda7d22343b481c05a490996af24306 (diff)
adding tests of calls to reserved objects.
Diffstat (limited to 'test/spec/LibreJSSpec.js')
-rw-r--r--test/spec/LibreJSSpec.js17
1 files changed, 12 insertions, 5 deletions
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 () => {