aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/tests
diff options
context:
space:
mode:
Diffstat (limited to 'components/net/tests')
-rw-r--r--components/net/tests/fetch.rs116
-rw-r--r--components/net/tests/hsts.rs56
-rw-r--r--components/net/tests/http_cache.rs2
-rw-r--r--components/net/tests/http_loader.rs288
-rw-r--r--components/net/tests/main.rs22
-rw-r--r--components/net/tests/subresource_integrity.rs4
6 files changed, 280 insertions, 208 deletions
diff --git a/components/net/tests/fetch.rs b/components/net/tests/fetch.rs
index 27fff40e897..55d2241fb02 100644
--- a/components/net/tests/fetch.rs
+++ b/components/net/tests/fetch.rs
@@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex, Weak};
use std::time::{Duration, SystemTime};
use base::id::TEST_PIPELINE_ID;
-use crossbeam_channel::{unbounded, Sender};
+use crossbeam_channel::{Sender, unbounded};
use devtools_traits::{HttpRequest as DevtoolsHttpRequest, HttpResponse as DevtoolsHttpResponse};
use headers::{
AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowMethods,
@@ -48,9 +48,9 @@ use uuid::Uuid;
use crate::http_loader::{expect_devtools_http_request, expect_devtools_http_response};
use crate::{
- create_embedder_proxy, create_embedder_proxy_and_receiver, create_http_state, fetch,
- fetch_with_context, fetch_with_cors_cache, make_body, make_server, make_ssl_server,
- new_fetch_context, DEFAULT_USER_AGENT,
+ DEFAULT_USER_AGENT, create_embedder_proxy, create_embedder_proxy_and_receiver,
+ create_http_state, fetch, fetch_with_context, fetch_with_cors_cache, make_body, make_server,
+ make_ssl_server, new_fetch_context,
};
// TODO write a struct that impls Handler for storing test values
@@ -298,19 +298,25 @@ fn test_cors_preflight_fetch() {
if request.method() == Method::OPTIONS &&
state.clone().fetch_add(1, Ordering::SeqCst) == 0
{
- assert!(request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD));
- assert!(!request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS));
- assert!(!request
- .headers()
- .get(header::REFERER)
- .unwrap()
- .to_str()
- .unwrap()
- .contains("a.html"));
+ assert!(
+ request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD)
+ );
+ assert!(
+ !request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS)
+ );
+ assert!(
+ !request
+ .headers()
+ .get(header::REFERER)
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .contains("a.html")
+ );
response
.headers_mut()
.typed_insert(AccessControlAllowOrigin::ANY);
@@ -356,12 +362,16 @@ fn test_cors_preflight_cache_fetch() {
if request.method() == Method::OPTIONS &&
state.clone().fetch_add(1, Ordering::SeqCst) == 0
{
- assert!(request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD));
- assert!(!request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS));
+ assert!(
+ request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD)
+ );
+ assert!(
+ !request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS)
+ );
response
.headers_mut()
.typed_insert(AccessControlAllowOrigin::ANY);
@@ -424,12 +434,16 @@ fn test_cors_preflight_fetch_network_error() {
if request.method() == Method::OPTIONS &&
state.clone().fetch_add(1, Ordering::SeqCst) == 0
{
- assert!(request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD));
- assert!(!request
- .headers()
- .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS));
+ assert!(
+ request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_METHOD)
+ );
+ assert!(
+ !request
+ .headers()
+ .contains_key(header::ACCESS_CONTROL_REQUEST_HEADERS)
+ );
response
.headers_mut()
.typed_insert(AccessControlAllowOrigin::ANY);
@@ -488,9 +502,11 @@ fn test_fetch_response_is_basic_filtered() {
let headers = fetch_response.headers;
assert!(!headers.contains_key(header::SET_COOKIE));
- assert!(headers
- .get(HeaderName::from_static("set-cookie2"))
- .is_none());
+ assert!(
+ headers
+ .get(HeaderName::from_static("set-cookie2"))
+ .is_none()
+ );
}
#[test]
@@ -560,9 +576,11 @@ fn test_fetch_response_is_cors_filtered() {
assert!(!headers.contains_key(header::ACCESS_CONTROL_ALLOW_ORIGIN));
assert!(!headers.contains_key(header::SET_COOKIE));
- assert!(headers
- .get(HeaderName::from_static("set-cookie2"))
- .is_none());
+ assert!(
+ headers
+ .get(HeaderName::from_static("set-cookie2"))
+ .is_none()
+ );
}
#[test]
@@ -794,18 +812,22 @@ fn test_load_adds_host_to_hsts_list_when_url_is_https() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
- assert!(context
- .state
- .hsts_list
- .read()
- .unwrap()
- .is_host_secure(url.host_str().unwrap()));
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
+ assert!(
+ context
+ .state
+ .hsts_list
+ .read()
+ .unwrap()
+ .is_host_secure(url.host_str().unwrap())
+ );
}
#[test]
diff --git a/components/net/tests/hsts.rs b/components/net/tests/hsts.rs
index 771e057e715..863cbc56fe1 100644
--- a/components/net/tests/hsts.rs
+++ b/components/net/tests/hsts.rs
@@ -106,12 +106,14 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() {
let mut entries_map = HashMap::new();
entries_map.insert(
"mozilla.org".to_owned(),
- vec![HstsEntry::new(
- "mozilla.org".to_owned(),
- IncludeSubdomains::NotIncluded,
- Some(StdDuration::from_secs(500000)),
- )
- .unwrap()],
+ vec![
+ HstsEntry::new(
+ "mozilla.org".to_owned(),
+ IncludeSubdomains::NotIncluded,
+ Some(StdDuration::from_secs(500000)),
+ )
+ .unwrap(),
+ ],
);
let mut list = HstsList {
entries_map: entries_map,
@@ -182,12 +184,14 @@ fn test_push_entry_to_hsts_list_should_not_create_duplicate_entry() {
let mut entries_map = HashMap::new();
entries_map.insert(
"mozilla.org".to_owned(),
- vec![HstsEntry::new(
- "mozilla.org".to_owned(),
- IncludeSubdomains::NotIncluded,
- None,
- )
- .unwrap()],
+ vec![
+ HstsEntry::new(
+ "mozilla.org".to_owned(),
+ IncludeSubdomains::NotIncluded,
+ None,
+ )
+ .unwrap(),
+ ],
);
let mut list = HstsList {
entries_map: entries_map,
@@ -286,12 +290,14 @@ fn test_hsts_list_with_exact_domain_entry_is_is_host_secure() {
let mut entries_map = HashMap::new();
entries_map.insert(
"mozilla.org".to_owned(),
- vec![HstsEntry::new(
- "mozilla.org".to_owned(),
- IncludeSubdomains::NotIncluded,
- None,
- )
- .unwrap()],
+ vec![
+ HstsEntry::new(
+ "mozilla.org".to_owned(),
+ IncludeSubdomains::NotIncluded,
+ None,
+ )
+ .unwrap(),
+ ],
);
let hsts_list = HstsList {
@@ -320,12 +326,14 @@ fn test_hsts_list_with_subdomain_when_include_subdomains_is_false_is_not_is_host
let mut entries_map = HashMap::new();
entries_map.insert(
"mozilla.org".to_owned(),
- vec![HstsEntry::new(
- "mozilla.org".to_owned(),
- IncludeSubdomains::NotIncluded,
- None,
- )
- .unwrap()],
+ vec![
+ HstsEntry::new(
+ "mozilla.org".to_owned(),
+ IncludeSubdomains::NotIncluded,
+ None,
+ )
+ .unwrap(),
+ ],
);
let hsts_list = HstsList {
entries_map: entries_map,
diff --git a/components/net/tests/http_cache.rs b/components/net/tests/http_cache.rs
index 57d2d5f0dba..e37455c5d73 100644
--- a/components/net/tests/http_cache.rs
+++ b/components/net/tests/http_cache.rs
@@ -3,8 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::id::TEST_PIPELINE_ID;
-use http::header::{HeaderValue, EXPIRES};
use http::StatusCode;
+use http::header::{EXPIRES, HeaderValue};
use net::http_cache::HttpCache;
use net_traits::request::{Referrer, RequestBuilder};
use net_traits::response::{Response, ResponseBody};
diff --git a/components/net/tests/http_loader.rs b/components/net/tests/http_loader.rs
index b95166d8ee2..b3afe11852c 100644
--- a/components/net/tests/http_loader.rs
+++ b/components/net/tests/http_loader.rs
@@ -12,14 +12,14 @@ use std::time::Duration;
use base::id::{TEST_PIPELINE_ID, TEST_WEBVIEW_ID};
use cookie::Cookie as CookiePair;
-use crossbeam_channel::{unbounded, Receiver};
+use crossbeam_channel::{Receiver, unbounded};
use devtools_traits::{
ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest,
HttpResponse as DevtoolsHttpResponse, NetworkEvent,
};
use embedder_traits::AuthenticationResponse;
-use flate2::write::{GzEncoder, ZlibEncoder};
use flate2::Compression;
+use flate2::write::{GzEncoder, ZlibEncoder};
use headers::authorization::Basic;
use headers::{
Authorization, ContentLength, Date, HeaderMapExt, Host, StrictTransportSecurity, UserAgent,
@@ -37,7 +37,7 @@ use net::cookie_storage::CookieStorage;
use net::fetch::methods::{self};
use net::http_loader::{determine_requests_referrer, serialize_origin};
use net::resource_thread::AuthCacheEntry;
-use net::test::{replace_host_table, DECODER_BUFFER_SIZE};
+use net::test::{DECODER_BUFFER_SIZE, replace_host_table};
use net_traits::http_status::HttpStatus;
use net_traits::request::{
BodyChunkRequest, BodyChunkResponse, BodySource, CredentialsMode, Destination, Referrer,
@@ -184,12 +184,14 @@ fn test_check_default_headers_loaded_in_every_request() {
.build();
let response = dbg!(fetch(request, None));
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
// Testing for method.POST
let mut post_headers = headers.clone();
@@ -210,19 +212,21 @@ fn test_check_default_headers_loaded_in_every_request() {
.build();
let response = fetch(request, None);
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
let _ = server.close();
}
#[test]
-fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length_should_be_set_to_0(
-) {
+fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length_should_be_set_to_0()
+ {
let handler = move |request: HyperRequest<Incoming>,
_: &mut HyperResponse<BoxBody<Bytes, hyper::Error>>| {
assert_eq!(
@@ -241,12 +245,14 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length
.build();
let response = fetch(request, None);
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
let _ = server.close();
}
@@ -276,12 +282,14 @@ fn test_request_and_response_data_with_network_messages() {
let (devtools_chan, devtools_port) = unbounded();
let response = fetch(request, Some(devtools_chan));
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
let _ = server.close();
@@ -487,8 +495,8 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
}
#[test]
-fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_content_encoding_deflate(
-) {
+fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_content_encoding_deflate()
+ {
let handler =
move |_: HyperRequest<Incoming>,
response: &mut HyperResponse<BoxBody<Bytes, hyper::Error>>| {
@@ -628,12 +636,14 @@ fn test_load_doesnt_add_host_to_hsts_list_when_url_is_http_even_if_hsts_headers_
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
assert_eq!(
context
.state
@@ -675,12 +685,14 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
assert_cookie_for_domain(
&context.state.cookie_jar,
@@ -728,12 +740,14 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -775,12 +789,14 @@ fn test_load_sends_cookie_if_nonhttp() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -814,12 +830,14 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
assert_cookie_for_domain(
&context.state.cookie_jar,
@@ -827,9 +845,11 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
Some("mozillaIs=theBest"),
);
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
- assert!(cookie_jar
- .cookies_for_url(&url, CookieSource::NonHTTP)
- .is_none());
+ assert!(
+ cookie_jar
+ .cookies_for_url(&url, CookieSource::NonHTTP)
+ .is_none()
+ );
}
#[test]
@@ -897,12 +917,14 @@ fn test_load_sets_content_length_to_length_of_request_body() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -937,12 +959,14 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -974,12 +998,14 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1014,12 +1040,14 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1051,12 +1079,14 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1397,12 +1427,14 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1593,12 +1625,14 @@ fn test_user_credentials_prompt_when_proxy_authentication_is_required() {
let _ = server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1643,12 +1677,14 @@ fn test_prompt_credentials_when_client_receives_unauthorized_response() {
server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_success());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_success()
+ );
}
#[test]
@@ -1687,12 +1723,14 @@ fn test_prompt_credentials_user_cancels_dialog_input() {
server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_client_error());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_client_error()
+ );
}
#[test]
@@ -1737,12 +1775,14 @@ fn test_prompt_credentials_user_input_incorrect_credentials() {
server.close();
- assert!(response
- .internal_response
- .unwrap()
- .status
- .code()
- .is_client_error());
+ assert!(
+ response
+ .internal_response
+ .unwrap()
+ .status
+ .code()
+ .is_client_error()
+ );
}
#[test]
diff --git a/components/net/tests/main.rs b/components/net/tests/main.rs
index 531fefb1eb0..504fea09777 100644
--- a/components/net/tests/main.rs
+++ b/components/net/tests/main.rs
@@ -26,7 +26,7 @@ use std::net::TcpListener as StdTcpListener;
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, Mutex, RwLock, Weak};
-use crossbeam_channel::{unbounded, Receiver, Sender};
+use crossbeam_channel::{Receiver, Sender, unbounded};
use devtools_traits::DevtoolsControlMsg;
use embedder_traits::{AuthenticationResponse, EmbedderMsg, EmbedderProxy, EventLoopWaker};
use futures::future::ready;
@@ -127,15 +127,17 @@ fn receive_credential_prompt_msgs(
embedder_receiver: Receiver<EmbedderMsg>,
response: Option<AuthenticationResponse>,
) -> std::thread::JoinHandle<()> {
- std::thread::spawn(move || loop {
- let embedder_msg = embedder_receiver.recv().unwrap();
- match embedder_msg {
- embedder_traits::EmbedderMsg::RequestAuthentication(_, _, _, response_sender) => {
- let _ = response_sender.send(response);
- break;
- },
- embedder_traits::EmbedderMsg::WebResourceRequested(..) => {},
- _ => unreachable!(),
+ std::thread::spawn(move || {
+ loop {
+ let embedder_msg = embedder_receiver.recv().unwrap();
+ match embedder_msg {
+ embedder_traits::EmbedderMsg::RequestAuthentication(_, _, _, response_sender) => {
+ let _ = response_sender.send(response);
+ break;
+ },
+ embedder_traits::EmbedderMsg::WebResourceRequested(..) => {},
+ _ => unreachable!(),
+ }
}
})
}
diff --git a/components/net/tests/subresource_integrity.rs b/components/net/tests/subresource_integrity.rs
index b6063a7528d..c3c40a95154 100644
--- a/components/net/tests/subresource_integrity.rs
+++ b/components/net/tests/subresource_integrity.rs
@@ -3,8 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use net::subresource_integrity::{
- get_prioritized_hash_function, get_strongest_metadata, is_response_integrity_valid,
- parsed_metadata, SriEntry,
+ SriEntry, get_prioritized_hash_function, get_strongest_metadata, is_response_integrity_valid,
+ parsed_metadata,
};
use net_traits::response::{Response, ResponseBody};
use net_traits::{ResourceFetchTiming, ResourceTimingType};