Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update proxyType values to match w3c spec #13285

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
19 changes: 9 additions & 10 deletions dotnet/src/webdriver/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ namespace OpenQA.Selenium
/// <summary>
/// Describes the kind of proxy.
/// </summary>
/// <remarks>
/// Keep these in sync with the Firefox preferences numbers:
/// http://kb.mozillazine.org/Network.proxy.type
/// </remarks>
public enum ProxyKind
{
/// <summary>
/// Direct connection, no proxy (default on Windows).
/// Direct connection, no proxy.
/// </summary>
Direct = 0,
Direct,

/// <summary>
/// Manual proxy settings (e.g., for httpProxy).
Expand All @@ -51,15 +47,15 @@ public enum ProxyKind
/// <summary>
/// Use proxy automatic detection.
/// </summary>
AutoDetect = 4,
AutoDetect,

/// <summary>
/// Use the system values for proxy settings (default on Linux).
/// Use the system values for proxy settings.
/// </summary>
System,

/// <summary>
/// No proxy type is specified.
/// No proxy type is specified. This must be changed before use
/// </summary>
Unspecified
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -496,7 +492,10 @@ internal Dictionary<string, object> ToLegacyCapability()
private Dictionary<string, object> AsDictionary(bool isSpecCompliant)
{
Dictionary<string, object> serializedDictionary = null;
if (this.proxyKind != ProxyKind.Unspecified)
if (this.proxyKind == ProxyKind.Unspecified) {
throw new InvalidOperationException("proxyKind must be set before use");
}
else
{
serializedDictionary = new Dictionary<string, object>();
if (this.proxyKind == ProxyKind.ProxyAutoConfigure)
Expand Down
22 changes: 8 additions & 14 deletions java/src/org/openqa/selenium/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,12 @@
public class Proxy {

public enum ProxyType {
// Keep these in sync with the Firefox preferences numbers:
// http://kb.mozillazine.org/Network.proxy.type

DIRECT("direct"), // Direct connection, no proxy (default on Windows)
DIRECT("direct"), // Direct connection, no proxy
MANUAL("manual"), // Manual proxy settings (e.g. for httpProxy)
PAC("pac"), // Proxy auto-configuration from URL

RESERVED_1("reserved_1"), // Never used (but reserved in Firefox)

AUTODETECT("autodetect"), // Proxy auto-detection (presumably with WPAD)
SYSTEM("system"), // Use system settings (default on Linux)

UNSPECIFIED("unspecified");
SYSTEM("system"), // Use system settings
UNSPECIFIED("unspecified"); // This must be changed before using

private final String type;

Expand Down Expand Up @@ -127,7 +120,9 @@ public Proxy(Map<String, ?> raw) {
public Map<String, Object> toJson() {
Map<String, Object> m = new HashMap<>();

if (proxyType != ProxyType.UNSPECIFIED) {
if (proxyType == ProxyType.UNSPECIFIED) {
throw new IllegalStateException("proxyType must be specified before use");
} else {
m.put(PROXY_TYPE, proxyType.toString());
}
if (ftpProxy != null) {
Expand Down Expand Up @@ -165,7 +160,7 @@ public Map<String, Object> toJson() {

/**
* Gets the {@link ProxyType}. This can signal if set to use a direct connection (without proxy),
* manually set proxy settings, auto-configured proxy settings, or whether to use the default
* manually set proxy settings, autoconfigured proxy settings, or whether to use the default
* system proxy settings. It defaults to {@link ProxyType#UNSPECIFIED}.
*
* @return the proxy type employed
Expand Down Expand Up @@ -198,7 +193,7 @@ public boolean isAutodetect() {
/**
* Specifies whether to autodetect proxy settings.
*
* @param autodetect set to true to use proxy auto detection, false to leave proxy settings
* @param autodetect set to true to use proxy auto-detection, false to leave proxy settings
* unspecified
* @return reference to self
*/
Expand Down Expand Up @@ -455,7 +450,6 @@ public String toString() {
builder.append("pac: ").append(getProxyAutoconfigUrl());
break;

case RESERVED_1:
case UNSPECIFIED:
break;
}
Expand Down
34 changes: 12 additions & 22 deletions py/selenium/webdriver/common/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,26 @@
"""The Proxy implementation."""


class ProxyTypeFactory:
"""Factory for proxy types."""

@staticmethod
def make(ff_value, string):
return {"ff_value": ff_value, "string": 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.
"""

DIRECT = ProxyTypeFactory.make(0, "DIRECT") # Direct connection, no proxy (default on Windows).
MANUAL = ProxyTypeFactory.make(1, "MANUAL") # Manual proxy settings (e.g., for httpProxy).
PAC = ProxyTypeFactory.make(2, "PAC") # Proxy autoconfiguration from URL.
RESERVED_1 = ProxyTypeFactory.make(3, "RESERVED1") # Never used.
AUTODETECT = ProxyTypeFactory.make(4, "AUTODETECT") # Proxy autodetection (presumably with WPAD).
SYSTEM = ProxyTypeFactory.make(5, "SYSTEM") # Use system settings (default on Linux).
UNSPECIFIED = ProxyTypeFactory.make(6, "UNSPECIFIED") # Not initialized (for internal use).
DIRECT = "DIRECT" # Direct connection, no proxy
MANUAL = "MANUAL" # Manual proxy settings (e.g., for httpProxy).
PAC = "PAC" # Proxy autoconfiguration from URL.
AUTODETECT = "AUTODETECT" # Proxy auto-detection (presumably with WPAD).
SYSTEM = "SYSTEM" # Use system settings

@classmethod
def load(cls, value):
if isinstance(value, dict) and "string" in value:
value = value["string"]
value = str(value).upper()
for attr in dir(cls):
attr_value = getattr(cls, attr)
if isinstance(attr_value, dict) and "string" in attr_value and attr_value["string"] == value:
return attr_value
if getattr(cls, attr) == value:
return value
raise Exception(f"No proxy type is found for {value}")


Expand All @@ -72,7 +60,7 @@ class Proxy:
"""Proxy contains information about proxy type and necessary proxy
settings."""

proxyType = ProxyType.UNSPECIFIED
proxyType = None
autodetect = False
ftpProxy = ""
httpProxy = ""
Expand Down Expand Up @@ -281,13 +269,15 @@ def proxy_type(self, value) -> None:
self.proxyType = value

def _verify_proxy_type_compatibility(self, compatible_proxy):
if self.proxyType not in (ProxyType.UNSPECIFIED, compatible_proxy):
if self.proxyType not in (None, compatible_proxy):
raise ValueError(
f"Specified proxy type ({compatible_proxy}) not compatible with current setting ({self.proxyType})"
)

def to_capabilities(self):
proxy_caps = {"proxyType": self.proxyType["string"].lower()}
if not self.proxyType:
raise ValueError("proxyType must be specified before use")
proxy_caps = {"proxyType": self.proxyType.lower()}
proxies = [
"autodetect",
"ftpProxy",
Expand Down
10 changes: 4 additions & 6 deletions py/test/selenium/webdriver/common/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def test_can_init_pacproxy():
assert PAC_PROXY["proxyAutoconfigUrl"] == proxy.proxy_autoconfig_url


def test_can_init_empty_proxy():
def test_errors_on_empty_proxy():
proxy = Proxy()
assert ProxyType.UNSPECIFIED == proxy.proxy_type
assert proxy.proxy_type is None
assert "" == proxy.http_proxy
assert "" == proxy.ftp_proxy
assert "" == proxy.no_proxy
Expand All @@ -135,8 +135,6 @@ def test_can_init_empty_proxy():
assert proxy.socks_version is None

options = ArgOptions()
options.proxy = proxy

proxy_capabilities = {}
proxy_capabilities["proxyType"] = "unspecified"
assert proxy_capabilities == options.to_capabilities().get("proxy")
with pytest.raises(ValueError):
options.proxy = proxy
7 changes: 3 additions & 4 deletions rb/lib/selenium/webdriver/common/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ module Selenium
module WebDriver
class Proxy
TYPES = {
direct: 'DIRECT', # Direct connection, no proxy (default on Windows).
direct: 'DIRECT', # Direct connection, no proxy.
manual: 'MANUAL', # Manual proxy settings (e.g., for httpProxy).
pac: 'PAC', # Proxy autoconfiguration from URL.
auto_detect: 'AUTODETECT', # Proxy autodetection (presumably with WPAD).
system: 'SYSTEM' # Use system settings (default on Linux).
auto_detect: 'AUTODETECT', # Proxy auto-detection (presumably with WPAD).
system: 'SYSTEM' # Use system settings.
}.freeze

ALLOWED = {type: 'proxyType',
Expand All @@ -44,7 +44,6 @@ class Proxy

def self.json_create(data)
data['proxyType'] = data['proxyType'].downcase.to_sym
return if data['proxyType'] == :unspecified

proxy = new

Expand Down
4 changes: 0 additions & 4 deletions rb/spec/unit/selenium/webdriver/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ module WebDriver

expect(proxy).to eq(other)
end

it 'deserializes to nil if proxyType is UNSPECIFIED' do
expect(described_class.json_create('proxyType' => 'UNSPECIFIED')).to be_nil
end
end
end # WebDriver
end # Selenium
Loading