Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Test www.example.com in place of *.example.com
Browse files Browse the repository at this point in the history
Also refactor the test target management a bit
  • Loading branch information
pde committed Sep 4, 2014
1 parent 6a92b19 commit c907714
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions src/chrome/content/ruleset-tests.js
Expand Up @@ -15,7 +15,6 @@ if(HTTPSEverywhere) {
};
}


function openStatus() {
// make sure mixed content blocking preferences are correct
Services.prefs.setBoolPref("security.mixed_content.block_display_content", false);
Expand All @@ -26,6 +25,34 @@ function openStatus() {
gBrowser.selectedTab = statusTab;
}

function addTestTarget(urls, target, ruleset_ids) {
// Add one target and associated metadata to the list of
// URLs to be tested, performing housekeeping along the way
HTTPSEverywhere.log(5, "target is " + target);
var active_ids = [];
for (var n = 0; n < ruleset_ids.length; n++) {
var rs_id = ruleset_ids[n];
var rs = HTTPSEverywhere.https_rules.rulesetsByID[rs_id];
if (!rs) {
// most rulesets will need to be fetched from the database
HTTPSEverywhere.https_rules.loadRulesetById(rs_id);
rs = HTTPSEverywhere.https_rules.rulesetsByID[rs_id];
if (!rs) {
HTTPSEverywhere.log(5, "ARGH unexpected missing ruleset");
}
}
if (rs.active) { active_ids.push(rs_id) };
}
// Some rulesets that might rewrite this target, let's test them
if (active_ids.length > 0) {
urls.push({
url: 'http://'+target,
target: target,
ruleset_ids: active_ids
});
}
}

function testRunner() {
Components.utils.import("resource://gre/modules/PopupNotifications.jsm");

Expand All @@ -34,33 +61,16 @@ function testRunner() {
var output = [];
var urls = [];
var num = 0;
var targets = HTTPSEverywhere.https_rules.targets;

for(var target in HTTPSEverywhere.https_rules.targets) {
var active_ids = [];
for(var target in targets) {
var t;
if(target.indexOf("*") == -1) {
HTTPSEverywhere.log(5, "target is " + target);
var ruleset_ids = HTTPSEverywhere.https_rules.targets[target];
for (var n = 0; n < ruleset_ids.length; n++) {
var rs_id = ruleset_ids[n];
var rs = HTTPSEverywhere.https_rules.rulesetsByID[rs_id];
if (!rs) {
// most rulesets will need to be fetched from the database
HTTPSEverywhere.https_rules.loadRulesetById(rs_id);
rs = HTTPSEverywhere.https_rules.rulesetsByID[rs_id];
if (!rs) {
HTTPSEverywhere.log(5, "ARGH unexpected missing ruleset");
}
}
if (rs.active) { active_ids.push(rs_id) };
}
// Some rulesets that might rewrite this target, let's test them
if (active_ids.length > 0) {
urls.push({
url: 'http://'+target,
target: target,
ruleset_ids: active_ids
});
}
addTestTarget(urls, target, targets[target]);
} else {
// target is like *.example.wildcard.com, let's see what we can do...
t = target.replace("*.", "www.");
if (!(t in targets)) { addTestTarget(urls, t, targets[target]); }
}
}

Expand Down

0 comments on commit c907714

Please sign in to comment.