Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
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
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ sudo: required
language: generic
services:
- docker
before_install:
- docker build -t httpse .
script:
- docker run --rm -ti -v $(pwd):/opt -e FIREFOX=/$FIREFOX/firefox/firefox --privileged httpse bash -c "service miredo start && test/travis-ruleset-fetch.sh"
- test/travis.sh
env:
- FIREFOX=firefox-latest
- FIREFOX=firefox-esr-latest
- TEST=firefox FIREFOX=firefox-dev
- TEST=firefox FIREFOX=firefox-latest
- TEST=firefox FIREFOX=firefox-esr-latest
- TEST=chromium
- TEST=rules
- TEST=fetch
30 changes: 30 additions & 0 deletions test/fetch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# Run https-everywhere-checker for each changed ruleset
# This is run from test/travis.sh, but should work just as well without travis
# as long as $RULESETS_CHANGED is supplied.

RULETESTFOLDER="test/rules"

# Exclude those rulesets 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.
OUTPUT_FILE=`mktemp`
trap 'rm "$OUTPUT_FILE"' EXIT
python $RULETESTFOLDER/src/https_everywhere_checker/check_rules.py $RULETESTFOLDER/http.checker.config $TO_BE_TESTED 2>&1 | tee $OUTPUT_FILE
# Unfortunately, no specific exit codes are available for connection
# failures, so we catch those with grep.
if [[ `cat $OUTPUT_FILE | grep ERROR | wc -l` -ge 1 ]]; then
echo >&2 "Test URL test failed."
exit 1
fi
fi
echo >&2 "Test URL test succeeded."
71 changes: 0 additions & 71 deletions test/travis-ruleset-fetch.sh

This file was deleted.

69 changes: 69 additions & 0 deletions test/travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Wrapper for travis tests

function docker_build {
docker build -t httpse .
}

# Folder paths, relative to parent
RULESETFOLDER="src/chrome/content/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

# 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
trap 'git remote remove upstream-for-travis' EXIT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need this trap for if we're running on Travis?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was helping when writing the PR. I wouldn't say that this will always be run by travis, though. There may be an instance when we're double-checking the travis build (for instance, we did this when we discovered lack of travis ipv6 support), and there are no negative consequences from keeping it in (other than increasing the build time by a fraction of a second).

git fetch upstream-for-travis master
COMMON_BASE_COMMIT=$(git merge-base upstream-for-travis/master HEAD)
RULESETS_CHANGED=$(git diff --name-only $COMMON_BASE_COMMIT | grep $RULESETFOLDER | grep '.xml')
if [ "$(git diff --name-only $COMMON_BASE_COMMIT)" != "$RULESETS_CHANGED" ]; then
ONLY_RULESETS_CHANGED=false
fi

# At this point, if anything fails, the test should fail
set -e

if ! $ONLY_RULESETS_CHANGED; then
echo >&2 "Core code changes have been made."
if [ "$TEST" == "firefox" ]; then
echo >&2 "Running firefox test suite."
docker_build
docker run --rm -ti -v $(pwd):/opt -e FIREFOX=/$FIREFOX/firefox/firefox httpse bash -c "test/firefox.sh"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're introducing an extra change in this PR, running these tests in Docker containers. Can you update the PR desc explaining why? Also, comment below on why --privileged.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

fi
if [ "$TEST" == "chromium" ]; then
echo >&2 "Running chromium test suite."
docker_build
# --privileged is required here because chromium requires kernel lxc access
docker run --rm -ti -v $(pwd):/opt --privileged httpse bash -c "test/chromium.sh"
fi
fi
# Only run test if something has changed.
if [ "$RULESETS_CHANGED" ]; then
echo >&2 "Ruleset database has changed."

if [ "$TEST" == "rules" ]; then
echo >&2 "Performing comprehensive coverage test."
docker_build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like docker_build gets run in every branch of these ifs, and can be hoisted up a couple of levels? And if that means it only gets run once, maybe de-alias it? Relatedly, some of the docker run flags are a little repetitive and might benefit from aliasing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker_build will not be run in several instances. If you are in env TEST=chromium, for instance, and no core code changes are made. Or if only core code changes are made and you are in env TEST=rules. These cases are described in #6220 (comment)

docker run --rm -ti -v $(pwd):/opt httpse bash -c "test/rules.sh"
fi


if [ "$TEST" == "fetch" ]; then
echo >&2 "Testing test URLs in all changed rulesets."
docker_build
# --privileged is required here for miredo to create a network tunnel
docker run --rm -ti -v $(pwd):/opt -e RULESETS_CHANGED="$RULESETS_CHANGED" --privileged httpse bash -c "service miredo start && test/fetch.sh"
fi
fi

exit 0