Skip to content

Commit dfb8898

Browse files
committed
Add test url formatting to https_everywhere_checker tests
1 parent dd23e40 commit dfb8898

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

test/rules/coverage.checker.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
rulesdir = src/chrome/content/rules
66
check_coverage = true
77
check_nonmatch_groups = true
8+
check_test_formatting = true
89
include_default_off = false
910
skiplist = utils/ruleset-coverage-whitelist.txt
1011

test/rules/http.checker.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Directory with XML files describing HTTPS Everywhere rulesets
55
rulesdir = src/chrome/content/rules
66
check_coverage = false
7+
check_nonmatch_groups = false
8+
check_test_formatting = false
79
auto_disable = false
810
include_default_off = false
911

test/rules/src/https_everywhere_checker/check_rules.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ def cli():
282282
checkNonmatchGroups = False
283283
if config.has_option("rulesets", "check_nonmatch_groups"):
284284
checkNonmatchGroups = config.getboolean("rulesets", "check_nonmatch_groups")
285+
checkTestFormatting = False
286+
if config.has_option("rulesets", "check_test_formatting"):
287+
checkTestFormatting = config.getboolean("rulesets", "check_test_formatting")
285288
certdir = config.get("certificates", "basedir")
286-
if config.has_option("rulesets", "check_coverage"):
287-
checkCoverage = config.getboolean("rulesets", "check_coverage")
288289
if config.has_option("rulesets", "skiplist"):
289290
skiplist = config.get("rulesets", "skiplist")
290291
with open(skiplist) as f:
@@ -326,6 +327,7 @@ def cli():
326327
rulesets = []
327328
coverageProblemsExist = False
328329
nonmatchGroupProblemsExist = False
330+
testFormattingProblemsExist = False
329331
for xmlFname in xmlFnames:
330332
logging.debug("Parsing %s", xmlFname)
331333
if skipFile(xmlFname):
@@ -352,6 +354,12 @@ def cli():
352354
for problem in problems:
353355
nonmatchGroupProblemsExist = True
354356
logging.error(problem)
357+
if checkTestFormatting:
358+
logging.debug("Checking test formatting for '%s'." % ruleset.name)
359+
problems = ruleset.getTestFormattingProblems()
360+
for problem in problems:
361+
testFormattingProblemsExist = True
362+
logging.error(problem)
355363
trie.addRuleset(ruleset)
356364
rulesets.append(ruleset)
357365

@@ -424,6 +432,9 @@ def cli():
424432
if checkNonmatchGroups:
425433
if nonmatchGroupProblemsExist:
426434
return 1 # exit with error code
435+
if checkTestFormatting:
436+
if testFormattingProblemsExist:
437+
return 1 # exit with error code
427438
return 0 # exit with success
428439

429440
if __name__ == '__main__':

test/rules/src/https_everywhere_checker/rules.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urlparse import urlparse
2+
13
import regex
24

35
class Rule(object):
@@ -229,6 +231,18 @@ def getNonmatchGroupProblems(self):
229231
self.filename, test.url))
230232
return problems
231233

234+
def getTestFormattingProblems(self):
235+
"""Verify that tests are formatted properly. This ensures that no test url
236+
will lack a '/' in the path."""
237+
problems = []
238+
for rule in self.rules:
239+
for test in rule.tests:
240+
parsed_url = urlparse(test.url)
241+
if parsed_url.path == '':
242+
problems.append("%s: Test url lacks a trailing /: %s" % (
243+
self.filename, test.url))
244+
return problems
245+
232246
def whatApplies(self, url):
233247
for exclusion in self.exclusions:
234248
if exclusion.matches(url):

0 commit comments

Comments
 (0)