aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2019-03-26 22:47:00 +0100
committerhackademix <giorgio@maone.net>2019-03-26 22:47:00 +0100
commita99f7d91acf0fe82a8c82440c28ffc5fe379924a (patch)
tree594351262b1f3578c8f1fad0250fd436c647a41a
parent9884643742b54b88f94111d62f5e89a12a60e604 (diff)
Automated regression tests for whitelist and blacklist management, including wildcards.
-rw-r--r--main_background.js1
-rw-r--r--test/spec/LibreJSSpec.js40
2 files changed, 40 insertions, 1 deletions
diff --git a/main_background.js b/main_background.js
index f1c7f09..5943fb8 100644
--- a/main_background.js
+++ b/main_background.js
@@ -1208,6 +1208,7 @@ async function init_addon() {
editHtml,
handle_script,
ExternalLicenses,
+ ListManager, ListStore, Storage,
};
// create or focus the autotest tab if it's a debugging session
if ((await browser.management.getSelf()).installType === "development") {
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";