Bug 1359417 WebExtensions ProxyAPI uses HTTPS proxy instead of HTTP proxy and Bug 1362798 WebExtensions ProxyAPI should support return strings HTTP and SOCKS4 draft
authorEric Jung <eric@ericjung.net>
Fri, 12 May 2017 12:18:28 -0600
changeset 579861 69af6b119c038f7c79dcbfa97f7e3b22d8997dac
parent 573556 37a5b7f6f101df2eb292b1b6baaf1540c9920e20
child 629133 a567cd64cf1b6c15e586dc1aa3ed92f4bc606a21
push id59386
push userbmo:eric@ericjung.net
push dateWed, 17 May 2017 21:21:43 +0000
bugs1359417, 1362798
milestone55.0a1
Bug 1359417 WebExtensions ProxyAPI uses HTTPS proxy instead of HTTP proxy and Bug 1362798 WebExtensions ProxyAPI should support return strings HTTP and SOCKS4 MozReview-Commit-ID: GSxv0s8RPbo
toolkit/components/extensions/ProxyScriptContext.jsm
toolkit/components/extensions/test/xpcshell/test_proxy_scripts.js
--- a/toolkit/components/extensions/ProxyScriptContext.jsm
+++ b/toolkit/components/extensions/ProxyScriptContext.jsm
@@ -38,17 +38,19 @@ const {
   LocalAPIImplementation,
   SchemaAPIManager,
 } = ExtensionCommon;
 
 const PROXY_TYPES = Object.freeze({
   DIRECT: "direct",
   HTTPS: "https",
   PROXY: "proxy",
-  SOCKS: "socks",
+  HTTP: "http", // Synonym for PROXY_TYPES.PROXY
+  SOCKS: "socks",  // SOCKS5
+  SOCKS4: "socks4",
 });
 
 class ProxyScriptContext extends BaseContext {
   constructor(extension, url, contextInfo = {}) {
     super("proxy_script", extension);
     this.contextInfo = contextInfo;
     this.extension = extension;
     this.messageManager = Services.cpmm;
@@ -170,35 +172,40 @@ class ProxyScriptContext extends BaseCon
       });
       return null;
     }
 
     parts[0] = parts[0].toLowerCase();
 
     switch (parts[0]) {
       case PROXY_TYPES.PROXY:
+      case PROXY_TYPES.HTTP:
+      case PROXY_TYPES.HTTPS:
       case PROXY_TYPES.SOCKS:
+      case PROXY_TYPES.SOCKS4:
         if (!parts[1]) {
           this.extension.emit("proxy-error", {
             message: `FindProxyForURL: Missing argument for "${parts[0]}"`,
           });
           return null;
         }
 
         let [host, port] = parts[1].split(":");
         if (!host || !port) {
           this.extension.emit("proxy-error", {
             message: `FindProxyForURL: Unable to parse argument for ${rule}`,
           });
           return null;
         }
 
-        let type = PROXY_TYPES.SOCKS;
+        let type = parts[0];
         if (parts[0] == PROXY_TYPES.PROXY) {
-          type = PROXY_TYPES.HTTPS;
+          // PROXY_TYPES.HTTP and PROXY_TYPES.PROXY are synonyms
+          // but ProxyService.newProxyInfo() does not accept "proxy"
+          type = PROXY_TYPES.HTTP;
         }
 
         let failoverProxy = this.createProxyInfo(rules.slice(1));
         return ProxyService.newProxyInfo(type, host, port, 0,
           PROXY_TIMEOUT_SEC, failoverProxy);
       case PROXY_TYPES.DIRECT:
         return null;
       default:
--- a/toolkit/components/extensions/test/xpcshell/test_proxy_scripts.js
+++ b/toolkit/components/extensions/test/xpcshell/test_proxy_scripts.js
@@ -151,17 +151,17 @@ add_task(function* testProxyScriptWithUn
         return "UNEXPECTED 1.2.3.4:8080";
       }
     },
   }, {
     proxyInfo: null,
   });
 });
 
