file: and about: are now opaque-filtered responses

This commit is contained in:
Patrick Shaughnessy 2020-02-04 17:00:56 -05:00
parent f3dbe7d388
commit 41d896c201
5 changed files with 29 additions and 67 deletions

View file

@ -279,14 +279,7 @@ pub fn main_fetch(
false false
}; };
if (same_origin && !cors_flag ) || if (same_origin && !cors_flag) || current_url.scheme() == "data" {
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
{
// Substep 1. // Substep 1.
request.response_tainting = ResponseTainting::Basic; request.response_tainting = ResponseTainting::Basic;

View file

@ -113,12 +113,21 @@ fn test_fetch_aboutblank() {
let origin = Origin::Origin(url.origin()); let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), None); let mut request = Request::new(url, Some(origin), None);
request.referrer = Referrer::NoReferrer; request.referrer = Referrer::NoReferrer;
let fetch_response = fetch(&mut request, 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!(!fetch_response.is_network_error());
assert_eq!( assert_eq!(fetch_response.headers.len(), 0);
*fetch_response.body.lock().unwrap(), let resp_body = fetch_response.body.lock().unwrap();
ResponseBody::Done(vec![]) 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] #[test]
@ -176,7 +185,6 @@ fn test_fetch_blob() {
methods::fetch(&mut request, &mut target, &context); methods::fetch(&mut request, &mut target, &context);
let fetch_response = receiver.recv().unwrap(); let fetch_response = receiver.recv().unwrap();
assert!(!fetch_response.is_network_error()); assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 2); assert_eq!(fetch_response.headers.len(), 2);
@ -198,25 +206,36 @@ fn test_fetch_blob() {
} }
#[test] #[test]
fn test_fetch_file() { fn test_file() {
let path = Path::new("../../resources/servo.css") let path = Path::new("../../resources/servo.css")
.canonicalize() .canonicalize()
.unwrap(); .unwrap();
let url = ServoUrl::from_file_path(path.clone()).unwrap(); let url = ServoUrl::from_file_path(path.clone()).unwrap();
let origin = Origin::Origin(url.origin()); let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), None); let mut request = Request::new(url, Some(origin), None);
let fetch_response = fetch(&mut request, 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!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 1); assert_eq!(fetch_response.headers.len(), 0);
let content_type: Mime = fetch_response 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 .headers
.typed_get::<ContentType>() .typed_get::<ContentType>()
.unwrap() .unwrap()
.into(); .into();
assert_eq!(content_type, mime::TEXT_CSS); 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(); let file = fs::read(path).unwrap();
match *resp_body { match *resp_body {

View file

@ -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

View file

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

View file

@ -1,5 +0,0 @@
[send-non-same-origin.htm]
type: testharness
[XMLHttpRequest: send() - non same-origin (about:blank)]
expected: FAIL