From 8b64624a68e6af0c934cc7a29aafbe0503d55a9d Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 18:48:21 -0500 Subject: [PATCH 01/13] Fix path Signed-off-by: Nick Semenkovich --- install-dev-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index 6646c50ce4d4..110b57770cf3 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -32,7 +32,7 @@ pip install --user --no-allow-insecure --no-allow-external -r requirements.txt cd https-everywhere-checker pip install --user -r requirements.txt cd - -cd test/chrome +cd test/chromium pip install --user -r requirements.txt cd - From 7b6909b5fcd13e20d9ace2aa59879e86bf61e6c6 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 18:49:49 -0500 Subject: [PATCH 02/13] PEP8: Convert tab -> space indent No code changes. Only automated indent fix. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 5f9e6e44031a..3043614bb54e 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -15,14 +15,14 @@ from selenium.common.exceptions import WebDriverException class bcolors: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' chromeOps = webdriver.ChromeOptions() chromeOps.add_extension(sys.argv[1]) @@ -31,23 +31,23 @@ class bcolors: chromdriver_path = "chromedriver" if 'TRAVIS' in os.environ: - chromeOps.add_argument('--no-sandbox') - chromdriver_path = os.path.abspath("test/chromium/chromedriver") + chromeOps.add_argument('--no-sandbox') + chromdriver_path = os.path.abspath("test/chromium/chromedriver") # First argument is optional, if not specified will search path. try: - driver = webdriver.Chrome(chromdriver_path, chrome_options=chromeOps) + driver = webdriver.Chrome(chromdriver_path, chrome_options=chromeOps) except WebDriverException as e: - error = e.__str__() + error = e.__str__() - if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chrome/README.md\ + if "executable needs to be in PATH" in e.__str__(): + print "ChromeDriver isn't installed. Check test/chrome/README.md\ for instructions on how to install ChromeDriver" - sys.exit(2) - else: - raise e + sys.exit(2) + else: + raise e print '' #New line @@ -56,10 +56,10 @@ class bcolors: #Page Loaded if driver.current_url.startswith('https'): - print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC + print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC elif driver.current_url.startswith('http'): - print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC - sys.exit(1) + print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC + sys.exit(1) print '' #New line From a66b64c1d885707abc2c45513e7cecae71003fd4 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 18:52:05 -0500 Subject: [PATCH 03/13] Close driver on failure too, misspelling fix. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 3043614bb54e..0dabd8ff95f8 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -28,16 +28,16 @@ class bcolors: chromeOps.add_extension(sys.argv[1]) chromeOps.add_argument("--disable-setuid-sandbox") -chromdriver_path = "chromedriver" +chromedriver_path = "chromedriver" if 'TRAVIS' in os.environ: chromeOps.add_argument('--no-sandbox') - chromdriver_path = os.path.abspath("test/chromium/chromedriver") + chromedriver_path = os.path.abspath("test/chromium/chromedriver") # First argument is optional, if not specified will search path. try: - driver = webdriver.Chrome(chromdriver_path, chrome_options=chromeOps) + driver = webdriver.Chrome(chromedriver_path, chrome_options=chromeOps) except WebDriverException as e: error = e.__str__() @@ -55,12 +55,18 @@ class bcolors: #Page Loaded +failed = False if driver.current_url.startswith('https'): print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC elif driver.current_url.startswith('http'): print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC + failed = True sys.exit(1) print '' #New line driver.quit() + + +if failed: + sys.exit(1) From 2b6851d259a89e6d38a846e57416491e9b554329 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 18:53:37 -0500 Subject: [PATCH 04/13] Add back path per-platform path logic Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 0dabd8ff95f8..1c3a124d5ad4 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -24,11 +24,17 @@ class bcolors: BOLD = '\033[1m' UNDERLINE = '\033[4m' + +if sys.platform.startswith("linux"): + chromedriver_path = "/usr/lib/chromium-browser/chromedriver" +else: + chromedriver_path = "chromedriver" # Let's just hope it's in the user's path. + + chromeOps = webdriver.ChromeOptions() chromeOps.add_extension(sys.argv[1]) chromeOps.add_argument("--disable-setuid-sandbox") -chromedriver_path = "chromedriver" if 'TRAVIS' in os.environ: chromeOps.add_argument('--no-sandbox') From abfce9850ea5e61383ae93d360a1760de126a1b9 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 18:56:23 -0500 Subject: [PATCH 05/13] Minor comment cleanups. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 1c3a124d5ad4..f009d83c8e36 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -40,39 +40,37 @@ class bcolors: chromeOps.add_argument('--no-sandbox') chromedriver_path = os.path.abspath("test/chromium/chromedriver") -# First argument is optional, if not specified will search path. try: + # First argument is optional, if not specified will search path. driver = webdriver.Chrome(chromedriver_path, chrome_options=chromeOps) except WebDriverException as e: error = e.__str__() if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chrome/README.md\ -for instructions on how to install ChromeDriver" + print "ChromeDriver isn't installed. Check test/chrome/README.md " \ + "for instructions on how to install ChromeDriver" sys.exit(2) else: raise e -print '' #New line +print '' driver.get('http://libssh.org/robots.txt') -#Page Loaded - -failed = False +test_failed = False if driver.current_url.startswith('https'): print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC elif driver.current_url.startswith('http'): print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC - failed = True + test_failed = True sys.exit(1) -print '' #New line +print '' driver.quit() -if failed: +if test_failed: sys.exit(1) From 902d8cc1728c276807b4cb7d81dbd0ed317c0989 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 19:21:21 -0500 Subject: [PATCH 06/13] Try to drop some flags, and see if Travis cares. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index f009d83c8e36..a829955c016a 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -27,19 +27,15 @@ class bcolors: if sys.platform.startswith("linux"): chromedriver_path = "/usr/lib/chromium-browser/chromedriver" +elif 'TRAVIS' in os.environ: + # For TravisCI, we manually copy chromedriver to the local path. + chromedriver_path = os.path.abspath("test/chromium/chromedriver") else: chromedriver_path = "chromedriver" # Let's just hope it's in the user's path. chromeOps = webdriver.ChromeOptions() chromeOps.add_extension(sys.argv[1]) -chromeOps.add_argument("--disable-setuid-sandbox") - - -if 'TRAVIS' in os.environ: - chromeOps.add_argument('--no-sandbox') - chromedriver_path = os.path.abspath("test/chromium/chromedriver") - try: # First argument is optional, if not specified will search path. From f30e4bec62280376d8856681a27bde45321eee38 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 19:23:28 -0500 Subject: [PATCH 07/13] More verbose error messages. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index a829955c016a..6de0420e5b49 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -57,9 +57,9 @@ class bcolors: test_failed = False if driver.current_url.startswith('https'): - print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC + print bcolors.OKGREEN + "Chromium: HTTP to HTTPS redirection successful" + bcolors.ENDC elif driver.current_url.startswith('http'): - print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC + print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC test_failed = True sys.exit(1) From 69c128269e1512c9e17e07989f045c6eb9ffbfad Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 19:26:51 -0500 Subject: [PATCH 08/13] Travis uses --- test/chromium/script.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 6de0420e5b49..638f73eabce8 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -25,17 +25,21 @@ class bcolors: UNDERLINE = '\033[4m' +chromeOps = webdriver.ChromeOptions() +chromeOps.add_extension(sys.argv[1]) + if sys.platform.startswith("linux"): chromedriver_path = "/usr/lib/chromium-browser/chromedriver" elif 'TRAVIS' in os.environ: # For TravisCI, we manually copy chromedriver to the local path. chromedriver_path = os.path.abspath("test/chromium/chromedriver") -else: - chromedriver_path = "chromedriver" # Let's just hope it's in the user's path. + # Travis has setuid restrictions. I think this becomes unnecessary in M42+ + chromeOps.add_argument('--no-suid-sandbox') +else: + # Let's hope it's in the user's path. + chromedriver_path = "chromedriver" -chromeOps = webdriver.ChromeOptions() -chromeOps.add_extension(sys.argv[1]) try: # First argument is optional, if not specified will search path. From 7627c76694cbd0a38c3ee661eec45b6ae2982f3e Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 19:33:35 -0500 Subject: [PATCH 09/13] Travis realllly doesn't like sandboxes. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index 638f73eabce8..debbd8be97f9 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -34,8 +34,9 @@ class bcolors: # For TravisCI, we manually copy chromedriver to the local path. chromedriver_path = os.path.abspath("test/chromium/chromedriver") - # Travis has setuid restrictions. I think this becomes unnecessary in M42+ + # Travis has setuid restrictions. I think this becomes unnecessary in M42+? chromeOps.add_argument('--no-suid-sandbox') + chromeOps.add_argument('--no-sandbox') else: # Let's hope it's in the user's path. chromedriver_path = "chromedriver" From d53222488237d2fa0dc79bebe0b9e6518c85b6e3 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 19:37:02 -0500 Subject: [PATCH 10/13] Fix readlink errors & more properly CD to the project root. Signed-off-by: Nick Semenkovich --- test.sh | 12 +++++++++--- test/chromium.sh | 19 ++++++++++--------- test/firefox.sh | 16 ++++++++++------ test/rules.sh | 12 ++++++++++-- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/test.sh b/test.sh index 3a255e25b36d..441bd3557157 100755 --- a/test.sh +++ b/test.sh @@ -3,10 +3,16 @@ # Get into the project-root. This script may be executed as `test.sh` # or as .git/hooks/pre-push, so we need to find the directory containing -# test.sh before we can proceed. If $0 is not a symlink, `readlink` will -# print nothing; if it is a symlink it will print the link target. +# test.sh before we can proceed. -cd $(dirname $0)/$(dirname $(readlink $0)) +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi ./test/rules.sh ./test/firefox.sh $@ diff --git a/test/chromium.sh b/test/chromium.sh index 23c439f19129..e3d76b73f954 100755 --- a/test/chromium.sh +++ b/test/chromium.sh @@ -1,15 +1,16 @@ -#!/bin/bash +#!/bin/bash -ex # Run Chromium tests for HTTPS Everywhere -# -# Get into the project-root. This script may be executed as `chromium.sh` -# or as ./test/chromium.sh, so we need to find the directory -# containing firefox.sh before we can proceed. If $0 is not a symlink, -# `readlink` will print nothing; if it is a symlink it will print the -# link target. -set -o errexit -o xtrace +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi -cd $(dirname $0)/$(dirname $(readlink $0))../ # If you just want to run Chromium with the latest code: if [ "$1" == "--justrun" ]; then diff --git a/test/firefox.sh b/test/firefox.sh index 67758dc2fbd9..3856a5c01d3c 100755 --- a/test/firefox.sh +++ b/test/firefox.sh @@ -1,12 +1,16 @@ #!/bin/bash -ex # Run Firefox tests for HTTPS Everywhere -# -# Get into the project-root. This script may be executed as `firefox.sh` -# or as ./test/firefox.sh, so we need to find the directory containing -# firefox.sh before we can proceed. If $0 is not a symlink, `readlink` -# will print nothing; if it is a symlink it will print the link target. -cd $(dirname $0)/$(dirname $(readlink $0))../ +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi + source utils/mktemp.sh diff --git a/test/rules.sh b/test/rules.sh index cac08eec3d62..2e2286496088 100755 --- a/test/rules.sh +++ b/test/rules.sh @@ -1,10 +1,18 @@ -#!/bin/bash +#!/bin/bash -ex # # Test that all rulesets modified after a certain date have sufficient test # coverage, according to the ruleset checker. # -cd $(dirname $0)/$(dirname $(readlink $0))../ +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi source utils/mktemp.sh From e596791c33222362931aa222112fbd538d6d7b86 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 21:06:09 -0500 Subject: [PATCH 11/13] Actually fix Travis logic. Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index debbd8be97f9..bd5948991735 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -28,15 +28,14 @@ class bcolors: chromeOps = webdriver.ChromeOptions() chromeOps.add_extension(sys.argv[1]) -if sys.platform.startswith("linux"): - chromedriver_path = "/usr/lib/chromium-browser/chromedriver" -elif 'TRAVIS' in os.environ: +if 'TRAVIS' in os.environ.keys(): # For TravisCI, we manually copy chromedriver to the local path. chromedriver_path = os.path.abspath("test/chromium/chromedriver") # Travis has setuid restrictions. I think this becomes unnecessary in M42+? - chromeOps.add_argument('--no-suid-sandbox') - chromeOps.add_argument('--no-sandbox') + chromeOps.add_argument('--disable-setuid-sandbox') +elif sys.platform.startswith("linux"): + chromedriver_path = "/usr/lib/chromium-browser/chromedriver" else: # Let's hope it's in the user's path. chromedriver_path = "chromedriver" From 1e17430a57a9bc8fe048757a4c03bf5dbe0479d1 Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sat, 5 Sep 2015 21:26:12 -0500 Subject: [PATCH 12/13] Explicitly cache pip because of a known Travis bug See: https://github.com/travis-ci/travis-ci/issues/3239 Signed-off-by: Nick Semenkovich --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a5eacafc5f4b..ff1d674bb72b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ language: python python: - "2.7" -cache: pip +cache: + directories: + - $HOME/.cache/pip addons: apt: packages: From 2a1115da83ba87f9f6515c386a12cd8f356802ac Mon Sep 17 00:00:00 2001 From: Nick Semenkovich Date: Sun, 6 Sep 2015 09:33:46 -0500 Subject: [PATCH 13/13] Fix unreachable code Signed-off-by: Nick Semenkovich --- test/chromium/script.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/chromium/script.py b/test/chromium/script.py index bd5948991735..78cc693c5169 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -65,7 +65,6 @@ class bcolors: elif driver.current_url.startswith('http'): print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC test_failed = True - sys.exit(1) print ''