Skip to content

Commit

Permalink
file: and about: are now opaque-filtered responses
Browse files Browse the repository at this point in the history
  • Loading branch information
pshaughn committed Feb 11, 2020
1 parent f3dbe7d commit 41d896c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 67 deletions.
9 changes: 1 addition & 8 deletions components/net/fetch/methods.rs
Expand Up @@ -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;

Expand Down
37 changes: 28 additions & 9 deletions components/net/tests/fetch.rs
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand All @@ -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::<ContentType>()
.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 {
Expand Down
41 changes: 0 additions & 41 deletions tests/wpt/metadata/fetch/api/basic/scheme-about.any.js.ini

This file was deleted.

@@ -1,9 +1,5 @@
[same-origin.html]
type: testharness
expected: TIMEOUT
[unsupported_scheme]
expected: FAIL

[about_blank]
expected: TIMEOUT

5 changes: 0 additions & 5 deletions tests/wpt/metadata/xhr/send-non-same-origin.htm.ini

This file was deleted.

0 comments on commit 41d896c

Please sign in to comment.