Bug 1369827 - Vendoring in webdriver 0.30. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 18 Aug 2017 15:18:19 +0200
changeset 651182 0b87577d9ea04b45bf63a0800b45c0395a7cd56e
parent 651181 1438ef94372a6eb97419aef34bede4697b435c10
child 651183 8384fa719fb23158acb0fad21a853bf10bfb6878
push id75622
push userbmo:hskupin@gmail.com
push dateWed, 23 Aug 2017 09:48:18 +0000
bugs1369827
milestone57.0a1
Bug 1369827 - Vendoring in webdriver 0.30. MozReview-Commit-ID: C8vP6itpEXi
third_party/rust/webdriver/.cargo-checksum.json
third_party/rust/webdriver/Cargo.toml
third_party/rust/webdriver/src/capabilities.rs
--- a/third_party/rust/webdriver/.cargo-checksum.json
+++ b/third_party/rust/webdriver/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"78252ef89a407b1d76616b7afbf7afb8205530a7f7039f3a7ea140684e3aa8bc","Cargo.toml":"b0f014ae89a79a1923c0209445f65935adf26fabbea19af22a62fc4c51bfb016","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"bd0e99ce271903a9f67cf5f8fca2f67f2583e4336fbaf583fcd78ec238d4176e","src/capabilities.rs":"3ced096444da586e077b0d62fb515f757e7809063e0c65fd7435678c8a8641b3","src/command.rs":"3538491c5e77746eca8d326185903f3336e47f75f69401167acbd655708e736a","src/common.rs":"79d50f6c29f16d370b707988fe7b1747e17372f979df75d30be3e250dce55836","src/error.rs":"7621e0c325c488b537e1bd26dd580b23863bf07bbae52cf8b77e6a7d37df47c3","src/httpapi.rs":"83fec1cefedbadb8bf7458374f909a44ff76d67046e8428fc01067d5d8401dc6","src/lib.rs":"336c146e934711dfe49f4b44bbcf278686b00be8d89abb9c7b7b045254994fbf","src/macros.rs":"93094c48e3880d925e684fba9678693eb8c0c39c7ed47b130b0751c4bca37ddc","src/response.rs":"160bc15135d623d1bc5b33c6edaf69a4034d36c1cd8d9cefb64f436001dda01e","src/server.rs":"4f8976a215783c98f1e3927e5440590fe3a41189bf62fea151434598f904753c"},"package":"3aa46482421441f1954f5df7443a66e5744e8de22a3d825262157b109dbdd535"}
\ No newline at end of file
+{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"78252ef89a407b1d76616b7afbf7afb8205530a7f7039f3a7ea140684e3aa8bc","Cargo.toml":"9ce1bfb98e94cb9f2494676ef0cc741dcfeab1b60d7f5fa23ae261b02025bc1c","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"bd0e99ce271903a9f67cf5f8fca2f67f2583e4336fbaf583fcd78ec238d4176e","src/capabilities.rs":"12a71bf787f1102435f9c2ae2c357acf397b80fadcb3355710ef9bbc39d8a337","src/command.rs":"3538491c5e77746eca8d326185903f3336e47f75f69401167acbd655708e736a","src/common.rs":"79d50f6c29f16d370b707988fe7b1747e17372f979df75d30be3e250dce55836","src/error.rs":"7621e0c325c488b537e1bd26dd580b23863bf07bbae52cf8b77e6a7d37df47c3","src/httpapi.rs":"83fec1cefedbadb8bf7458374f909a44ff76d67046e8428fc01067d5d8401dc6","src/lib.rs":"336c146e934711dfe49f4b44bbcf278686b00be8d89abb9c7b7b045254994fbf","src/macros.rs":"93094c48e3880d925e684fba9678693eb8c0c39c7ed47b130b0751c4bca37ddc","src/response.rs":"160bc15135d623d1bc5b33c6edaf69a4034d36c1cd8d9cefb64f436001dda01e","src/server.rs":"4f8976a215783c98f1e3927e5440590fe3a41189bf62fea151434598f904753c"},"package":"b05f860c230757d0df161f6b2db8820ca636940689b29b148ea53bd8685feb84"}
\ No newline at end of file
--- a/third_party/rust/webdriver/Cargo.toml
+++ b/third_party/rust/webdriver/Cargo.toml
@@ -7,40 +7,40 @@
 #
 # If you believe there's an error in this file please file an
 # issue against the rust-lang/cargo repository. If you're
 # editing this file be aware that the upstream Cargo.toml
 # will likely look very different (and much more reasonable)
 
 [package]
 name = "webdriver"
-version = "0.29.0"
+version = "0.30.0"
 authors = ["Mozilla Tools and Automation <tools@lists.mozilla.com>"]
 description = "Library implementing the wire protocol for the W3C WebDriver specification"
 documentation = "https://docs.rs/webdriver"
 readme = "README.md"
 keywords = ["webdriver", "browser", "automation", "protocol", "w3c"]
 license = "MPL-2.0"
 repository = "https://github.com/mozilla/webdriver-rust"
-[dependencies.regex]
-version = "0.2"
+[dependencies.time]
+version = "0.1"
 
-[dependencies.url]
-version = "1"
+[dependencies.rustc-serialize]
+version = "0.3"
+
+[dependencies.backtrace]
+version = "0.3"
 
 [dependencies.log]
 version = "0.3"
 
-[dependencies.hyper]
-version = "0.10"
-
-[dependencies.rustc-serialize]
-version = "0.3"
-
 [dependencies.cookie]
 version = "0.9"
 default-features = false
 
-[dependencies.time]
-version = "0.1"
+[dependencies.url]
+version = "1"
 
-[dependencies.backtrace]
-version = "0.3"
+[dependencies.hyper]
+version = "0.10"
+
+[dependencies.regex]
+version = "0.2"
--- a/third_party/rust/webdriver/src/capabilities.rs
+++ b/third_party/rust/webdriver/src/capabilities.rs
@@ -1,13 +1,12 @@
 use command::Parameters;
 use error::{ErrorStatus, WebDriverError, WebDriverResult};
 use rustc_serialize::json::{Json, ToJson};
 use std::collections::BTreeMap;
-use std::net::Ipv6Addr;
 use url::Url;
 
 pub type Capabilities = BTreeMap<String, Json>;
 
 /// Trait for objects that can be used to inspect browser capabilities
 ///
 /// The main methods in this trait are called with a Capabilites object
 /// resulting from a full set of potential capabilites for the session.
@@ -166,24 +165,24 @@ impl SpecNewSessionParameters {
                             ErrorStatus::InvalidArgument,
                             "proxyAutoconfigUrl was not a valid url"))));
                     },
                     None => return Err(WebDriverError::new(
                         ErrorStatus::InvalidArgument,
                         "proxyAutoconfigUrl was not a string"
                     ))
                 },
