Skip to content

Commit

Permalink
Feature: add WDM_SSL_VERIFY env property
Browse files Browse the repository at this point in the history
Details: add WDM_SSL_VERIFY env property to disable requests ssl verification (feature to fix issues #219, #226)
  • Loading branch information
aleksandr-kotlyar committed Oct 18, 2021
1 parent 7e92270 commit 4b8e6eb
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

---
## 3.5.2
### SSL
- Feature: now you can disable SSL verification by setting `os.environ['WDM_SSL_VERIFY']='0'` in case if you have troubles with SSL Certificates or SSL Certificate Chain (like in issues
[#219](https://github.com/SergeyPirogov/webdriver_manager/issues/219), [#226](https://github.com/SergeyPirogov/webdriver_manager/issues/226))
---
## 3.5.1
### IEDriver
- Fix: huge typo in IEDriver (appeared accidentally in 3.5.0 version)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_chrome_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def test_chrome_manager_with_selenium():
driver.close()


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(os.path.dirname(
os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = ChromeDriverManager(path=custom_path).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


def test_chrome_manager_cached_driver_with_selenium():
custom_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "custom")
manager = ChromeDriverManager(path=custom_path)
Expand Down
20 changes: 19 additions & 1 deletion tests/test_chromium_driver.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import os

import pytest
from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = ChromeDriverManager(
version="83.0.4103.39",
path=custom_path,
chrome_type=ChromeType.CHROMIUM,
).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


def test_chromium_manager_with_specific_version():
bin_path = ChromeDriverManager("2.27", chrome_type=ChromeType.CHROMIUM).install()
assert os.path.exists(bin_path)
Expand Down
21 changes: 18 additions & 3 deletions tests/test_edge_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ def test_edge_manager_with_selenium():
driver.quit()


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = EdgeChromiumDriverManager(path=custom_path).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


def test_edge_manager_with_wrong_version():
with pytest.raises(ValueError) as ex:
driver_path = EdgeChromiumDriverManager(
Expand All @@ -25,9 +40,9 @@ def test_edge_manager_with_wrong_version():
driver.quit()

assert (
"There is no such driver by url "
"https://msedgedriver.azureedge.net/0.2/edgedriver_win64.zip"
) in ex.value.args[0]
"There is no such driver by url "
"https://msedgedriver.azureedge.net/0.2/edgedriver_win64.zip"
) in ex.value.args[0]


@pytest.mark.parametrize('os_type', ['win32', 'win64', 'linux64', 'mac64'])
Expand Down
19 changes: 19 additions & 0 deletions tests/test_env_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

import pytest

from webdriver_manager.driver import Driver


@pytest.mark.parametrize(
'verify_value, expected_ssl_verify',
[
('1', True),
('0', False),
('', True),
]
)
def test_driver_ssl_verify_env(verify_value, expected_ssl_verify):
os.environ['WDM_SSL_VERIFY'] = verify_value

assert Driver('a', 'b', 'c', 'd', 'e').ssl_verify is expected_ssl_verify
15 changes: 15 additions & 0 deletions tests/test_firefox_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ def test_gecko_manager_with_selenium():
ff.quit()


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = GeckoDriverManager(path=custom_path).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


def test_gecko_manager_with_wrong_version():
with pytest.raises(ValueError) as ex:
driver_path = GeckoDriverManager("0.2").install()
Expand Down
15 changes: 15 additions & 0 deletions tests/test_ie_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ def test_ie_manager_with_different_versions(version):
# assert os.path.exists(driver_path)


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = IEDriverManager(path=custom_path).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_download_ie_driver_x64(os_type):
path = IEDriverManager(os_type=os_type).install()
Expand Down
15 changes: 15 additions & 0 deletions tests/test_opera_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ def test_opera_driver_manager_with_correct_version():
assert os.path.exists(driver_path)


def test_driver_with_ssl_verify_disabled_can_be_downloaded():
try:
os.environ['WDM_SSL_VERIFY'] = '0'
custom_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = OperaDriverManager(path=custom_path).install()

assert os.path.exists(driver_path)

finally:
os.environ['WDM_SSL_VERIFY'] = ''


def test_operadriver_manager_with_selenium():
driver_path = OperaDriverManager().install()
options = webdriver.ChromeOptions()
Expand Down
32 changes: 22 additions & 10 deletions webdriver_manager/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
validate_response,
get_browser_version_from_os,
ChromeType,
os_name,
OSType,
firefox_version,
)
Expand All @@ -25,6 +24,7 @@ def __init__(self, name,
self._version = version
self._os_type = os_type
self._latest_release_url = latest_release_url
self.ssl_verify = False if os.getenv('WDM_SSL_VERIFY') == '0' else True

def get_name(self):
return self._name
Expand Down Expand Up @@ -61,7 +61,10 @@ def get_os_type(self):

def get_latest_release_version(self):
log(f"Get LATEST driver version for {self.browser_version}")
resp = requests.get(f"{self._latest_release_url}_{self.browser_version}")
resp = requests.get(
url=f"{self._latest_release_url}_{self.browser_version}",
verify=self.ssl_verify
)
validate_response(resp)
return resp.text.rstrip()

Expand Down Expand Up @@ -99,6 +102,7 @@ def get_latest_release_version(self) -> str:
resp = requests.get(
url=self.latest_release_url,
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
return resp.json()["tag_name"]
Expand All @@ -109,6 +113,7 @@ def get_url(self):
resp = requests.get(
url=self.tagged_release_url(self.get_version()),
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
assets = resp.json()["assets"]
Expand Down Expand Up @@ -170,6 +175,7 @@ def get_latest_release_version(self) -> str:
resp = requests.get(
url=self.latest_release_url,
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
releases = resp.json()
Expand All @@ -187,6 +193,7 @@ def get_url(self):
resp = requests.get(
url=self.tagged_release_url(self.get_version()),
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
assets = resp.json()["assets"]
Expand Down Expand Up @@ -235,19 +242,24 @@ def __init__(self, name,
log("GH_TOKEN will be used to perform requests")
self.auth_header = {'Authorization': f'token {self._os_token}'}

def get_latest_release_version(self):
# type: () -> str
resp = requests.get(self.latest_release_url, headers=self.auth_header)
def get_latest_release_version(self) -> str:
resp = requests.get(
url=self.latest_release_url,
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
return resp.json()["tag_name"]

def get_url(self):
# type: () -> str
def get_url(self) -> str:
# https://github.com/operasoftware/operachromiumdriver/releases/download/v.2.45/operadriver_linux64.zip
version = self.get_version()
log(f"Getting latest opera release info for {version}")
resp = requests.get(url=self.tagged_release_url(version),
headers=self.auth_header)
resp = requests.get(
url=self.tagged_release_url(version),
headers=self.auth_header,
verify=self.ssl_verify,
)
validate_response(resp)
assets = resp.json()["assets"]
name = "{0}_{1}".format(self.get_name(), self.get_os_type())
Expand Down Expand Up @@ -288,6 +300,6 @@ def get_latest_release_version(self) -> str:
OSType.MAC in self.get_os_type(): f'{self._latest_release_url}_{major_edge_version}_MACOS',
OSType.LINUX in self.get_os_type(): f'{self._latest_release_url}_{major_edge_version}_LINUX',
}[True]
resp = requests.get(latest_release_url)
resp = requests.get(latest_release_url, verify=self.ssl_verify)
validate_response(resp)
return resp.text.rstrip()
2 changes: 1 addition & 1 deletion webdriver_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_driver_path(self, driver):
if binary_path:
return binary_path

file = download_file(driver.get_url())
file = download_file(driver.get_url(), driver.ssl_verify)
binary_path = self.driver_cache.save_file_to_cache(file, browser_version,
driver_name, os_type, driver_version)
return binary_path
4 changes: 2 additions & 2 deletions webdriver_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def write_file(content, path):
return path


def download_file(url: str) -> File:
def download_file(url: str, ssl_verify=True) -> File:
log(f"Trying to download new driver from {url}")
response = requests.get(url, stream=True)
response = requests.get(url, stream=True, verify=ssl_verify)
validate_response(response)
return File(response)

Expand Down

0 comments on commit 4b8e6eb

Please sign in to comment.