mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Rewrite test_if_auth_creds_not_in_url_but_in_cache_it_sets_it.
This commit is contained in:
parent
27d90fb6a8
commit
9f23949628
1 changed files with 27 additions and 25 deletions
|
@ -1493,38 +1493,40 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
|
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 request = Request::from_init(RequestInit {
|
||||||
let ui_provider = TestProvider::new();
|
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 {
|
let auth_entry = AuthCacheEntry {
|
||||||
user_name: "username".to_owned(),
|
user_name: "username".to_owned(),
|
||||||
password: "test".to_owned(),
|
password: "test".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
http_state.auth_cache.write().unwrap().entries.insert(url.origin().clone().ascii_serialization(), auth_entry);
|
context.state.auth_cache.write().unwrap().entries.insert(url.origin().clone().ascii_serialization(), auth_entry);
|
||||||
|
|
||||||
let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
|
let response = fetch(Rc::new(request), &mut None, &context);
|
||||||
load_data.credentials_flag = true;
|
|
||||||
|
|
||||||
let mut auth_header = Headers::new();
|
let _ = server.close();
|
||||||
|
|
||||||
auth_header.set(
|
assert!(response.status.unwrap().is_success());
|
||||||
Authorization(
|
|
||||||
Basic {
|
|
||||||
username: "username".to_owned(),
|
|
||||||
password: Some("test".to_owned())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue