Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ set -e
if [ "$TEST" == "rules" ]; then
echo >&2 "Performing comprehensive coverage test."
docker run --rm -ti -v $(pwd):/opt httpse python utils/ruleset_filenames_validate.py
docker run --rm -ti -v $(pwd):/opt httpse bash -c "utils/remove-obsolete-references.sh"
docker run --rm -ti -v $(pwd):/opt httpse bash -c "utils/validate.sh"
docker run --rm -ti -v $(pwd):/opt httpse python utils/validate.py
docker run --rm -ti -v $(pwd):/opt httpse python utils/trivial-validate.py --quiet
docker run --rm -ti -v $(pwd):/opt httpse bash -c "test/rules.sh"
docker run --rm -ti -v $(pwd):/opt node bash -c "cd /opt && node utils/normalize-securecookie.js"
[ `git diff --name-only $RULESETFOLDER | wc -l` -eq 0 ]
Expand Down
8 changes: 8 additions & 0 deletions utils/trivial-validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def nomes_all(where=sys.argv[1:]):
xpath_from = etree.XPath("/ruleset/rule/@from")
xpath_to = etree.XPath("/ruleset/rule/@to")

print("Complicated validation & assertions of rulesets using utils/trivial-validate.py begins...")

host_counter = Counter()
for filename in filenames:
xml_parser = etree.XMLParser(remove_blank_text=True)
Expand Down Expand Up @@ -200,4 +202,10 @@ def nomes_all(where=sys.argv[1:]):
failure = 1
fail("%s failed: %s" % (host, is_valid_target_host.__doc__))

if failure != 0:
message = "Complicated validation & assertions of rulesets using utils/trivial-validate.py failed."
else:
message = "Complicated validation & assertions of rulesets using utils/trivial-validate.py succeeded."

print(message)
sys.exit(failure)
55 changes: 55 additions & 0 deletions utils/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python2.7

import argparse
import glob
import os
import unicodedata

from lxml import etree

def normalize(f):
"""
OSX and Linux filesystems encode composite characters differently in
filenames. We should normalize to NFC: https://unicode.org/reports/tr15/
"""
f = unicodedata.normalize("NFC", unicode(f, "utf-8")).encode("utf-8")
return f

# commandline arguments parsing (nobody use it, though)
parser = argparse.ArgumentParser(description="Validate rulesets against relaxng.xml")
parser.add_argument("--source_dir", default="src/chrome/content/rules")

args = parser.parse_args()

# XML ruleset files
files = map(normalize, glob.glob(os.path.join(args.source_dir, "*.xml")))

# read the schema file
relaxng_doc = etree.parse('utils/relaxng.xml')
relaxng = etree.RelaxNG(relaxng_doc)

exit_code = 0

print("Validation of rulesets against utils/relaxng.xml begins...")

for filename in sorted(files):
tree = etree.parse(filename)

if not relaxng.validate(tree):
exit_code = 1
e = relaxng.error_log.last_error
print("%s %s:%s:%s: %s" % (e.level_name, e.filename, e.line, e.column, e.message))



if exit_code == 0:
message = "Validation of rulesets against utils/relaxng.xml succeeded."
else:
message = "\nTwo very common reasons for this are the following:\n" \
" - missing caret (^) in 'from' attribute: it should be \"^http:\" and not \"http:\"\n" \
" - missing trailing slashes in 'from' or 'to' when specifying full hostnames: \n" \
" it should be \"https://eff.org/\" and not \"https://eff.org\"\n\n" \
"Validation of rulesets against utils/relaxng.xml failed."

print(message)
exit(exit_code)
49 changes: 0 additions & 49 deletions utils/validate.sh

This file was deleted.