From a99f7d91acf0fe82a8c82440c28ffc5fe379924a Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 26 Mar 2019 22:47:00 +0100 Subject: Automated regression tests for whitelist and blacklist management, including wildcards. --- test/spec/LibreJSSpec.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'test') 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"; -- cgit v1.2.3