Bug 1369827 - Fix socksVersion key in proxy capabilities. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 23 Aug 2017 11:47:01 +0200
changeset 655952 eebb247b1e36ca0c673ec0c73a7700c28d35ecdd
parent 655951 35c7af22ff9332b1de6fac660efe74531ac73df2
child 655953 9d7efda3174fe1fc831155abd70871b752735600
push id77013
push userbmo:hskupin@gmail.com
push dateWed, 30 Aug 2017 15:59:42 +0000
bugs1369827
milestone57.0a1
Bug 1369827 - Fix socksVersion key in proxy capabilities. In the spec the socksProxyVersion key has been renamed to socksVersion. Marionette has to be adjusted for this change. MozReview-Commit-ID: Ep3zNZLKxXl
testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
testing/marionette/session.js
testing/marionette/test_session.js
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
@@ -53,16 +53,36 @@ class TestProxyCapabilities(MarionetteTe
 
     def test_proxy_type_manual_without_port(self):
         proxy_hostname = "marionette.test"
         capabilities = {"proxy": {
             "proxyType": "manual",
             "ftpProxy": "{}:21".format(proxy_hostname),
             "httpProxy": "{}:80".format(proxy_hostname),
             "sslProxy": "{}:443".format(proxy_hostname),
+            "socksProxy": proxy_hostname,
+            "socksVersion": 4,
+        }}
+
+        self.marionette.start_session(capabilities)
+        self.assertEqual(self.marionette.session_capabilities["proxy"],
+                         capabilities["proxy"])
+
+    def test_proxy_type_manual_socks_requires_version(self):
+        proxy_port = 4444
+        proxy_hostname = "marionette.test"
+        proxy_host = "{}:{}".format(proxy_hostname, proxy_port)
+        capabilities = {"proxy": {
+            "proxyType": "manual",
+            "socksProxy": proxy_host,
+        }}
+
+        with self.assertRaises(errors.SessionNotCreatedException):
+            self.marionette.start_session(capabilities)
+
     def test_proxy_type_pac(self):
         pac_url = "http://marionette.test"
         capabilities = {"proxy": {"proxyType": "pac", "proxyAutoconfigUrl": pac_url}}
 
         self.marionette.start_session(capabilities)
         self.assertEqual(self.marionette.session_capabilities["proxy"],
                          capabilities["proxy"])
 
@@ -91,8 +111,14 @@ class TestProxyCapabilities(MarionetteTe
 
     def test_invalid_autoconfig_url_for_pac(self):
         with self.assertRaises(errors.SessionNotCreatedException):
             self.marionette.start_session({"proxy": {"proxyType": "pac"}})
 
         with self.assertRaises(errors.SessionNotCreatedException):
             self.marionette.start_session({"proxy": {"proxyType": "pac",
                                                      "proxyAutoconfigUrl": None}})
+
+    def test_missing_socks_version_for_manual(self):
+        capabilities = {"proxy": {"proxyType": "manual", "socksProxy": "marionette.test"}}
+
+        with self.assertRaises(errors.SessionNotCreatedException):
+            self.marionette.start_session(capabilities)
--- a/testing/marionette/session.js
+++ b/testing/marionette/session.js
@@ -271,18 +271,17 @@ session.Proxy = class {
         if (typeof json.httpProxy != "undefined") {
           [p.httpProxy, p.httpProxyPort] = fromHost("http", json.httpProxy);
         }
         if (typeof json.sslProxy != "undefined") {
           [p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
         }
         if (typeof json.socksProxy != "undefined") {
           [p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
-          p.socksProxyVersion = assert.positiveInteger(
-              json.socksProxyVersion);
+          p.socksVersion = assert.positiveInteger(json.socksVersion);
         }
         break;
 
       default:
         throw new InvalidArgumentError(
             `Invalid type of proxy: ${p.proxyType}`);
     }
 
@@ -307,17 +306,17 @@ session.Proxy = class {
     }
 
     return marshal({
       proxyType: this.proxyType,
       ftpProxy: toHost(this.ftpProxy, this.ftpProxyPort),
       httpProxy: toHost(this.httpProxy, this.httpProxyPort),
       sslProxy: toHost(this.sslProxy, this.sslProxyPort),
       socksProxy: toHost(this.socksProxy, this.socksProxyPort),
-      socksProxyVersion: this.socksProxyVersion,
+      socksVersion: this.socksVersion,
       proxyAutoconfigUrl: this.proxyAutoconfigUrl,
     });
   }
 
   toString() { return "[object session.Proxy]"; }
 };
 
 /** WebDriver session capabilities representation. */
--- a/testing/marionette/test_session.js
+++ b/testing/marionette/test_session.js
@@ -184,16 +184,21 @@ add_test(function test_Proxy_toJSON() {
   deepEqual(p.toJSON(), {proxyType: "manual"});
 
   for (let proxy of ["ftpProxy", "httpProxy", "sslProxy", "socksProxy"]) {
     let expected = {proxyType: "manual"}
 
     let manual = new session.Proxy();
     manual.proxyType = "manual";
 
+    if (proxy == "socksProxy") {
+      manual.socksVersion = 5;
+      expected.socksVersion = 5;
+    }
+
     // without port
     manual[proxy] = "foo";
     expected[proxy] = "foo"
     deepEqual(manual.toJSON(), expected);
 
     // with port
     manual[proxy] = "foo";
     manual[`${proxy}Port`] = 0;
@@ -233,18 +238,18 @@ add_test(function test_Proxy_fromJSON() 
         "2001:db8::1"]) {
       manual[proxy] = host;
       Assert.throws(() => session.Proxy.fromJSON(manual),
           InvalidArgumentError);
     }
 
     let expected = {"proxyType": "manual"};
     if (proxy == "socksProxy") {
-      manual.socksProxyVersion = 5;
-      expected.socksProxyVersion = 5;
+      manual.socksVersion = 5;
+      expected.socksVersion = 5;
     }
 
     // valid proxy hosts with port
     for (let host of ["foo:1", "foo:80", "foo:443", "foo:65535",
         "127.0.0.1:42", "[2001:db8::1]:42"]) {
       manual[proxy] = host;
       expected[proxy] = host;