webdriver: Add "noProxy" support for manual proxy type (#121)
authorHenrik Skupin <hskupin@mozilla.com>
Wed, 30 Aug 2017 21:02:55 +0200
changeset 428168 d42ac5c19480cc34f3e730e3a4a0691fccbed47e
parent 428167 7a1f04b90639a3d58a5210cc144b4db7f7a58323
child 428169 a12424febc5e41c5d52d77fb01f6b86f0150f6cd
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone57.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
webdriver: Add "noProxy" support for manual proxy type (#121) Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 89df5f92278488697460b279eea0708e482c3813 committer: GitHub <noreply@github.com>
testing/webdriver/src/capabilities.rs
--- a/testing/webdriver/src/capabilities.rs
+++ b/testing/webdriver/src/capabilities.rs
@@ -167,16 +167,17 @@ impl SpecNewSessionParameters {
                     },
                     None => return Err(WebDriverError::new(
                         ErrorStatus::InvalidArgument,
                         "proxyAutoconfigUrl was not a string"
                     ))
                 },
                 "ftpProxy" => try!(SpecNewSessionParameters::validate_host(value)),
                 "httpProxy" => try!(SpecNewSessionParameters::validate_host(value)),
+                "noProxy" => try!(SpecNewSessionParameters::validate_no_proxy(value)),
                 "sslProxy" => try!(SpecNewSessionParameters::validate_host(value)),
                 "socksProxy" => try!(SpecNewSessionParameters::validate_host(value)),
                 "socksVersion" => if !value.is_number() {
                     return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
                                                    "socksVersion was not a number"))
                 },
                 "socksUsername" => if !value.is_string() {
                     return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
@@ -189,16 +190,38 @@ impl SpecNewSessionParameters {
                 x => return Err(WebDriverError::new(
                     ErrorStatus::InvalidArgument,
                     format!("{} was not a valid proxy configuration capability", x)))
             }
         }
         Ok(())
     }
 
+    fn validate_no_proxy(value: &Json) -> WebDriverResult<()> {
+        match value.as_array() {
+            Some(hosts) => {
+                for host in hosts {
+                    match host.as_string() {
+                        Some(_) => {},
+                        None => return Err(WebDriverError::new(
+                            ErrorStatus::InvalidArgument,
+                            format!("{} was not a string", host)
+                        ))
+                    }
+                }
+            },
+            None => return Err(WebDriverError::new(
+                ErrorStatus::InvalidArgument,
+                format!("{} was not an array", value)
+            ))
+        }
+
+        Ok(())
+    }
+
     /// Validate whether a named capability is JSON value is a string containing a host
     /// and possible port
     fn validate_host(value: &Json) -> WebDriverResult<()> {
         match value.as_string() {
             Some(host) => {
                 if host.contains("://") {
                     return Err(WebDriverError::new(
                         ErrorStatus::InvalidArgument,
@@ -492,29 +515,37 @@ impl ToJson for LegacyNewSessionParamete
     }
 }
 
 #[cfg(test)]
 mod tests {
     use rustc_serialize::json::Json;
     use super::{WebDriverResult, SpecNewSessionParameters};
 
-    fn validate_host(value: &str) -> WebDriverResult<()> {
-        SpecNewSessionParameters::validate_host(&Json::String(value.into()))
+    fn validate_proxy(value: &str) -> WebDriverResult<()> {
+        let data = Json::from_str(value).unwrap();
+        SpecNewSessionParameters::validate_proxy(&data)
     }
 
     #[test]
-    fn test_validate_host() {
-        validate_host("127.0.0.1").unwrap();
-        validate_host("127.0.0.1:").unwrap();
-        validate_host("127.0.0.1:3128").unwrap();
-        validate_host("[2001:db8::1]").unwrap();
-        validate_host("[2001:db8::1]:3128").unwrap();
-        validate_host("localhost").unwrap();
-        validate_host("localhost:3128").unwrap();
-        validate_host("example.org").unwrap();
-        validate_host("example.org:3128").unwrap();
+    fn test_validate_proxy() {
+        // proxy hosts
+        validate_proxy("{\"httpProxy\": \"127.0.0.1\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"127.0.0.1:\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"127.0.0.1:3128\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"localhost\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"localhost:3128\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"[2001:db8::1]\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"[2001:db8::1]:3128\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"example.org\"}").unwrap();
+        validate_proxy("{\"httpProxy\": \"example.org:3128\"}").unwrap();
 
-        assert!(validate_host("http://example.org").is_err());  // existing scheme
-        assert!(validate_host("example.org:-1").is_err());  // invalid port
-        assert!(validate_host("2001:db8::1").is_err());  // missing brackets
+        assert!(validate_proxy("{\"httpProxy\": \"http://example.org\"}").is_err());
+        assert!(validate_proxy("{\"httpProxy\": \"example.org:-1\"}").is_err());
+        assert!(validate_proxy("{\"httpProxy\": \"2001:db8::1\"}").is_err());
+
+        // no proxy for manual proxy type
+        validate_proxy("{\"noProxy\": [\"foo\"]}").unwrap();
+
+        assert!(validate_proxy("{\"noProxy\": \"foo\"}").is_err());
+        assert!(validate_proxy("{\"noProxy\": [42]}").is_err());
     }
 }