Bug 1507138 fix default port usage with proxy settings, r=aswan
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 29 Nov 2018 16:19:40 +0000
changeset 507966 9b21db074305040e2058811d24f7dbc95eb4adbf
parent 507965 8d3e17a3c95e00634c8e54da19f7f8bb328e948f
child 507967 d81d2b5e6e27308135996c6105b875dd088af81f
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1507138
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507138 fix default port usage with proxy settings, r=aswan Differential Revision: https://phabricator.services.mozilla.com/D13324
toolkit/components/extensions/parent/ext-proxy.js
toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
--- a/toolkit/components/extensions/parent/ext-proxy.js
+++ b/toolkit/components/extensions/parent/ext-proxy.js
@@ -27,16 +27,23 @@ const proxySvc = Ci.nsIProtocolProxyServ
 const PROXY_TYPES_MAP = new Map([
   ["none", proxySvc.PROXYCONFIG_DIRECT],
   ["autoDetect", proxySvc.PROXYCONFIG_WPAD],
   ["system", proxySvc.PROXYCONFIG_SYSTEM],
   ["manual", proxySvc.PROXYCONFIG_MANUAL],
   ["autoConfig", proxySvc.PROXYCONFIG_PAC],
 ]);
 
+const DEFAULT_PORTS = new Map([
+  ["http", 80],
+  ["ssl", 443],
+  ["ftp", 21],
+  ["socks", 1080],
+]);
+
 ExtensionPreferencesManager.addSetting("proxy.settings", {
   prefNames: [
     "network.proxy.type",
     "network.proxy.http",
     "network.proxy.http_port",
     "network.proxy.share_proxy_settings",
     "network.proxy.ftp",
     "network.proxy.ftp_port",
@@ -61,18 +68,18 @@ ExtensionPreferencesManager.addSetting("
       "network.proxy.socks_version": value.socksVersion,
       "network.proxy.no_proxies_on": value.passthrough,
     };
 
     for (let prop of ["http", "ftp", "ssl", "socks"]) {
       if (value[prop]) {
         let url = new URL(`http://${value[prop]}`);
         prefs[`network.proxy.${prop}`] = url.hostname;
-        let port = parseInt(url.port, 10);
-        prefs[`network.proxy.${prop}_port`] = isNaN(port) ? 0 : port;
+        let port = parseInt(url.port, 10) || DEFAULT_PORTS.get(prop);
+        prefs[`network.proxy.${prop}_port`] = port;
       } else {
         prefs[`network.proxy.${prop}`] = undefined;
         prefs[`network.proxy.${prop}_port`] = undefined;
       }
     }
 
     return prefs;
   },
--- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
@@ -172,22 +172,22 @@ add_task(async function test_browser_set
     {
       proxyType: "manual",
       http: "http://www.mozilla.org",
       autoConfigUrl: "",
     },
     {
       "network.proxy.type": proxySvc.PROXYCONFIG_MANUAL,
       "network.proxy.http": "www.mozilla.org",
-      "network.proxy.http_port": 0,
+      "network.proxy.http_port": 80,
       "network.proxy.autoconfig_url": "",
     },
     {
       proxyType: "manual",
-      http: "www.mozilla.org",
+      http: "www.mozilla.org:80",
       autoConfigUrl: "",
     }
   );
 
   // When using proxyAll, we expect all proxies to be set to
   // be the same as http.
   await testProxy(
     {
@@ -240,16 +240,89 @@ add_task(async function test_browser_set
       "network.proxy.ssl_port": 8082,
       "network.proxy.socks": "mozilla.org",
       "network.proxy.socks_port": 8083,
       "network.proxy.socks_version": 4,
       "network.proxy.no_proxies_on": ".mozilla.org",
     }
   );
 
+  await testProxy(
+    {
+      proxyType: "manual",
+      http: "http://www.mozilla.org",
+      ftp: "ftp://www.mozilla.org",
+      ssl: "https://www.mozilla.org",
+      socks: "mozilla.org",
+      socksVersion: 4,
+      passthrough: ".mozilla.org",
+    },
+    {
+      "network.proxy.type": proxySvc.PROXYCONFIG_MANUAL,
+      "network.proxy.http": "www.mozilla.org",
+      "network.proxy.http_port": 80,
+      "network.proxy.share_proxy_settings": false,
+      "network.proxy.ftp": "www.mozilla.org",
+      "network.proxy.ftp_port": 21,
+      "network.proxy.ssl": "www.mozilla.org",
+      "network.proxy.ssl_port": 443,
+      "network.proxy.socks": "mozilla.org",
+      "network.proxy.socks_port": 1080,
+      "network.proxy.socks_version": 4,
+      "network.proxy.no_proxies_on": ".mozilla.org",
+    },
+    {
+      proxyType: "manual",
+      http: "www.mozilla.org:80",
+      httpProxyAll: false,
+      ftp: "www.mozilla.org:21",
+      ssl: "www.mozilla.org:443",
+      socks: "mozilla.org:1080",
+      socksVersion: 4,
+      passthrough: ".mozilla.org",
+    }
+  );
+
+
+  await testProxy(
+    {
+      proxyType: "manual",
+      http: "http://www.mozilla.org:80",
+      ftp: "ftp://www.mozilla.org:21",
+      ssl: "https://www.mozilla.org:443",
+      socks: "mozilla.org:1080",
+      socksVersion: 4,
+      passthrough: ".mozilla.org",
+    },
+    {
+      "network.proxy.type": proxySvc.PROXYCONFIG_MANUAL,
+      "network.proxy.http": "www.mozilla.org",
+      "network.proxy.http_port": 80,
+      "network.proxy.share_proxy_settings": false,
+      "network.proxy.ftp": "www.mozilla.org",
+      "network.proxy.ftp_port": 21,
+      "network.proxy.ssl": "www.mozilla.org",
+      "network.proxy.ssl_port": 443,
+      "network.proxy.socks": "mozilla.org",
+      "network.proxy.socks_port": 1080,
+      "network.proxy.socks_version": 4,
+      "network.proxy.no_proxies_on": ".mozilla.org",
+    },
+    {
+      proxyType: "manual",
+      http: "www.mozilla.org:80",
+      httpProxyAll: false,
+      ftp: "www.mozilla.org:21",
+      ssl: "www.mozilla.org:443",
+      socks: "mozilla.org:1080",
+      socksVersion: 4,
+      passthrough: ".mozilla.org",
+    }
+  );
+
   // Test resetting values.
   await testProxy(
     {
       proxyType: "none",
       http: "",
       ftp: "",
       ssl: "",
       socks: "",