From d214ed2baa2d3a8d4409f38cb33f71056c98b468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Mon, 19 Oct 2015 16:54:20 +0200 Subject: [PATCH 1/3] Add pre-commit hook with unit test for ruleset test URLs This adds a simple shell script which runs all changed rulesets by https-everywhere-checker. It happens every now and then that people submit rulesets that fail only because of subtle SSL misconfigurations (typically broken certificate chains), and this helps to catch those. --- install-dev-dependencies.sh | 3 ++- test/commit.sh | 51 +++++++++++++++++++++++++++++++++++++ test/rules | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 test/commit.sh diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index e9e079bb3bd6..2fdd5c21f6ee 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -38,5 +38,6 @@ cd test/chromium pip install --user -r requirements.txt cd - -# Install a hook to run tests before pushing. +# Install git hooks to run tests before committing and pushing. ln -sf ../../test.sh .git/hooks/pre-push +ln -sf ../../test/commit.sh .git/hooks/pre-commit diff --git a/test/commit.sh b/test/commit.sh new file mode 100755 index 000000000000..b94b036c091a --- /dev/null +++ b/test/commit.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Run https-everywhere-checker for each changed ruleset + +# Folder paths, relative to parent +RULESETFOLDER="src/chrome/content/rules" +RULETESTFOLDER="test/rules" + +# Go to git repo root; taken from ../test.sh. Note that +# $GIT_DIR is .git in this case. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR + cd .. +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi + +RULESETS_CHANGED=$(git diff --name-only HEAD | grep $RULESETFOLDER | grep '.xml') + +# Only run test if something has changed. +if [ "$RULESETS_CHANGED" ]; then + echo >&2 "Ruleset database has changed. Testing test URLs in all changed rulesets." + + # Make a list of all changed rulesets, but exclude those + # that do not exist. + for RULESET in $RULESETS_CHANGED; do + # First check if the given ruleset actually exists + if [ ! -f $RULESET ]; then + echo >&2 "Skipped $RULESET; file not found." + continue + fi + TO_BE_TESTED="$TO_BE_TESTED $RULESET" + done + + if [ "$TO_BE_TESTED" ]; then + # Do the actual test, using https-everywhere-checker. + TESTOUTPUT=$(python $RULETESTFOLDER/src/https_everywhere_checker/check_rules.py $RULETESTFOLDER/http.checker.config $TO_BE_TESTED 2>&1) + echo >&2 "$TESTOUTPUT" + # Unfortunately, no specific exit codes are available for connection + # failures, so we catch those with grep. + if [[ "$TESTOUTPUT" =~ "ERROR" ]]; then + echo >&2 "Test URL test failed." + exit 1 + fi + fi + echo >&2 "Test URL test succeeded." +fi + +exit 0 diff --git a/test/rules b/test/rules index 73d84b434c4a..05d7c201f857 160000 --- a/test/rules +++ b/test/rules @@ -1 +1 @@ -Subproject commit 73d84b434c4ab400f79fa6d8244300ec7630edb1 +Subproject commit 05d7c201f857a1fdfcd50ce85f626fbbd9f7b0df From 6fd03a34cc08e09ebf4db32afb064d86ded7c487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Mon, 18 Jan 2016 20:05:39 +0100 Subject: [PATCH 2/3] Move test from git hook to Travis Following jsha's suggestion in https://github.com/EFForg/https-everywhere/pull/3107#issuecomment-165623578, this removes the pre-commit test from the developer installation script, but adds it instead to Travis. --- .travis.yml | 1 + install-dev-dependencies.sh | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3298cd7642f2..fd9914cbfb6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ before_script: - mv chromedriver test/chromium/chromedriver script: - ./test.sh + - test/commit.sh sudo: false notifications: email: diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index 2fdd5c21f6ee..9e668c372966 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -38,6 +38,5 @@ cd test/chromium pip install --user -r requirements.txt cd - -# Install git hooks to run tests before committing and pushing. +# Install git hook to run tests before pushing. ln -sf ../../test.sh .git/hooks/pre-push -ln -sf ../../test/commit.sh .git/hooks/pre-commit From 39ea42cc80e253ef7ddca38cb4980268a4125674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Mon, 18 Jan 2016 22:30:10 +0100 Subject: [PATCH 3/3] Make ruleset fetch test Travis specific This renames the pre-commit test to reflect that it is now Travis specific; rather than the contents of the previous commit, this checks the current branch against the EFForg GitHub repository master branch. --- .travis.yml | 2 +- test/{commit.sh => travis-ruleset-fetch.sh} | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) rename test/{commit.sh => travis-ruleset-fetch.sh} (81%) diff --git a/.travis.yml b/.travis.yml index fd9914cbfb6a..3176bd117849 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_script: - mv chromedriver test/chromium/chromedriver script: - ./test.sh - - test/commit.sh + - test/travis-ruleset-fetch.sh sudo: false notifications: email: diff --git a/test/commit.sh b/test/travis-ruleset-fetch.sh similarity index 81% rename from test/commit.sh rename to test/travis-ruleset-fetch.sh index b94b036c091a..ab877d24ab00 100755 --- a/test/commit.sh +++ b/test/travis-ruleset-fetch.sh @@ -17,7 +17,11 @@ else git rev-parse && cd "$(git rev-parse --show-toplevel)" fi -RULESETS_CHANGED=$(git diff --name-only HEAD | grep $RULESETFOLDER | grep '.xml') +# Fetch the current GitHub version of HTTPS-E to compare to its master +git remote add upstream-for-travis https://github.com/EFForg/https-everywhere.git +git fetch upstream-for-travis master +RULESETS_CHANGED=$(git diff --name-only upstream-for-travis/master | grep $RULESETFOLDER | grep '.xml') +git remote remove upstream-for-travis # Only run test if something has changed. if [ "$RULESETS_CHANGED" ]; then