Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions py/selenium/webdriver/common/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

"""The Proxy implementation."""

import warnings


class ProxyTypeFactory:
"""Factory for proxy types."""
Expand All @@ -28,8 +31,8 @@ def make(ff_value, string):
class ProxyType:
"""Set of possible types of proxy.

Each proxy type has 2 properties: 'ff_value' is value of Firefox
profile preference, 'string' is id of proxy type.
Each proxy type has 2 properties: 'ff_value' is value of Firefox
profile preference, 'string' is id of proxy type.
"""

DIRECT = ProxyTypeFactory.make(0, "DIRECT") # Direct connection, no proxy (default on Windows).
Expand Down Expand Up @@ -63,6 +66,14 @@ def __get__(self, obj, cls):
def __set__(self, obj, value):
if self.name == "autodetect" and not isinstance(value, bool):
raise ValueError("Autodetect proxy value needs to be a boolean")
if self.name == "ftpProxy":
# TODO: Remove ftpProxy in future version and remove deprecation warning
# https://github.com/SeleniumHQ/selenium/issues/15905
warnings.warn(
"ftpProxy is deprecated and will be removed in the future",
DeprecationWarning,
stacklevel=2,
)
getattr(obj, "_verify_proxy_type_compatibility")(self.p_type)
setattr(obj, "proxyType", self.p_type)
setattr(obj, self.name, value)
Expand All @@ -74,7 +85,7 @@ class Proxy:

proxyType = ProxyType.UNSPECIFIED
autodetect = False
ftpProxy = ""
ftpProxy = "" # TODO: Remove ftpProxy in future version and remove deprecation warning
httpProxy = ""
noProxy = ""
proxyAutoconfigUrl = ""
Expand All @@ -100,6 +111,7 @@ class Proxy:
`value`: `str`
"""

# TODO: Remove ftpProxy in future version and remove deprecation warning
ftp_proxy = _ProxyTypeDescriptor("ftpProxy", ProxyType.MANUAL)
"""Gets and Sets `ftp_proxy`

Expand Down Expand Up @@ -244,7 +256,14 @@ def __init__(self, raw=None):
if raw:
if "proxyType" in raw and raw["proxyType"]:
self.proxy_type = ProxyType.load(raw["proxyType"])
# TODO: Remove ftpProxy in future version and remove deprecation warning
# https://github.com/SeleniumHQ/selenium/issues/15905
if "ftpProxy" in raw and raw["ftpProxy"]:
warnings.warn(
"ftpProxy is deprecated and will be removed in the future",
DeprecationWarning,
stacklevel=2,
)
self.ftp_proxy = raw["ftpProxy"]
if "httpProxy" in raw and raw["httpProxy"]:
self.http_proxy = raw["httpProxy"]
Expand Down Expand Up @@ -288,6 +307,7 @@ def _verify_proxy_type_compatibility(self, compatible_proxy):

def to_capabilities(self):
proxy_caps = {"proxyType": self.proxyType["string"].lower()}
# TODO: Remove ftpProxy in future version and remove deprecation warning
proxies = [
"autodetect",
"ftpProxy",
Expand Down
8 changes: 8 additions & 0 deletions py/test/selenium/webdriver/common/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

MANUAL_PROXY = {
"httpProxy": "some.url:1234",
# TODO: Remove ftpProxy in future (currently deprecated)
# https://github.com/SeleniumHQ/selenium/issues/15905
"ftpProxy": "ftp.proxy",
"noProxy": "localhost, foo.localhost",
"sslProxy": "ssl.proxy:1234",
Expand All @@ -43,6 +45,8 @@
def test_can_add_manual_proxy_to_options():
proxy = Proxy()
proxy.http_proxy = MANUAL_PROXY["httpProxy"]
# TODO: Remove ftpProxy in future (currently deprecated)
# https://github.com/SeleniumHQ/selenium/issues/15905
proxy.ftp_proxy = MANUAL_PROXY["ftpProxy"]
proxy.no_proxy = MANUAL_PROXY["noProxy"]
proxy.sslProxy = MANUAL_PROXY["sslProxy"]
Expand Down Expand Up @@ -98,6 +102,8 @@ def test_can_init_manual_proxy():

assert ProxyType.MANUAL == proxy.proxy_type
assert MANUAL_PROXY["httpProxy"] == proxy.http_proxy
# TODO: Remove ftpProxy in future (currently deprecated)
# https://github.com/SeleniumHQ/selenium/issues/15905
assert MANUAL_PROXY["ftpProxy"] == proxy.ftp_proxy
assert MANUAL_PROXY["noProxy"] == proxy.no_proxy
assert MANUAL_PROXY["sslProxy"] == proxy.sslProxy
Expand All @@ -123,6 +129,8 @@ def test_can_init_empty_proxy():
proxy = Proxy()
assert ProxyType.UNSPECIFIED == proxy.proxy_type
assert "" == proxy.http_proxy
# TODO: Remove ftpProxy in future (currently deprecated)
# https://github.com/SeleniumHQ/selenium/issues/15905
assert "" == proxy.ftp_proxy
assert "" == proxy.no_proxy
assert "" == proxy.sslProxy
Expand Down
Loading