diff options
author | hackademix <giorgio@maone.net> | 2019-03-26 22:47:00 +0100 |
---|---|---|
committer | hackademix <giorgio@maone.net> | 2019-03-26 22:47:00 +0100 |
commit | a99f7d91acf0fe82a8c82440c28ffc5fe379924a (patch) | |
tree | 594351262b1f3578c8f1fad0250fd436c647a41a /test/spec | |
parent | 9884643742b54b88f94111d62f5e89a12a60e604 (diff) |
Automated regression tests for whitelist and blacklist management, including wildcards.
Diffstat (limited to 'test/spec')
-rw-r--r-- | test/spec/LibreJSSpec.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js index 57c7f65..43f37a7 100644 --- a/test/spec/LibreJSSpec.js +++ b/test/spec/LibreJSSpec.js @@ -38,15 +38,53 @@ describe("LibreJS' components", () => { 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}`; - let tab, documentUrl; beforeAll(async () => { let url = browser.extension.getURL("/test/resources/index.html"); tab = (await browser.tabs.query({url}))[0] || (await browser.tabs.create({url})); documentUrl = url; + }); + describe("The whitelist/blacklist manager", () => { + let {ListManager, ListStore, Storage} = LibreJS; + let lm = new ListManager(new ListStore("_test.whitelist", Storage.CSV), new ListStore("_test.blacklist", Storage.CSV), new Set()); + let forgot = ["http://formerly.whitelist.ed/", "http://formerly.blacklist.ed/"]; + + beforeAll(async () => { + await lm.whitelist("https://fsf.org/*", "https://*.gnu.org/*", forgot[0]); + await lm.blacklist("https://*.evil.gnu.org/*", "https://verybad.com/*", forgot[1]); + }); + + it("Should handle basic CRUD operations", async () => { + expect(lm.getStatus(forgot[0])).toBe("whitelisted"); + expect(lm.getStatus(forgot[1])).toBe("blacklisted"); + + await lm.forget(...forgot); + + for (let url of forgot) { + expect(lm.getStatus(url)).toBe("unknown"); + } + }); + + it("Should support full path wildcards", () => { + expect(lm.getStatus("https://unknown.org")).toBe("unknown"); + expect(lm.getStatus("https://fsf.org/some/path")).toBe("whitelisted"); + expect(lm.getStatus("https://fsf.org/")).toBe("whitelisted"); + expect(lm.getStatus("https://fsf.org")).toBe("whitelisted"); + expect(lm.getStatus("https://subdomain.fsf.org")).toBe("unknown"); + expect(lm.getStatus("https://verybad.com/some/other/path?with=querystring")).toBe("blacklisted"); + }); + it("Should support subdomain wildcards", () => { + expect(lm.getStatus("https://gnu.org")).toBe("whitelisted"); + expect(lm.getStatus("https://www.gnu.org")).toBe("whitelisted"); + expect(lm.getStatus("https://evil.gnu.org")).toBe("blacklisted"); + expect(lm.getStatus("https://more.evil.gnu.org")).toBe("blacklisted"); + expect(lm.getStatus("https://more.evil.gnu.org/some/evil/path?too")).toBe("blacklisted"); + }); + }) + describe("The external script source processor", () => { let url = "https://www.gnu.org/mock-script.js"; |