diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-10-31 17:21:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-31 16:21:27 +0000 |
commit | f5fd560ef8cc1ae9c67641808956cefbacfa3169 (patch) | |
tree | dd6b1d6fa2434dc5d1ba622751c784d255068002 /components/net/tests | |
parent | 851b125d4b42ff9663e1f9bed423aedf0657fa13 (diff) | |
download | servo-f5fd560ef8cc1ae9c67641808956cefbacfa3169.tar.gz servo-f5fd560ef8cc1ae9c67641808956cefbacfa3169.zip |
net: Ensure that origin serialization is consistent (#34081)
A recent refactoring (#33531) made a change that resulted in the
`Origin` header including the port even when the default port for a
scheme was used. This made the serialization different from that used
for `rust-url`'s `Origin::ascii_serialization()`, breaking CORS on some
sites. This change makes it so that the serialization is consistent
again.
This change also fixes the visiblity on a few methods in
`http_loader.rs` since visibility needs to be adjusted for testing
anyway.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/net/tests')
-rw-r--r-- | components/net/tests/http_loader.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/components/net/tests/http_loader.rs b/components/net/tests/http_loader.rs index d19febcbd7e..68c8868428a 100644 --- a/components/net/tests/http_loader.rs +++ b/components/net/tests/http_loader.rs @@ -33,7 +33,7 @@ use ipc_channel::router::ROUTER; use net::cookie::ServoCookie; use net::cookie_storage::CookieStorage; use net::fetch::methods::{self}; -use net::http_loader::determine_requests_referrer; +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_traits::http_status::HttpStatus; @@ -45,6 +45,7 @@ use net_traits::response::{Response, ResponseBody}; use net_traits::{CookieSource, FetchTaskTarget, NetworkError, ReferrerPolicy}; use servo_url::{ImmutableOrigin, ServoUrl}; use tokio_test::block_on; +use url::Url; use crate::{fetch, fetch_with_context, make_server, new_fetch_context}; @@ -1457,3 +1458,24 @@ fn test_fetch_compressed_response_update_count() { (DATA_DECOMPRESSED_LEN + DECODER_BUFFER_SIZE - 1) / DECODER_BUFFER_SIZE; assert_eq!(response_update_count, EXPECTED_UPDATE_COUNT); } + +#[test] +fn test_origin_serialization_compatability() { + let ensure_serialiations_match = |url_string| { + let url = Url::parse(url_string).unwrap(); + let origin = ImmutableOrigin::new(url.origin()); + let serialized = format!("{}", serialize_origin(&origin)); + assert_eq!(serialized, origin.ascii_serialization()); + }; + + ensure_serialiations_match("https://example.com"); + ensure_serialiations_match("https://example.com:443"); + + ensure_serialiations_match("http://example.com"); + ensure_serialiations_match("http://example.com:80"); + + ensure_serialiations_match("https://example.com:1234"); + ensure_serialiations_match("http://example.com:1234"); + + ensure_serialiations_match("data:,dataurltexta"); +} |