Auto merge of #16508 - brainlessdeveloper:fetch-set-origin, r=asajeffrey

Properly set origin of fetch requests

<!-- Please describe your changes on the following line: -->

These changes aim to fix #15247

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15247 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes
- [x] These changes do not require tests because cors is already tested with different origins

These changes require changes in tests, but I need help with that (see comments below).

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16508)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-17 08:29:23 -07:00 committed by GitHub
commit 2bb4f65100
32 changed files with 173 additions and 529 deletions

View file

@ -216,7 +216,8 @@ impl FontCache {
url: url.clone(),
type_: RequestType::Font,
destination: Destination::Font,
origin: url.clone(),
// TODO: Add a proper origin - Can't import GlobalScope from gfx
// We can leave origin to be set by default
.. RequestInit::default()
};

View file

@ -1371,7 +1371,7 @@ fn cors_check(request: &Request, response: &Response) -> Result<(), ()> {
};
match request.origin {
Origin::Origin(ref o) if o.ascii_serialization() == origin => {},
Origin::Origin(ref o) if o.ascii_serialization() == origin.trim() => {},
_ => return Err(())
}

View file

@ -158,9 +158,7 @@ pub struct RequestInit {
pub use_cors_preflight: bool,
pub credentials_mode: CredentialsMode,
pub use_url_credentials: bool,
// this should actually be set by fetch, but fetch
// doesn't have info about the client right now
pub origin: ServoUrl,
pub origin: ImmutableOrigin,
// XXXManishearth these should be part of the client object
pub referrer_url: Option<ServoUrl>,
pub referrer_policy: Option<ReferrerPolicy>,
@ -188,7 +186,7 @@ impl Default for RequestInit {
use_cors_preflight: false,
credentials_mode: CredentialsMode::Omit,
use_url_credentials: false,
origin: ServoUrl::parse("about:blank").unwrap(),
origin: ImmutableOrigin::new_opaque(),
referrer_url: None,
referrer_policy: None,
pipeline_id: None,
@ -302,7 +300,7 @@ impl Request {
pub fn from_init(init: RequestInit) -> Request {
let mut req = Request::new(init.url.clone(),
Some(Origin::Origin(init.origin.origin())),
Some(Origin::Origin(init.origin)),
init.pipeline_id);
req.method = init.method;
req.headers = init.headers;

View file

@ -160,6 +160,7 @@ impl DedicatedWorkerGlobalScope {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone();
thread::Builder::new().name(name).spawn(move || {
thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER);
@ -179,10 +180,10 @@ impl DedicatedWorkerGlobalScope {
destination: Destination::Worker,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: worker_url,
pipeline_id: pipeline_id,
referrer_url: referrer_url,
referrer_policy: referrer_policy,
origin,
.. RequestInit::default()
};

View file

@ -387,7 +387,7 @@ impl EventSource {
// TODO: Step 9 set request's client settings
let mut request = RequestInit {
url: url_record,
origin: global.get_url(),
origin: global.origin().immutable().clone(),
pipeline_id: Some(global.pipeline_id()),
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
use_url_credentials: true,

View file

@ -259,7 +259,7 @@ impl HTMLImageElement {
let request = RequestInit {
url: img_url.clone(),
origin: document.url().clone(),
origin: document.origin().immutable().clone(),
type_: RequestType::Image,
pipeline_id: Some(document.global().pipeline_id()),
.. RequestInit::default()

View file

@ -550,7 +550,7 @@ impl HTMLMediaElement {
destination: Destination::Media,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: document.url(),
origin: document.origin().immutable().clone(),
pipeline_id: Some(self.global().pipeline_id()),
referrer_url: Some(document.url()),
referrer_policy: document.get_referrer_policy(),

View file

@ -253,7 +253,7 @@ fn fetch_a_classic_script(script: &HTMLScriptElement,
Some(CorsSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
_ => CredentialsMode::Include,
},
origin: doc.url(),
origin: doc.origin().immutable().clone(),
pipeline_id: Some(script.global().pipeline_id()),
referrer_url: Some(doc.url()),
referrer_policy: doc.get_referrer_policy(),

View file

@ -151,6 +151,7 @@ impl ServiceWorkerGlobalScope {
.. } = scope_things;
let serialized_worker_url = script_url.to_string();
let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone();
thread::Builder::new().name(format!("ServiceWorker for {}", serialized_worker_url)).spawn(move || {
thread_state::initialize(SCRIPT | IN_WORKER);
let roots = RootCollection::new();
@ -164,10 +165,10 @@ impl ServiceWorkerGlobalScope {
destination: Destination::ServiceWorker,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: script_url,
pipeline_id: pipeline_id,
referrer_url: referrer_url,
referrer_policy: referrer_policy,
origin,
.. RequestInit::default()
};

View file

@ -211,7 +211,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
destination: Destination::Script,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: self.worker_url.clone(),
origin: global_scope.origin().immutable().clone(),
pipeline_id: Some(self.upcast::<GlobalScope>().pipeline_id()),
referrer_url: None,
referrer_policy: None,

View file

@ -574,17 +574,14 @@ impl WorkletThread {
// TODO: Fetch a module graph, not just a single script.
// TODO: Fetch the script asynchronously?
// TODO: Caching.
// TODO: Avoid re-parsing the origin as a URL.
let resource_fetcher = self.global_init.resource_threads.sender();
let origin_url = ServoUrl::parse(&*origin.unicode_serialization())
.unwrap_or_else(|_| ServoUrl::parse("about:blank").unwrap());
let request = RequestInit {
url: script_url,
type_: RequestType::Script,
destination: Destination::Script,
mode: RequestMode::CorsMode,
origin: origin_url,
credentials_mode: credentials.into(),
origin,
.. RequestInit::default()
};
let script = load_whole_resource(request, &resource_fetcher).ok()

View file

@ -594,7 +594,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
use_cors_preflight: has_handlers,
credentials_mode: credentials_mode,
use_url_credentials: use_url_credentials,
origin: self.global().get_url(),
origin: self.global().origin().immutable().clone(),
referrer_url: self.referrer_url.clone(),
referrer_policy: self.referrer_policy.clone(),
pipeline_id: Some(self.global().pipeline_id()),

View file

@ -56,10 +56,7 @@ fn request_init_from_request(request: NetTraitsRequest) -> NetTraitsRequestInit
use_cors_preflight: request.use_cors_preflight,
credentials_mode: request.credentials_mode,
use_url_credentials: request.use_url_credentials,
// TODO: NetTraitsRequestInit and NetTraitsRequest have different "origin"
// ... NetTraitsRequestInit.origin: Url
// ... NetTraitsRequest.origin: RefCell<Origin>
origin: request.url(),
origin: GlobalScope::current().expect("No current global object").origin().immutable().clone(),
referrer_url: from_referrer_to_referrer_url(&request),
referrer_policy: request.referrer_policy,
pipeline_id: request.pipeline_id,

View file

@ -70,7 +70,7 @@ pub fn fetch_image_for_layout(url: ServoUrl,
let request = FetchRequestInit {
url: url,
origin: document.url().clone(),
origin: document.origin().immutable().clone(),
type_: RequestType::Image,
pipeline_id: Some(document.global().pipeline_id()),
.. FetchRequestInit::default()

View file

@ -1928,6 +1928,12 @@ impl ScriptThread {
ROUTER.route_ipc_receiver_to_mpsc_sender(ipc_timer_event_port,
self.timer_event_chan.clone());
let origin = if final_url.as_str() == "about:blank" {
incomplete.origin.clone()
} else {
MutableOrigin::new(final_url.origin())
};
// Create the window and document objects.
let window = Window::new(self.js_runtime.clone(),
MainThreadScriptChan(sender.clone()),
@ -1951,7 +1957,7 @@ impl ScriptThread {
incomplete.pipeline_id,
incomplete.parent_info,
incomplete.window_size,
incomplete.origin.clone(),
origin,
self.webvr_thread.clone());
// Initialize the browsing context for the window.
@ -2283,13 +2289,13 @@ impl ScriptThread {
destination: Destination::Document,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: load_data.url.clone(),
pipeline_id: Some(id),
referrer_url: load_data.referrer_url,
referrer_policy: load_data.referrer_policy,
headers: load_data.headers,
body: load_data.data,
redirect_mode: RedirectMode::Manual,
origin: incomplete.origin.immutable().clone(),
.. RequestInit::default()
};

View file

@ -261,7 +261,7 @@ impl<'a> StylesheetLoader<'a> {
Some(CorsSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
_ => CredentialsMode::Include,
},
origin: document.url(),
origin: document.origin().immutable().clone(),
pipeline_id: Some(self.elem.global().pipeline_id()),
referrer_url: Some(document.url()),
referrer_policy: referrer_policy,

View file

@ -30,7 +30,7 @@ use net_traits::{CookieSource, NetworkError};
use net_traits::request::{Request, RequestInit, RequestMode, CredentialsMode, Destination};
use net_traits::response::ResponseBody;
use new_fetch_context;
use servo_url::ServoUrl;
use servo_url::{ServoUrl, ImmutableOrigin};
use std::collections::HashMap;
use std::io::{Read, Write};
use std::str::FromStr;
@ -38,6 +38,10 @@ use std::sync::{Arc, Mutex, RwLock, mpsc};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::Receiver;
fn mock_origin() -> ImmutableOrigin {
ServoUrl::parse("http://servo.org").unwrap().origin()
}
fn read_response(reader: &mut Read) -> String {
let mut buf = vec![0; 1024];
match reader.read(&mut buf) {
@ -138,12 +142,12 @@ fn test_check_default_headers_loaded_in_every_request() {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
origin: url.clone().origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
// Testing for method.POST
let mut post_headers = headers.clone();
@ -157,12 +161,12 @@ fn test_check_default_headers_loaded_in_every_request() {
url: url.clone(),
method: Method::Post,
destination: Destination::Document,
origin: url.clone(),
origin: url.clone().origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let _ = server.close();
}
@ -179,12 +183,12 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length
method: Method::Post,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let _ = server.close();
}
@ -205,13 +209,13 @@ fn test_request_and_response_data_with_network_messages() {
headers: request_headers,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let (devtools_chan, devtools_port) = mpsc::channel();
let response = fetch(&mut request, Some(devtools_chan));
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let _ = server.close();
@ -292,13 +296,13 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: None,
.. RequestInit::default()
});
let (devtools_chan, devtools_port) = mpsc::channel();
let response = fetch(&mut request, Some(devtools_chan));
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let _ = server.close();
@ -327,7 +331,6 @@ fn test_redirected_request_to_devtools() {
url: pre_url.clone(),
method: Method::Post,
destination: Destination::Document,
origin: pre_url.clone(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -375,7 +378,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
url: pre_url.clone(),
method: Method::Post,
destination: Destination::Document,
origin: pre_url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -403,7 +406,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -411,8 +414,9 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert_eq!(*response.body.lock().unwrap(),
let internal_response = response.internal_response.unwrap();
assert!(internal_response.status.unwrap().is_success());
assert_eq!(*internal_response.body.lock().unwrap(),
ResponseBody::Done(b"Yay!".to_vec()));
}
@ -432,7 +436,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -440,8 +444,9 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert_eq!(*response.body.lock().unwrap(),
let internal_response = response.internal_response.unwrap();
assert!(internal_response.status.unwrap().is_success());
assert_eq!(*internal_response.body.lock().unwrap(),
ResponseBody::Done(b"Yay!".to_vec()));
}
@ -470,7 +475,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
body: Some(b"Body on POST!".to_vec()),
method: Method::Post,
destination: Destination::Document,
origin: pre_url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -495,7 +500,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -504,7 +509,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
assert_eq!(context.state.hsts_list.read().unwrap().is_host_secure(url.host_str().unwrap()), false);
}
@ -525,7 +530,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -534,7 +539,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), Some("mozillaIs=theBest"));
}
@ -565,7 +570,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -574,7 +579,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -603,7 +608,7 @@ fn test_load_sends_cookie_if_nonhttp() {
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -612,7 +617,7 @@ fn test_load_sends_cookie_if_nonhttp() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -633,7 +638,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -642,7 +647,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), Some("mozillaIs=theBest"));
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
@ -667,7 +672,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -676,7 +681,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);
}
@ -696,7 +701,7 @@ fn test_load_sets_content_length_to_length_of_request_body() {
method: Method::Post,
body: Some(content.to_vec()),
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -704,7 +709,7 @@ fn test_load_sets_content_length_to_length_of_request_body() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -724,7 +729,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
method: Method::Get,
headers: accept_headers,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -732,7 +737,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -752,7 +757,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -760,7 +765,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -780,7 +785,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
method: Method::Get,
headers: accept_encoding_headers,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -788,7 +793,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -807,7 +812,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -815,7 +820,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -843,7 +848,7 @@ fn test_load_errors_when_there_a_redirect_loop() {
url: url_a.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url_a.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -886,7 +891,7 @@ fn test_load_succeeds_with_a_redirect_loop() {
url: url_a.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url_a.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -922,7 +927,7 @@ fn test_load_follows_a_redirect() {
url: pre_url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: pre_url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
@ -931,9 +936,9 @@ fn test_load_follows_a_redirect() {
let _ = pre_server.close();
let _ = post_server.close();
let response = response.to_actual();
assert!(response.status.unwrap().is_success());
assert_eq!(*response.body.lock().unwrap(),
let internal_response = response.internal_response.unwrap();
assert!(internal_response.status.unwrap().is_success());
assert_eq!(*internal_response.body.lock().unwrap(),
ResponseBody::Done(b"Yay!".to_vec()));
}
@ -999,7 +1004,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
url: url_x.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url_x.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -1008,9 +1013,9 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
let _ = server.close();
let response = response.to_actual();
assert!(response.status.unwrap().is_success());
assert_eq!(*response.body.lock().unwrap(),
let internal_response = response.internal_response.unwrap();
assert!(internal_response.status.unwrap().is_success());
assert_eq!(*internal_response.body.lock().unwrap(),
ResponseBody::Done(b"Yay!".to_vec()));
}
@ -1043,7 +1048,7 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -1052,9 +1057,9 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
let _ = server.close();
let response = response.to_actual();
assert!(response.status.unwrap().is_success());
assert_eq!(*response.body.lock().unwrap(),
let internal_response = response.internal_response.unwrap();
assert!(internal_response.status.unwrap().is_success());
assert_eq!(*internal_response.body.lock().unwrap(),
ResponseBody::Done(b"Yay!".to_vec()));
}
@ -1075,7 +1080,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -1093,7 +1098,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
let _ = server.close();
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
}
#[test]
@ -1109,7 +1114,7 @@ fn test_auth_ui_needs_www_auth() {
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
origin: mock_origin(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
@ -1119,7 +1124,7 @@ fn test_auth_ui_needs_www_auth() {
let _ = server.close();
assert_eq!(response.status.unwrap(), StatusCode::Unauthorized);
assert_eq!(response.internal_response.unwrap().status.unwrap(), StatusCode::Unauthorized);
}
#[test]
@ -1142,11 +1147,11 @@ fn test_origin_set() {
url: url.clone(),
method: Method::Post,
body: None,
origin: url.clone(),
origin: url.clone().origin(),
.. RequestInit::default()
});
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let origin_url = ServoUrl::parse("http://example.com").unwrap();
origin = Origin::new(origin_url.scheme(), origin_url.host_str().unwrap(), origin_url.port());
@ -1156,26 +1161,26 @@ fn test_origin_set() {
method: Method::Get,
mode: RequestMode::CorsMode,
body: None,
origin: origin_url.clone(),
origin: origin_url.clone().origin(),
.. RequestInit::default()
});
*origin_header_clone.lock().unwrap() = Some(origin.clone());
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
// Test Origin header is not set on method Head
let mut request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Head,
body: None,
origin: url.clone(),
origin: url.clone().origin(),
.. RequestInit::default()
});
*origin_header_clone.lock().unwrap() = None;
let response = fetch(&mut request, None);
assert!(response.status.unwrap().is_success());
assert!(response.internal_response.unwrap().status.unwrap().is_success());
let _ = server.close();
}

View file

@ -12,6 +12,3 @@
[Allow origin: [tab\]undefined//undefined]
expected: FAIL
[Allow origin: _http://web-platform.test:8000___[tab\]_]
expected: FAIL

View file

@ -1,17 +0,0 @@
[origin.htm]
type: testharness
[Allow origin: undefined//undefined]
expected: FAIL
[Allow origin: _undefined//undefined]
expected: FAIL
[Allow origin: _undefined//undefined___[tab\]_]
expected: FAIL
[Allow origin: [tab\]undefined//undefined]
expected: FAIL
[Allow origin: _http://web-platform.test:8000___[tab\]_]
expected: FAIL

View file

@ -1,17 +0,0 @@
[mode-same-origin.any.worker.html]
type: testharness
[Fetch https://web-platform.test:8443/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://www1.web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[mode-same-origin.any.html]
type: testharness
[Fetch https://web-platform.test:8443/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://www1.web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL

View file

@ -3,93 +3,32 @@
[Same domain different port [no-cors mode\]]
expected: FAIL
[Same domain different port [server forbid CORS\]]
expected: FAIL
[Same domain different port [cors mode\]]
expected: FAIL
[Same domain different protocol different port [no-cors mode\]]
expected: FAIL
[Same domain different protocol different port [server forbid CORS\]]
expected: FAIL
[Same domain different protocol different port [cors mode\]]
expected: FAIL
[Cross domain basic usage [no-cors mode\]]
expected: FAIL
[Cross domain basic usage [server forbid CORS\]]
expected: FAIL
[Cross domain basic usage [cors mode\]]
expected: FAIL
[Cross domain different port [no-cors mode\]]
expected: FAIL
[Cross domain different port [server forbid CORS\]]
expected: FAIL
[Cross domain different port [cors mode\]]
expected: FAIL
[Cross domain different protocol [no-cors mode\]]
expected: FAIL
[Cross domain different protocol [server forbid CORS\]]
expected: FAIL
[Cross domain different protocol [cors mode\]]
expected: FAIL
[cors-basic.any.html]
type: testharness
[Same domain different port [no-cors mode\]]
expected: FAIL
[Same domain different port [server forbid CORS\]]
expected: FAIL
[Same domain different port [cors mode\]]
expected: FAIL
[Same domain different protocol different port [no-cors mode\]]
expected: FAIL
[Same domain different protocol different port [server forbid CORS\]]
expected: FAIL
[Same domain different protocol different port [cors mode\]]
expected: FAIL
[Cross domain basic usage [no-cors mode\]]
expected: FAIL
[Cross domain basic usage [server forbid CORS\]]
expected: FAIL
[Cross domain basic usage [cors mode\]]
expected: FAIL
[Cross domain different port [no-cors mode\]]
expected: FAIL
[Cross domain different port [server forbid CORS\]]
expected: FAIL
[Cross domain different port [cors mode\]]
expected: FAIL
[Cross domain different protocol [no-cors mode\]]
expected: FAIL
[Cross domain different protocol [server forbid CORS\]]
expected: FAIL
[Cross domain different protocol [cors mode\]]
expected: FAIL

View file

@ -6,12 +6,11 @@
[Include mode: remote cookies are not sent with local request]
expected: FAIL
[Same-origin mode: cookies are discarded in cors request]
expected: FAIL
[cors-cookies.any.worker.html]
type: testharness
[Include mode: 1 cookie]
expected: FAIL
[Include mode: local cookies are not sent with remote request]
expected: FAIL
@ -21,3 +20,17 @@
[Same-origin mode: cookies are discarded in cors request]
expected: FAIL
[Include mode: 1 cookie]
expected: FAIL
[Include mode: remote cookies are not sent with local request]
expected: FAIL
[Same-origin mode: cookies are discarded in cors request]
expected: FAIL
[Include mode: remote cookies are not sent with other remote request]
expected: FAIL
[Include mode: local cookies are not sent with remote request]
expected: FAIL

View file

@ -3,6 +3,3 @@
[Basic Access-Control-Expose-Headers: * support]
expected: FAIL
[Cannot use * for credentialed fetches]
expected: FAIL

View file

@ -1,68 +1,8 @@
[cors-filtering-worker.html]
type: testharness
[CORS filter on Cache-Control header]
expected: FAIL
[CORS filter on Content-Language header]
expected: FAIL
[CORS filter on Content-Type header]
expected: FAIL
[CORS filter on Expires header]
expected: FAIL
[CORS filter on Last-Modified header]
expected: FAIL
[CORS filter on Pragma header]
expected: FAIL
[CORS filter on Age header]
expected: FAIL
[CORS filter on Server header]
expected: FAIL
[CORS filter on Warning header]
expected: FAIL
[CORS filter on Content-Length header]
expected: FAIL
[CORS filter on Set-Cookie header]
expected: FAIL
[CORS filter on Set-Cookie2 header]
expected: FAIL
[CORS filter on Age header, header is exposed]
expected: FAIL
[CORS filter on Server header, header is exposed]
expected: FAIL
[CORS filter on Warning header, header is exposed]
expected: FAIL
[CORS filter on Content-Length header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie header, header is forbidden]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is forbidden]
expected: FAIL
[CORS filter on Set-Cookie header, header is forbidden(credentials = include)]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is forbidden(credentials = include)]
expected: FAIL

View file

@ -1,68 +1,8 @@
[cors-filtering.html]
type: testharness
[CORS filter on Cache-Control header]
expected: FAIL
[CORS filter on Content-Language header]
expected: FAIL
[CORS filter on Content-Type header]
expected: FAIL
[CORS filter on Expires header]
expected: FAIL
[CORS filter on Last-Modified header]
expected: FAIL
[CORS filter on Pragma header]
expected: FAIL
[CORS filter on Age header]
expected: FAIL
[CORS filter on Server header]
expected: FAIL
[CORS filter on Warning header]
expected: FAIL
[CORS filter on Content-Length header]
expected: FAIL
[CORS filter on Set-Cookie header]
expected: FAIL
[CORS filter on Set-Cookie2 header]
expected: FAIL
[CORS filter on Age header, header is exposed]
expected: FAIL
[CORS filter on Server header, header is exposed]
expected: FAIL
[CORS filter on Warning header, header is exposed]
expected: FAIL
[CORS filter on Content-Length header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is exposed]
expected: FAIL
[CORS filter on Set-Cookie header, header is forbidden]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is forbidden]
expected: FAIL
[CORS filter on Set-Cookie header, header is forbidden(credentials = include)]
expected: FAIL
[CORS filter on Set-Cookie2 header, header is forbidden(credentials = include)]
expected: FAIL

View file

@ -1,5 +1,32 @@
[cors-multiple-origins-worker.html]
type: testharness
[3 origins allowed, no match]
[3 origins allowed, match the 3rd (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd ("*")]
expected: FAIL
[3 origins allowed, match twice (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match twice ("*")]
expected: FAIL
[3 origins allowed, match twice ("*" and http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd ("*")]
expected: FAIL
[3 origins allowed, match twice (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match twice ("*")]
expected: FAIL
[3 origins allowed, match twice ("*" and http://web-platform.test:8000)]
expected: FAIL

View file

@ -1,5 +1,32 @@
[cors-multiple-origins.html]
type: testharness
[3 origins allowed, no match]
[3 origins allowed, match the 3rd (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd ("*")]
expected: FAIL
[3 origins allowed, match twice (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match twice ("*")]
expected: FAIL
[3 origins allowed, match twice ("*" and http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match the 3rd ("*")]
expected: FAIL
[3 origins allowed, match twice (http://web-platform.test:8000)]
expected: FAIL
[3 origins allowed, match twice ("*")]
expected: FAIL
[3 origins allowed, match twice ("*" and http://web-platform.test:8000)]
expected: FAIL

View file

@ -1,59 +0,0 @@
[cors-origin.any.html]
type: testharness
[Cross domain different subdomain [origin KO\]]
expected: FAIL
[Same domain different port [origin KO\]]
expected: FAIL
[Cross domain different port [origin KO\]]
expected: FAIL
[Cross domain different protocol [origin KO\]]
expected: FAIL
[Same domain different protocol different port [origin KO\]]
expected: FAIL
[Cross domain [POST\] [origin KO\]]
expected: FAIL
[Cross domain [HEAD\] [origin KO\]]
expected: FAIL
[CORS preflight [PUT\] [origin KO\]]
expected: FAIL
[Allowed origin: "" [origin KO\]]
expected: FAIL
[cors-origin.any.worker.html]
type: testharness
[Cross domain different subdomain [origin KO\]]
expected: FAIL
[Same domain different port [origin KO\]]
expected: FAIL
[Cross domain different port [origin KO\]]
expected: FAIL
[Cross domain different protocol [origin KO\]]
expected: FAIL
[Same domain different protocol different port [origin KO\]]
expected: FAIL
[Cross domain [POST\] [origin KO\]]
expected: FAIL
[Cross domain [HEAD\] [origin KO\]]
expected: FAIL
[CORS preflight [PUT\] [origin KO\]]
expected: FAIL
[Allowed origin: "" [origin KO\]]
expected: FAIL

View file

@ -1,20 +1,11 @@
[cors-preflight-star.any.html]
type: testharness
[CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test)]
expected: FAIL
[CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test)]
expected: FAIL
[CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *)]
expected: FAIL
[CORS that fails with credentials: true; method: PUT (allowed: *); header: undefined (allowed: )]
expected: FAIL
[CORS that fails with credentials: true; method: PUT (allowed: put); header: undefined (allowed: *)]
expected: FAIL
[CORS that fails with credentials: true; method: GET (allowed: get); header: X-Test,1 (allowed: *)]
expected: FAIL
@ -24,24 +15,12 @@
[cors-preflight-star.any.worker.html]
type: testharness
[CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test)]
expected: FAIL
[CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test)]
expected: FAIL
[CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *)]
expected: FAIL
[CORS that fails with credentials: true; method: PUT (allowed: *); header: undefined (allowed: )]
expected: FAIL
[CORS that fails with credentials: true; method: PUT (allowed: put); header: undefined (allowed: *)]
expected: FAIL
[CORS that fails with credentials: true; method: GET (allowed: get); header: X-Test,1 (allowed: *)]
expected: FAIL
[CORS that fails with credentials: true; method: GET (allowed: *); header: X-Test,1 (allowed: *)]
[CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test)]
expected: FAIL

View file

@ -3,15 +3,9 @@
[CORS [DELETE\], server allows]
expected: FAIL
[CORS [DELETE\], server refuses]
expected: FAIL
[CORS [PUT\], server allows]
expected: FAIL
[CORS [PUT\], server refuses]
expected: FAIL
[CORS [PATCH\], server allows]
expected: FAIL
@ -33,9 +27,6 @@
[CORS [PUT\] [several headers\], server allows]
expected: FAIL
[CORS [PUT\] [several headers\], server refuses]
expected: FAIL
[CORS [PUT\] [only safe headers\], server allows]
expected: FAIL
@ -45,15 +36,9 @@
[CORS [DELETE\], server allows]
expected: FAIL
[CORS [DELETE\], server refuses]
expected: FAIL
[CORS [PUT\], server allows]
expected: FAIL
[CORS [PUT\], server refuses]
expected: FAIL
[CORS [PATCH\], server allows]
expected: FAIL
@ -75,9 +60,6 @@
[CORS [PUT\] [several headers\], server allows]
expected: FAIL
[CORS [PUT\] [several headers\], server refuses]
expected: FAIL
[CORS [PUT\] [only safe headers\], server allows]
expected: FAIL

View file

@ -1,95 +0,0 @@
[cors-redirect-credentials.any.worker.html]
type: testharness
[Redirect 301 from remote to same remote with user and password]
expected: FAIL
[Redirect 301 from remote to same remote with user]
expected: FAIL
[Redirect 301 from remote to same remote with password]
expected: FAIL
[Redirect 302 from remote to same remote with user and password]
expected: FAIL
[Redirect 302 from remote to same remote with user]
expected: FAIL
[Redirect 302 from remote to same remote with password]
expected: FAIL
[Redirect 303 from remote to same remote with user and password]
expected: FAIL
[Redirect 303 from remote to same remote with user]
expected: FAIL
[Redirect 303 from remote to same remote with password]
expected: FAIL
[Redirect 307 from remote to same remote with user and password]
expected: FAIL
[Redirect 307 from remote to same remote with user]
expected: FAIL
[Redirect 307 from remote to same remote with password]
expected: FAIL
[Redirect 308 from remote to same remote with user and password]
expected: FAIL
[Redirect 308 from remote to same remote with user]
expected: FAIL
[Redirect 308 from remote to same remote with password]
expected: FAIL
[cors-redirect-credentials.any.html]
type: testharness
[Redirect 301 from remote to same remote with user and password]
expected: FAIL
[Redirect 301 from remote to same remote with user]
expected: FAIL
[Redirect 301 from remote to same remote with password]
expected: FAIL
[Redirect 302 from remote to same remote with user and password]
expected: FAIL
[Redirect 302 from remote to same remote with user]
expected: FAIL
[Redirect 302 from remote to same remote with password]
expected: FAIL
[Redirect 303 from remote to same remote with user and password]
expected: FAIL
[Redirect 303 from remote to same remote with user]
expected: FAIL
[Redirect 303 from remote to same remote with password]
expected: FAIL
[Redirect 307 from remote to same remote with user and password]
expected: FAIL
[Redirect 307 from remote to same remote with user]
expected: FAIL
[Redirect 307 from remote to same remote with password]
expected: FAIL
[Redirect 308 from remote to same remote with user and password]
expected: FAIL
[Redirect 308 from remote to same remote with user]
expected: FAIL
[Redirect 308 from remote to same remote with password]
expected: FAIL

View file

@ -63,45 +63,30 @@
[cors-redirect.any.html]
type: testharness
[Redirect 301: cors to same cors]
expected: FAIL
[Redirect 301: cors to another cors]
expected: FAIL
[Redirect 301: cors to same origin]
expected: FAIL
[Redirect 302: cors to same cors]
expected: FAIL
[Redirect 302: cors to another cors]
expected: FAIL
[Redirect 302: cors to same origin]
expected: FAIL
[Redirect 303: cors to same cors]
expected: FAIL
[Redirect 303: cors to another cors]
expected: FAIL
[Redirect 303: cors to same origin]
expected: FAIL
[Redirect 307: cors to same cors]
expected: FAIL
[Redirect 307: cors to another cors]
expected: FAIL
[Redirect 307: cors to same origin]
expected: FAIL
[Redirect 308: cors to same cors]
expected: FAIL
[Redirect 308: cors to another cors]
expected: FAIL