-add_task(function* testSocksReturnType() {
+add_task(function* testSocksReturnTypeWithHostCheck() {
   yield testProxyScript({
     scriptData() {
       function FindProxyForURL(url, host) {
         if (host === "www.mozilla.org") {
           return "SOCKS 4.4.4.4:9002";
         }
       }
     },
@@ -170,27 +170,78 @@ add_task(function* testSocksReturnType()
       host: "4.4.4.4",
       port: "9002",
       type: "socks",
       failoverProxy: null,
     },
   });
 });
 
+add_task(function* testSocksReturnType() {
+  yield testProxyScript({
+    scriptData() {
+      function FindProxyForURL(url, host) {
+        return "SOCKS foo.bar:1080";
+      }
+    },
+  }, {
+    proxyInfo: {
+      host: "foo.bar",
+      port: "1080",
+      type: "socks",
+      failoverProxy: null,
+    },
+  });
+});
+
+add_task(function* testSocks4ReturnType() {
+  yield testProxyScript({
+    scriptData() {
+      function FindProxyForURL(url, host) {
+        return "SOCKS4 1.2.3.4:1080";
+      }
+    },
+  }, {
+    proxyInfo: {
+      host: "1.2.3.4",
+      port: "1080",
+      type: "socks4",
+      failoverProxy: null,
+    },
+  });
+});
+
 add_task(function* testProxyReturnType() {
   yield testProxyScript({
     scriptData() {
       function FindProxyForURL(url, host) {
         return "PROXY 1.2.3.4:8080";
       }
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
+      type: "http",
+      failoverProxy: null,
+    },
+  });
+});
+
+add_task(function* testHTTPSProxyReturnType() {
+  yield testProxyScript({
+    scriptData() {
+      function FindProxyForURL(url, host) {
+        return "HTTPS 1.2.3.4:8080";
+      }
+    },
+  }, {
+    proxyInfo: {
+      host: "1.2.3.4",
+      port: "8080",
       type: "https",
       failoverProxy: null,
     },
   });
 });
 
 add_task(function* testUnusualWhitespaceForFindProxyForURL() {
   yield testProxyScript({
@@ -198,51 +249,51 @@ add_task(function* testUnusualWhitespace
       function FindProxyForURL(url, host) {
         return "   PROXY    1.2.3.4:8080      ";
       }
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
-      type: "https",
+      type: "http",
       failoverProxy: null,
     },
   });
 });
 
 add_task(function* testInvalidProxyScriptIgnoresFailover() {
   yield testProxyScript({
     scriptData() {
       function FindProxyForURL(url, host) {
         return "PROXY 1.2.3.4:8080; UNEXPECTED; SOCKS 1.2.3.4:8080";
       }
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
-      type: "https",
+      type: "http",
       failoverProxy: null,
     },
   });
 });
 
 add_task(function* testProxyScriptWithValidFailovers() {
   yield testProxyScript({
     scriptData() {
       function FindProxyForURL(url, host) {
         return "PROXY 1.2.3.4:8080; SOCKS 4.4.4.4:9000; DIRECT";
       }
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
-      type: "https",
+      type: "http",
       failoverProxy: {
         host: "4.4.4.4",
         port: "9000",
         type: "socks",
         failoverProxy: null,
       },
     },
   });
@@ -254,17 +305,17 @@ add_task(function* testProxyScriptWithAn
       function FindProxyForURL(url, host) {
         return "PROXY 1.2.3.4:8080; INVALID 1.2.3.4:9090; SOCKS 4.4.4.4:9000; DIRECT";
       }
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
-      type: "https",
+      type: "http",
       failoverProxy: null,
     },
   });
 });
 
 add_task(function* testProxyScriptWithEmptyFailovers() {
   yield testProxyScript({
     scriptData() {
@@ -309,13 +360,13 @@ add_task(function* testProxyScriptWithRu
     },
     runtimeMessage: {
       host: "www.mozilla.org",
     },
   }, {
     proxyInfo: {
       host: "1.2.3.4",
       port: "8080",
-      type: "https",
+      type: "http",
       failoverProxy: null,
     },
   });
 });