diff options
Diffstat (limited to 'chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc')
-rw-r--r-- | chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc | 97 |
1 files changed, 92 insertions, 5 deletions
diff --git a/chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc b/chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc index 4cafe900bb2..538274d42a9 100644 --- a/chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc +++ b/chromium/content/browser/loader/navigation_url_loader_impl_unittest.cc @@ -104,7 +104,7 @@ class TestNavigationLoaderInterceptor : public NavigationLoaderInterceptor { } private: - void DeleteURLLoader(network::URLLoader* url_loader) { + void DeleteURLLoader(network::mojom::URLLoader* url_loader) { DCHECK_EQ(url_loader_.get(), url_loader); url_loader_.reset(); } @@ -154,7 +154,8 @@ class NavigationURLLoaderImplTest : public testing::Test { const std::string& method, NavigationURLLoaderDelegate* delegate, bool allow_download = false, - bool is_main_frame = true) { + bool is_main_frame = true, + bool upgrade_if_insecure = false) { mojom::BeginNavigationParamsPtr begin_params = mojom::BeginNavigationParams::New( headers, net::LOAD_NORMAL, false /* skip_service_worker */, @@ -176,8 +177,10 @@ class NavigationURLLoaderImplTest : public testing::Test { false /* parent_is_main_frame */, false /* are_ancestors_secure */, -1 /* frame_tree_node_id */, false /* is_for_guests_only */, false /* report_raw_headers */, false /* is_prerenering */, + upgrade_if_insecure /* upgrade_if_insecure */, nullptr /* blob_url_loader_factory */, - base::UnguessableToken::Create() /* devtools_navigation_token */)); + base::UnguessableToken::Create() /* devtools_navigation_token */, + base::UnguessableToken::Create() /* devtools_frame_token */)); std::vector<std::unique_ptr<NavigationLoaderInterceptor>> interceptors; most_recent_resource_request_ = base::nullopt; interceptors.push_back(std::make_unique<TestNavigationLoaderInterceptor>( @@ -210,7 +213,7 @@ class NavigationURLLoaderImplTest : public testing::Test { redirect_url.GetOrigin().spec().c_str()), request_method, &delegate); delegate.WaitForRequestRedirected(); - loader->FollowRedirect(); + loader->FollowRedirect(base::nullopt, base::nullopt); EXPECT_EQ(expected_redirect_method, delegate.redirect_info().new_method); @@ -251,12 +254,32 @@ class NavigationURLLoaderImplTest : public testing::Test { url.GetOrigin().spec().c_str()), "GET", &delegate, false /* allow_download */, is_main_frame); delegate.WaitForRequestRedirected(); - loader->FollowRedirect(); + loader->FollowRedirect(base::nullopt, base::nullopt); delegate.WaitForResponseStarted(); return most_recent_resource_request_.value().priority; } + net::RedirectInfo NavigateAndReturnRedirectInfo(const GURL& url, + bool upgrade_if_insecure, + bool expect_request_fail) { + TestNavigationURLLoaderDelegate delegate; + std::unique_ptr<NavigationURLLoader> loader = CreateTestLoader( + url, + base::StringPrintf("%s: %s", net::HttpRequestHeaders::kOrigin, + url.GetOrigin().spec().c_str()), + "GET", &delegate, false /* allow_download */, true /*is_main_frame*/, + upgrade_if_insecure); + delegate.WaitForRequestRedirected(); + loader->FollowRedirect(base::nullopt, base::nullopt); + if (expect_request_fail) { + delegate.WaitForRequestFailed(); + } else { + delegate.WaitForResponseStarted(); + } + return delegate.redirect_info(); + } + protected: base::test::ScopedFeatureList feature_list_; TestBrowserThreadBundle thread_bundle_; @@ -345,4 +368,68 @@ TEST_F(NavigationURLLoaderImplTest, Redirect308Tests) { true); } +TEST_F(NavigationURLLoaderImplTest, RedirectModifiedHeaders) { + ASSERT_TRUE(http_test_server_.Start()); + + const GURL redirect_url = http_test_server_.GetURL("/redirect301-to-echo"); + + TestNavigationURLLoaderDelegate delegate; + std::unique_ptr<NavigationURLLoader> loader = CreateTestLoader( + redirect_url, "Header1: Value1\r\nHeader2: Value2", "GET", &delegate); + delegate.WaitForRequestRedirected(); + + ASSERT_TRUE(most_recent_resource_request_); + + // Initial request should only have initial headers. + std::string header1, header2; + EXPECT_TRUE( + most_recent_resource_request_->headers.GetHeader("Header1", &header1)); + EXPECT_EQ("Value1", header1); + EXPECT_TRUE( + most_recent_resource_request_->headers.GetHeader("Header2", &header2)); + EXPECT_EQ("Value2", header2); + EXPECT_FALSE(most_recent_resource_request_->headers.HasHeader("Header3")); + + // Overwrite Header2 and add Header3. + net::HttpRequestHeaders redirect_headers; + redirect_headers.SetHeader("Header2", ""); + redirect_headers.SetHeader("Header3", "Value3"); + loader->FollowRedirect(base::nullopt, redirect_headers); + delegate.WaitForResponseStarted(); + + // Redirected request should also have modified headers. + EXPECT_TRUE( + most_recent_resource_request_->headers.GetHeader("Header1", &header1)); + EXPECT_EQ("Value1", header1); + EXPECT_TRUE( + most_recent_resource_request_->headers.GetHeader("Header2", &header2)); + EXPECT_EQ("", header2); + std::string header3; + EXPECT_TRUE( + most_recent_resource_request_->headers.GetHeader("Header3", &header3)); + EXPECT_EQ("Value3", header3); +} + +// Tests that the Upgrade If Insecure flag is obeyed. +TEST_F(NavigationURLLoaderImplTest, UpgradeIfInsecureTest) { + ASSERT_TRUE(http_test_server_.Start()); + const GURL url = http_test_server_.GetURL("/redirect301-to-http"); + GURL expected_url = GURL("http://test.test/test"); + // We expect the request to fail since there is no server listening at + // test.test, but for the purpose of this test we only need to validate the + // redirect URL was not changed. + net::RedirectInfo redirect_info = NavigateAndReturnRedirectInfo( + url, false /* upgrade_if_insecure */, true /* expect_request_fail */); + EXPECT_FALSE(redirect_info.insecure_scheme_was_upgraded); + EXPECT_EQ(expected_url, redirect_info.new_url); + GURL::Replacements replacements; + replacements.SetSchemeStr("https"); + expected_url = expected_url.ReplaceComponents(replacements); + redirect_info = NavigateAndReturnRedirectInfo( + url, true /* upgrade_if_insecure */, true /* expect_request_fail */); + // Same as above, but validating the URL is upgraded to https. + EXPECT_TRUE(redirect_info.insecure_scheme_was_upgraded); + EXPECT_EQ(expected_url, redirect_info.new_url); +} + } // namespace content |