diff options
author | Nick Price <nick@spun.io> | 2016-12-20 13:16:03 -0500 |
---|---|---|
committer | Nick Price <nick@spun.io> | 2016-12-21 09:43:39 -0500 |
commit | a56a7baa9a4177cf9ac66703f2686fd8e4f6cfb5 (patch) | |
tree | 3948dca7a065f209cb4cbeb67af15175e4dcd18f /tests | |
parent | 71b68ea0dec10a8e71a9f080d7d7ff382d8f0127 (diff) | |
download | servo-a56a7baa9a4177cf9ac66703f2686fd8e4f6cfb5.tar.gz servo-a56a7baa9a4177cf9ac66703f2686fd8e4f6cfb5.zip |
Implement port-based blocking
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/net/fetch.rs | 13 | ||||
-rw-r--r-- | tests/wpt/metadata/MANIFEST.json | 6 | ||||
-rw-r--r-- | tests/wpt/web-platform-tests/fetch/api/request/request-bad-port.html | 82 |
3 files changed, 101 insertions, 0 deletions
diff --git a/tests/unit/net/fetch.rs b/tests/unit/net/fetch.rs index b2047056253..c88c8b1bf59 100644 --- a/tests/unit/net/fetch.rs +++ b/tests/unit/net/fetch.rs @@ -23,6 +23,7 @@ use hyper::status::StatusCode; use hyper::uri::RequestUri; use msg::constellation_msg::TEST_PIPELINE_ID; use net::fetch::cors_cache::CorsCache; +use net_traits::NetworkError; use net_traits::ReferrerPolicy; use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode}; use net_traits::response::{CacheState, Response, ResponseBody, ResponseType}; @@ -60,6 +61,18 @@ fn test_fetch_response_is_not_network_error() { } #[test] +fn test_fetch_on_bad_port_is_network_error() { + let url = ServoUrl::parse("http://www.example.org:6667").unwrap(); + let origin = Origin::Origin(url.origin()); + let request = Request::new(url, Some(origin), false, None); + *request.referrer.borrow_mut() = Referrer::NoReferrer; + let fetch_response = fetch(request, None); + assert!(fetch_response.is_network_error()); + let fetch_error = fetch_response.get_network_error().unwrap(); + assert!(fetch_error == &NetworkError::Internal("Request attempted on bad port".into())) +} + +#[test] fn test_fetch_response_body_matches_const_message() { static MESSAGE: &'static [u8] = b"Hello World!"; let handler = move |_: HyperRequest, response: HyperResponse| { diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 79a1f5075eb..86cd94c8b54 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -39719,6 +39719,12 @@ "url": "/cssom/shorthand-serialization.html" } ], + "fetch/api/request/request-bad-port.html": [ + { + "path": "fetch/api/request/request-bad-port.html", + "url": "/fetch/api/request/request-bad-port.html" + } + ], "html/semantics/forms/form-submission-0/submit-entity-body.html": [ { "path": "html/semantics/forms/form-submission-0/submit-entity-body.html", diff --git a/tests/wpt/web-platform-tests/fetch/api/request/request-bad-port.html b/tests/wpt/web-platform-tests/fetch/api/request/request-bad-port.html new file mode 100644 index 00000000000..e7535cf50a5 --- /dev/null +++ b/tests/wpt/web-platform-tests/fetch/api/request/request-bad-port.html @@ -0,0 +1,82 @@ +<!doctype html> +<meta charset="utf-8"> +<title></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + + // list of bad ports according to + // https://fetch.spec.whatwg.org/#port-blocking + var BLOCKED_PORTS_LIST = [ + 1, // tcpmux + 7, // echo + 9, // discard + 11, // systat + 13, // daytime + 15, // netstat + 17, // qotd + 19, // chargen + 20, // ftp-data + 21, // ftp + 22, // ssh + 23, // telnet + 25, // smtp + 37, // time + 42, // name + 43, // nicname + 53, // domain + 77, // priv-rjs + 79, // finger + 87, // ttylink + 95, // supdup + 101, // hostriame + 102, // iso-tsap + 103, // gppitnp + 104, // acr-nema + 109, // pop2 + 110, // pop3 + 111, // sunrpc + 113, // auth + 115, // sftp + 117, // uucp-path + 119, // nntp + 123, // ntp + 135, // loc-srv / epmap + 139, // netbios + 143, // imap2 + 179, // bgp + 389, // ldap + 465, // smtp+ssl + 512, // print / exec + 513, // login + 514, // shell + 515, // printer + 526, // tempo + 530, // courier + 531, // chat + 532, // netnews + 540, // uucp + 556, // remotefs + 563, // nntp+ssl + 587, // smtp + 601, // syslog-conn + 636, // ldap+ssl + 993, // imap+ssl + 995, // pop3+ssl + 2049, // nfs + 3659, // apple-sasl + 4045, // lockd + 6000, // x11 + 6665, // irc (alternate) + 6666, // irc (alternate) + 6667, // irc (default) + 6668, // irc (alternate) + 6669, // irc (alternate) + ]; + + BLOCKED_PORTS_LIST.map(function(a){ + promise_test(function(t){ + return promise_rejects(t, new TypeError(), fetch("http://example.com:" + a)) + }, 'Request on bad port ' + a + ' should throw TypeError.'); + }); +</script> |