From 41d896c201256636dc13bbf5b6cfda9270466f24 Mon Sep 17 00:00:00 2001 From: Patrick Shaughnessy Date: Tue, 4 Feb 2020 17:00:56 -0500 Subject: [PATCH] file: and about: are now opaque-filtered responses --- components/net/fetch/methods.rs | 9 +--- components/net/tests/fetch.rs | 37 +++++++++++++---- .../fetch/api/basic/scheme-about.any.js.ini | 41 ------------------- .../constructors/Worker/same-origin.html.ini | 4 -- .../metadata/xhr/send-non-same-origin.htm.ini | 5 --- 5 files changed, 29 insertions(+), 67 deletions(-) delete mode 100644 tests/wpt/metadata/fetch/api/basic/scheme-about.any.js.ini delete mode 100644 tests/wpt/metadata/xhr/send-non-same-origin.htm.ini diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 101cf4674446..e8c35e4a9015 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -279,14 +279,7 @@ pub fn main_fetch( false }; - if (same_origin && !cors_flag ) || - current_url.scheme() == "data" || - current_url.scheme() == "file" || // FIXME: Fetch spec has already dropped filtering against file: - // and about: schemes, but CSS tests will break on loading Ahem - // since we load them through a file: URL. - current_url.scheme() == "about" || - request.mode == RequestMode::Navigate - { + if (same_origin && !cors_flag) || current_url.scheme() == "data" { // Substep 1. request.response_tainting = ResponseTainting::Basic; diff --git a/components/net/tests/fetch.rs b/components/net/tests/fetch.rs index d26343684f03..eddd8f67779e 100644 --- a/components/net/tests/fetch.rs +++ b/components/net/tests/fetch.rs @@ -113,12 +113,21 @@ fn test_fetch_aboutblank() { let origin = Origin::Origin(url.origin()); let mut request = Request::new(url, Some(origin), None); request.referrer = Referrer::NoReferrer; + let fetch_response = fetch(&mut request, None); + // We should see an opaque-filtered response. + assert_eq!(fetch_response.response_type, ResponseType::Opaque); assert!(!fetch_response.is_network_error()); - assert_eq!( - *fetch_response.body.lock().unwrap(), - ResponseBody::Done(vec![]) - ); + assert_eq!(fetch_response.headers.len(), 0); + let resp_body = fetch_response.body.lock().unwrap(); + assert_eq!(*resp_body, ResponseBody::Empty); + + // The underlying response behind the filter should + // have a 0-byte body. + let actual_response = fetch_response.actual_response(); + assert!(!actual_response.is_network_error()); + let resp_body = actual_response.body.lock().unwrap(); + assert_eq!(*resp_body, ResponseBody::Done(vec![])); } #[test] @@ -176,7 +185,6 @@ fn test_fetch_blob() { methods::fetch(&mut request, &mut target, &context); let fetch_response = receiver.recv().unwrap(); - assert!(!fetch_response.is_network_error()); assert_eq!(fetch_response.headers.len(), 2); @@ -198,25 +206,36 @@ fn test_fetch_blob() { } #[test] -fn test_fetch_file() { +fn test_file() { let path = Path::new("../../resources/servo.css") .canonicalize() .unwrap(); let url = ServoUrl::from_file_path(path.clone()).unwrap(); + let origin = Origin::Origin(url.origin()); let mut request = Request::new(url, Some(origin), None); let fetch_response = fetch(&mut request, None); + // We should see an opaque-filtered response. + assert_eq!(fetch_response.response_type, ResponseType::Opaque); assert!(!fetch_response.is_network_error()); - assert_eq!(fetch_response.headers.len(), 1); - let content_type: Mime = fetch_response + assert_eq!(fetch_response.headers.len(), 0); + let resp_body = fetch_response.body.lock().unwrap(); + assert_eq!(*resp_body, ResponseBody::Empty); + + // The underlying response behind the filter should + // have the file's MIME type and contents. + let actual_response = fetch_response.actual_response(); + assert!(!actual_response.is_network_error()); + assert_eq!(actual_response.headers.len(), 1); + let content_type: Mime = actual_response .headers .typed_get::() .unwrap() .into(); assert_eq!(content_type, mime::TEXT_CSS); - let resp_body = fetch_response.body.lock().unwrap(); + let resp_body = actual_response.body.lock().unwrap(); let file = fs::read(path).unwrap(); match *resp_body { diff --git a/tests/wpt/metadata/fetch/api/basic/scheme-about.any.js.ini b/tests/wpt/metadata/fetch/api/basic/scheme-about.any.js.ini deleted file mode 100644 index e070826dde4f..000000000000 --- a/tests/wpt/metadata/fetch/api/basic/scheme-about.any.js.ini +++ /dev/null @@ -1,41 +0,0 @@ -[scheme-about.any.html] - type: testharness - [Fetching about:blank (GET) is OK] - expected: FAIL - - [Fetching about:blank (PUT) is OK] - expected: FAIL - - [Fetching about:blank (POST) is OK] - expected: FAIL - - [Fetching about:blank with method GET is KO] - expected: FAIL - - [Fetching about:blank with method PUT is KO] - expected: FAIL - - [Fetching about:blank with method POST is KO] - expected: FAIL - - -[scheme-about.any.worker.html] - type: testharness - [Fetching about:blank (GET) is OK] - expected: FAIL - - [Fetching about:blank (PUT) is OK] - expected: FAIL - - [Fetching about:blank (POST) is OK] - expected: FAIL - - [Fetching about:blank with method GET is KO] - expected: FAIL - - [Fetching about:blank with method PUT is KO] - expected: FAIL - - [Fetching about:blank with method POST is KO] - expected: FAIL - diff --git a/tests/wpt/metadata/workers/constructors/Worker/same-origin.html.ini b/tests/wpt/metadata/workers/constructors/Worker/same-origin.html.ini index de990d5d1e67..40a980b618be 100644 --- a/tests/wpt/metadata/workers/constructors/Worker/same-origin.html.ini +++ b/tests/wpt/metadata/workers/constructors/Worker/same-origin.html.ini @@ -1,9 +1,5 @@ [same-origin.html] type: testharness - expected: TIMEOUT [unsupported_scheme] expected: FAIL - [about_blank] - expected: TIMEOUT - diff --git a/tests/wpt/metadata/xhr/send-non-same-origin.htm.ini b/tests/wpt/metadata/xhr/send-non-same-origin.htm.ini deleted file mode 100644 index 6e2cd9426312..000000000000 --- a/tests/wpt/metadata/xhr/send-non-same-origin.htm.ini +++ /dev/null @@ -1,5 +0,0 @@ -[send-non-same-origin.htm] - type: testharness - [XMLHttpRequest: send() - non same-origin (about:blank)] - expected: FAIL -