forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
71 lines (57 loc) · 2.1 KB
/
script.py
File metadata and controls
71 lines (57 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python2.7
#
# Run Chromium tests for HTTPS Everywhere
#
# This script may be executed as `python script.py [directory of CRX]`
#
# The script is compatible with Python 2. Python 3 is not tested.
# Selenium, WebDriver and Google Chrome (or Chromium) must be installed
# in order for the script to run successfully. A desktop version
# of linux is required for the script to run correctly as well.
# Otherwise, use pyvirtualdisplay.
import sys, os, platform
from selenium import webdriver
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'
chromeOps = webdriver.ChromeOptions()
chromeOps.add_extension(sys.argv[1])
# Find the path to chromedriver
chromedriver_path = "chromedriver"
if sys.platform.startswith("linux"):
if 'Ubuntu' in platform.linux_distribution():
chromedriver_path = "/usr/lib/chromium-browser/chromedriver"
elif 'debian' in platform.linux_distribution():
#Debian is lowercase when platform.linux_distribution() is used.
#This is not a mistake.
chromedriver_path = "/usr/lib/chromium/chromedriver"
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"
sys.exit(2)
else:
raise e
print ''
driver.get('http://libssh.org/robots.txt')
test_failed = False
if driver.current_url.startswith('https'):
print bcolors.OKGREEN + "Chromium: HTTP to HTTPS redirection successful" + bcolors.ENDC
elif driver.current_url.startswith('http'):
print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC
test_failed = True
print ''
driver.quit()
if test_failed:
sys.exit(1)