-                "ftpProxy" => try!(SpecNewSessionParameters::validate_host_domain("ftpProxy", "ftp", obj, value)),
-                "ftpProxyPort" => try!(SpecNewSessionParameters::validate_port("ftpProxyPort", value)),
-                "httpProxy" => try!(SpecNewSessionParameters::validate_host_domain("httpProxy", "http", obj, value)),
-                "httpProxyPort" => try!(SpecNewSessionParameters::validate_port("httpProxyPort", value)),
-                "sslProxy" => try!(SpecNewSessionParameters::validate_host_domain("sslProxy", "http", obj, value)),
-                "sslProxyPort" => try!(SpecNewSessionParameters::validate_port("sslProxyPort", value)),
-                "socksProxy" => try!(SpecNewSessionParameters::validate_host_domain("socksProxy", "ssh", obj, value)),
-                "socksProxyPort" => try!(SpecNewSessionParameters::validate_port("socksProxyPort", value)),
+                "ftpProxy" => try!(SpecNewSessionParameters::validate_host(value)),
+                "httpProxy" => try!(SpecNewSessionParameters::validate_host(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,
                                                    "socksUsername was not a string"))
                 },
                 "socksPassword" => if !value.is_string() {
                     return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
                                                    "socksPassword was not a string"))
                 },
@@ -192,86 +191,49 @@ impl SpecNewSessionParameters {
                     format!("{} was not a valid proxy configuration capability", x)))
             }
         }
         Ok(())
     }
 
     /// Validate whether a named capability is JSON value is a string containing a host
     /// and possible port
