Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite and remove most unit tests for the legacy fetch stack. #14315

Merged
merged 14 commits into from Nov 24, 2016

Rewrite test_if_auth_creds_not_in_url_but_in_cache_it_sets_it.

  • Loading branch information
Ms2ger committed Nov 23, 2016
commit 9f23949628525dc4af2fd168dbbd90c88e67fd6f
@@ -1493,38 +1493,40 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {

#[test]
fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let handler = move |request: HyperRequest, response: HyperResponse| {
let expected = Authorization(Basic {
username: "username".to_owned(),
password: Some("test".to_owned())
});
assert_eq!(request.headers.get(), Some(&expected));
response.send(b"").unwrap();
};
let (mut server, url) = make_server(handler);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
let request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
});
let context = new_fetch_context(None);

let auth_entry = AuthCacheEntry {
user_name: "username".to_owned(),
password: "test".to_owned(),
};

http_state.auth_cache.write().unwrap().entries.insert(url.origin().clone().ascii_serialization(), auth_entry);
user_name: "username".to_owned(),
password: "test".to_owned(),
};

let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
load_data.credentials_flag = true;
context.state.auth_cache.write().unwrap().entries.insert(url.origin().clone().ascii_serialization(), auth_entry);

let mut auth_header = Headers::new();
let response = fetch(Rc::new(request), &mut None, &context);

auth_header.set(
Authorization(
Basic {
username: "username".to_owned(),
password: Some("test".to_owned())
}
)
);
let _ = server.close();

let _ = load(
&load_data, &ui_provider, &http_state,
None, &AssertMustIncludeHeadersRequestFactory {
expected_headers: auth_header,
body: <[_]>::to_vec(&[])
}, DEFAULT_USER_AGENT.into(), &CancellationListener::new(None), None);
assert!(response.status.unwrap().is_success());
}

#[test]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.