Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2917133002: Perform redirect checks before OnReceivedRedirect in //net. (Closed)
Patch Set: nasko comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 6973 matching lines...) Expand 10 before | Expand all | Expand 10 after
6984 ASSERT_TRUE(http_test_server()->Start()); 6984 ASSERT_TRUE(http_test_server()->Start());
6985 6985
6986 TestDelegate d; 6986 TestDelegate d;
6987 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6987 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6988 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY, 6988 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY,
6989 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); 6989 &d, TRAFFIC_ANNOTATION_FOR_TESTS));
6990 req->Start(); 6990 req->Start();
6991 base::RunLoop().Run(); 6991 base::RunLoop().Run();
6992 6992
6993 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); 6993 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
6994
6995 // The redirect should have been rejected before reporting it to the caller.
6996 EXPECT_EQ(0, d.received_redirect_count());
6994 } 6997 }
6995 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) 6998 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT)
6996 6999
6997 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 7000 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
6998 ASSERT_TRUE(http_test_server()->Start()); 7001 ASSERT_TRUE(http_test_server()->Start());
6999 7002
7000 TestDelegate d; 7003 TestDelegate d;
7001 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 7004 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
7002 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY, 7005 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY,
7003 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); 7006 &d, TRAFFIC_ANNOTATION_FOR_TESTS));
7004 req->Start(); 7007 req->Start();
7005 base::RunLoop().Run(); 7008 base::RunLoop().Run();
7006 7009
7007 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); 7010 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
7011
7012 // The redirect should have been rejected before reporting it to the
7013 // caller. See https://crbug.com/723796
7014 EXPECT_EQ(0, d.received_redirect_count());
7008 } 7015 }
7009 7016
7017 // Test that redirects to invalid URLs are rejected. See
7018 // https://crbug.com/462272.
7010 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 7019 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
7011 ASSERT_TRUE(http_test_server()->Start()); 7020 ASSERT_TRUE(http_test_server()->Start());
7012 7021
7013 TestDelegate d; 7022 TestDelegate d;
7014 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 7023 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
7015 http_test_server()->GetURL("/redirect-to-invalid-url.html"), 7024 http_test_server()->GetURL("/redirect-to-invalid-url.html"),
7016 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); 7025 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
7017 req->Start(); 7026 req->Start();
7018 base::RunLoop().Run(); 7027 base::RunLoop().Run();
7019 7028
7020 EXPECT_EQ(ERR_INVALID_URL, d.request_status()); 7029 EXPECT_EQ(1, d.response_started_count());
7030 EXPECT_EQ(ERR_INVALID_REDIRECT, d.request_status());
7031
7032 // The redirect should have been rejected before reporting it to the caller.
7033 EXPECT_EQ(0, d.received_redirect_count());
7021 } 7034 }
7022 7035
7023 // Make sure redirects are cached, despite not reading their bodies. 7036 // Make sure redirects are cached, despite not reading their bodies.
7024 TEST_F(URLRequestTestHTTP, CacheRedirect) { 7037 TEST_F(URLRequestTestHTTP, CacheRedirect) {
7025 ASSERT_TRUE(http_test_server()->Start()); 7038 ASSERT_TRUE(http_test_server()->Start());
7026 GURL redirect_url = 7039 GURL redirect_url =
7027 http_test_server()->GetURL("/redirect302-to-echo-cacheable"); 7040 http_test_server()->GetURL("/redirect302-to-echo-cacheable");
7028 7041
7029 { 7042 {
7030 TestDelegate d; 7043 TestDelegate d;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
7134 TestDelegate d; 7147 TestDelegate d;
7135 { 7148 {
7136 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 7149 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
7137 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d, 7150 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d,
7138 TRAFFIC_ANNOTATION_FOR_TESTS)); 7151 TRAFFIC_ANNOTATION_FOR_TESTS));
7139 7152
7140 r->Start(); 7153 r->Start();
7141 base::RunLoop().Run(); 7154 base::RunLoop().Run();
7142 7155
7143 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); 7156 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
7157
7158 // The redirect should have been rejected before reporting it to the caller.
7159 EXPECT_EQ(0, d.received_redirect_count());
7144 } 7160 }
7145 } 7161 }
7146 7162
7147 // Redirects from an URL with fragment to an unsafe URL with fragment should 7163 // Redirects from an URL with fragment to an unsafe URL with fragment should
7148 // be allowed, and the reference fragment of the target URL should be preserved. 7164 // be allowed, and the reference fragment of the target URL should be preserved.
7149 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { 7165 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) {
7150 ASSERT_TRUE(http_test_server()->Start()); 7166 ASSERT_TRUE(http_test_server()->Start());
7151 7167
7152 GURL original_url(http_test_server()->GetURL("/original#fragment1")); 7168 GURL original_url(http_test_server()->GetURL("/original#fragment1"));
7153 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 7169 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
(...skipping 4079 matching lines...) Expand 10 before | Expand all | Expand 10 after
11233 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 11249 AddTestInterceptor()->set_main_intercept_job(std::move(job));
11234 11250
11235 req->Start(); 11251 req->Start();
11236 req->Cancel(); 11252 req->Cancel();
11237 base::RunLoop().RunUntilIdle(); 11253 base::RunLoop().RunUntilIdle();
11238 EXPECT_EQ(ERR_ABORTED, d.request_status()); 11254 EXPECT_EQ(ERR_ABORTED, d.request_status());
11239 EXPECT_EQ(0, d.received_redirect_count()); 11255 EXPECT_EQ(0, d.received_redirect_count());
11240 } 11256 }
11241 11257
11242 } // namespace net 11258 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698