Skip to content

Commit

Permalink
update proxyType values to match w3c spec
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 11, 2023
1 parent e586190 commit 04c0159
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 50 deletions.
19 changes: 9 additions & 10 deletions dotnet/src/webdriver/Proxy.cs
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
}
Expand Down Expand Up @@ -488,7 +484,10 @@ public void AddBypassAddresses(IEnumerable<string> addressesToAdd)
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
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
27 changes: 9 additions & 18 deletions py/selenium/webdriver/common/proxy.py
Expand Up @@ -17,28 +17,17 @@
"""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):
Expand Down Expand Up @@ -72,7 +61,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,12 +270,14 @@ 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):
if not self.proxyType:
raise ValueError("proxyType must be specified before use")
proxy_caps = {"proxyType": self.proxyType["string"].lower()}
proxies = [
"autodetect",
Expand Down
7 changes: 3 additions & 4 deletions rb/lib/selenium/webdriver/common/proxy.rb
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
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

0 comments on commit 04c0159

Please sign in to comment.