diff --git a/CHANGELOG.md b/CHANGELOG.md index 745ec9d4..01a2bb55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/tests/test_chrome_driver.py b/tests/test_chrome_driver.py index a0c8f5a0..be40c4c5 100644 --- a/tests/test_chrome_driver.py +++ b/tests/test_chrome_driver.py @@ -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) diff --git a/tests/test_chromium_driver.py b/tests/test_chromium_driver.py index 26dbde63..487b9a6a 100644 --- a/tests/test_chromium_driver.py +++ b/tests/test_chromium_driver.py @@ -1,12 +1,29 @@ 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( + 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) diff --git a/tests/test_edge_driver.py b/tests/test_edge_driver.py index a2c25a1a..8f05e164 100644 --- a/tests/test_edge_driver.py +++ b/tests/test_edge_driver.py @@ -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( @@ -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']) diff --git a/tests/test_env_variables.py b/tests/test_env_variables.py new file mode 100644 index 00000000..3e52f7a6 --- /dev/null +++ b/tests/test_env_variables.py @@ -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 diff --git a/tests/test_firefox_manager.py b/tests/test_firefox_manager.py index b1d93ec7..cbe417a8 100644 --- a/tests/test_firefox_manager.py +++ b/tests/test_firefox_manager.py @@ -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() diff --git a/tests/test_ie_driver.py b/tests/test_ie_driver.py index 38c947b4..e0025ed7 100644 --- a/tests/test_ie_driver.py +++ b/tests/test_ie_driver.py @@ -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() diff --git a/tests/test_opera_manager.py b/tests/test_opera_manager.py index bb537a3a..5232f31b 100755 --- a/tests/test_opera_manager.py +++ b/tests/test_opera_manager.py @@ -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() diff --git a/webdriver_manager/driver.py b/webdriver_manager/driver.py index 7f28c984..f0aeced1 100644 --- a/webdriver_manager/driver.py +++ b/webdriver_manager/driver.py @@ -8,7 +8,6 @@ validate_response, get_browser_version_from_os, ChromeType, - os_name, OSType, firefox_version, ) @@ -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 @@ -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() @@ -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"] @@ -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"] @@ -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() @@ -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"] @@ -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()) @@ -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() diff --git a/webdriver_manager/manager.py b/webdriver_manager/manager.py index a0b3d7c3..946c7d30 100644 --- a/webdriver_manager/manager.py +++ b/webdriver_manager/manager.py @@ -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 diff --git a/webdriver_manager/utils.py b/webdriver_manager/utils.py index 566daf5e..5fd1b5bd 100644 --- a/webdriver_manager/utils.py +++ b/webdriver_manager/utils.py @@ -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)