-    fn validate_host_domain(name: &str,
-                            scheme: &str,
-                            obj: &Capabilities,
-                            value: &Json) -> WebDriverResult<()> {
+    fn validate_host(value: &Json) -> WebDriverResult<()> {
         match value.as_string() {
-            Some(x) => {
-                if x.contains("::/") {
+            Some(host) => {
+                if host.contains("://") {
                     return Err(WebDriverError::new(
                         ErrorStatus::InvalidArgument,
-                        format!("{} contains a scheme", name)));
+                        format!("{} contains a scheme", host)));
                 }
 
-                // IPv6 hosts must be enclosed with "[" and "]" in URLs
-                let host = match x.parse::<Ipv6Addr>() {
-                    Ok(ip) => format!("[{}]", ip),
-                    Err(_) => x.to_owned(),
-                };
+                // Temporarily add a scheme so the host can be parsed as URL
+                let s = String::from(format!("http://{}", host));
+                let url = try!(Url::parse(s.as_str()).or(Err(WebDriverError::new(
+                    ErrorStatus::InvalidArgument,
+                    format!("{} is not a valid host", host)))));
 
-                let mut s = String::with_capacity(scheme.len() + host.len() + 3);
-                s.push_str(scheme);
-                s.push_str("://");
-                s.push_str(host.as_str());
-
-                let url = try!(Url::parse(&*s).or(Err(WebDriverError::new(
-                    ErrorStatus::InvalidArgument,
-                    format!("{} was not a valid url", name)))));
                 if url.username() != "" ||
                     url.password() != None ||
                     url.path() != "/" ||
                     url.query() != None ||
                     url.fragment() != None {
                         return Err(WebDriverError::new(
                             ErrorStatus::InvalidArgument,
-                            format!("{} was not of the form host[:port]", name)));
-                    }
-                let mut port_key = String::with_capacity(name.len() + 4);
-                port_key.push_str(name);
-                port_key.push_str("Port");
-                if url.port() != None &&
-                    obj.contains_key(&*port_key) {
-                        return Err(WebDriverError::new(
-                                    ErrorStatus::InvalidArgument,
-                                    format!("{} supplied with a port as well as {}",
-                                            name, port_key)));
+                            format!("{} was not of the form host[:port]", host)));
                     }
             },
             None => return Err(WebDriverError::new(
                 ErrorStatus::InvalidArgument,
-                format!("{} was not a string", name)
+                format!("{} was not a string", value)
             ))
         }
         Ok(())
     }
 
-    fn validate_port(name: &str, value: &Json) -> WebDriverResult<()> {
-        match value.as_i64() {
-            Some(x) => {
-                if x < 0 || x > 2i64.pow(16) - 1 {
-                    return Err(WebDriverError::new(
-                        ErrorStatus::InvalidArgument,
-                        format!("{} is out of range", name)))
-                }
-            }
-            _ => return Err(WebDriverError::new(
-                ErrorStatus::InvalidArgument,
-                format!("{} was not an integer", name)))
-        }
-        Ok(())
-    }
-
     fn validate_timeouts(value: &Json) -> WebDriverResult<()> {
         let obj = try_opt!(value.as_object(),
                            ErrorStatus::InvalidArgument,
                            "timeouts capability was not an object");
         for (key, value) in obj.iter() {
             match &**key {
                 x @ "script" |
                 x @ "pageLoad" |
@@ -528,41 +490,31 @@ impl ToJson for LegacyNewSessionParamete
         data.insert("requiredCapabilities".to_owned(), self.required.to_json());
         Json::Object(data)
     }
 }
 
 #[cfg(test)]
 mod tests {
     use rustc_serialize::json::Json;
-    use std::collections::BTreeMap;
     use super::{WebDriverResult, SpecNewSessionParameters};
 
-    fn parse(data: &str) -> BTreeMap<String, Json> {
-        Json::from_str(&*data).unwrap().as_object().unwrap().clone()
-    }
-
-    fn validate_host(name: &str, scheme: &str, caps: &str, value: &str) -> WebDriverResult<()> {
-        SpecNewSessionParameters::validate_host_domain(name,
-                                                       scheme,
-                                                       &parse(caps),
-                                                       &Json::String(value.into()))
+    fn validate_host(value: &str) -> WebDriverResult<()> {
+        SpecNewSessionParameters::validate_host(&Json::String(value.into()))
     }
 
     #[test]
-    fn test_validate_host_domain() {
-        validate_host("ftpProxy", "ftp", "{}", "example.org").unwrap();
-        validate_host("ftpProxy", "ftp", "{}", "::1").unwrap();
-        assert!(validate_host("ftpProxy", "ftp", "{}", "ftp://example.org").is_err());
-        assert!(validate_host("ftpProxy", "ftp", "{}", "example.org/foo").is_err());
-        assert!(validate_host("ftpProxy", "ftp", "{}", "example.org#bar").is_err());
-        assert!(validate_host("ftpProxy", "ftp", "{}", "example.org?bar=baz").is_err());
-        assert!(validate_host("ftpProxy", "ftp", "{}", "foo:bar@example.org").is_err());
-        assert!(validate_host("ftpProxy", "ftp", "{}", "foo@example.org").is_err());
-        validate_host("httpProxy", "http", "{}", "example.org:8000").unwrap();
-        validate_host("httpProxy", "http", "{}", "::1:8000").unwrap();
-        validate_host("httpProxy", "http", "{\"ftpProxyPort\": \"1234\"}", "example.org:8000").unwrap();
-        assert!(validate_host("httpProxy", "http", "{\"httpProxyPort\": \"1234\"}", "example.org:8000").is_err());
-        validate_host("sslProxy", "http", "{}", "example.org:8000").unwrap();
-        validate_host("sslProxy", "http", "{\"ftpProxyPort\": \"1234\"}", "example.org:8000").unwrap();
-        assert!(validate_host("sslProxy", "http", "{\"sslProxyPort\": \"1234\"}", "example.org:8000").is_err());
+    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();
+
+        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
     }
 }