|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
| 18 | +import os |
18 | 19 | from unittest.mock import patch |
19 | 20 | from urllib import parse |
20 | 21 |
|
|
24 | 25 | from urllib3.util import Timeout |
25 | 26 |
|
26 | 27 | from selenium import __version__ |
| 28 | +from selenium.webdriver import Proxy |
| 29 | +from selenium.webdriver.common.proxy import ProxyType |
27 | 30 | from selenium.webdriver.remote.remote_connection import ClientConfig |
28 | 31 | from selenium.webdriver.remote.remote_connection import RemoteConnection |
29 | 32 |
|
@@ -117,6 +120,54 @@ def test_get_proxy_url_https(mock_proxy_settings): |
117 | 120 | assert proxy_url == proxy |
118 | 121 |
|
119 | 122 |
|
| 123 | +def test_get_proxy_url_https_via_client_config(): |
| 124 | + client_config = ClientConfig( |
| 125 | + remote_server_addr="https://localhost:4444", |
| 126 | + proxy=Proxy({"proxyType": ProxyType.MANUAL, "sslProxy": "https://admin:admin@http_proxy.com:8080"}), |
| 127 | + ) |
| 128 | + remote_connection = RemoteConnection(client_config=client_config) |
| 129 | + proxy_url = remote_connection._client_config.get_proxy_url() |
| 130 | + assert proxy_url == "https://admin:admin@http_proxy.com:8080" |
| 131 | + |
| 132 | + |
| 133 | +def test_get_proxy_url_http_via_client_config(): |
| 134 | + client_config = ClientConfig( |
| 135 | + remote_server_addr="https://localhost:4444", |
| 136 | + proxy=Proxy( |
| 137 | + { |
| 138 | + "proxyType": ProxyType.MANUAL, |
| 139 | + "httpProxy": "http://admin:admin@http_proxy.com:8080", |
| 140 | + "sslProxy": "https://admin:admin@http_proxy.com:8080", |
| 141 | + } |
| 142 | + ), |
| 143 | + ) |
| 144 | + remote_connection = RemoteConnection(client_config=client_config) |
| 145 | + proxy_url = remote_connection._client_config.get_proxy_url() |
| 146 | + assert proxy_url == "https://admin:admin@http_proxy.com:8080" |
| 147 | + |
| 148 | + |
| 149 | +def test_get_proxy_direct_via_client_config(): |
| 150 | + client_config = ClientConfig( |
| 151 | + remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.DIRECT}) |
| 152 | + ) |
| 153 | + remote_connection = RemoteConnection(client_config=client_config) |
| 154 | + proxy_url = remote_connection._client_config.get_proxy_url() |
| 155 | + assert proxy_url is None |
| 156 | + |
| 157 | + |
| 158 | +def test_get_proxy_system_matches_no_proxy_via_client_config(): |
| 159 | + os.environ["HTTP_PROXY"] = "http://admin:admin@system_proxy.com:8080" |
| 160 | + os.environ["NO_PROXY"] = "localhost,127.0.0.1" |
| 161 | + client_config = ClientConfig( |
| 162 | + remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.SYSTEM}) |
| 163 | + ) |
| 164 | + remote_connection = RemoteConnection(client_config=client_config) |
| 165 | + proxy_url = remote_connection._client_config.get_proxy_url() |
| 166 | + assert proxy_url is None |
| 167 | + os.environ.pop("HTTP_PROXY") |
| 168 | + os.environ.pop("NO_PROXY") |
| 169 | + |
| 170 | + |
120 | 171 | def test_get_proxy_url_none(mock_proxy_settings_missing): |
121 | 172 | remote_connection = RemoteConnection("https://remote", keep_alive=False) |
122 | 173 | proxy_url = remote_connection._client_config.get_proxy_url() |
|
0 commit comments