OLD | NEW |
---|---|
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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 GURL* new_url) OVERRIDE; | 361 GURL* new_url) OVERRIDE; |
362 | 362 |
363 virtual int OnBeforeSendHeaders(URLRequest* request, | 363 virtual int OnBeforeSendHeaders(URLRequest* request, |
364 const CompletionCallback& callback, | 364 const CompletionCallback& callback, |
365 HttpRequestHeaders* headers) OVERRIDE; | 365 HttpRequestHeaders* headers) OVERRIDE; |
366 | 366 |
367 virtual int OnHeadersReceived( | 367 virtual int OnHeadersReceived( |
368 URLRequest* request, | 368 URLRequest* request, |
369 const CompletionCallback& callback, | 369 const CompletionCallback& callback, |
370 const HttpResponseHeaders* original_response_headers, | 370 const HttpResponseHeaders* original_response_headers, |
371 scoped_refptr<HttpResponseHeaders>* override_response_headers) OVERRIDE; | 371 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
372 GURL* allowed_unsafe_redirect_url) OVERRIDE; | |
372 | 373 |
373 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 374 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
374 URLRequest* request, | 375 URLRequest* request, |
375 const AuthChallengeInfo& auth_info, | 376 const AuthChallengeInfo& auth_info, |
376 const AuthCallback& callback, | 377 const AuthCallback& callback, |
377 AuthCredentials* credentials) OVERRIDE; | 378 AuthCredentials* credentials) OVERRIDE; |
378 | 379 |
379 // Resets the callbacks and |stage_blocked_for_callback_|. | 380 // Resets the callbacks and |stage_blocked_for_callback_|. |
380 void Reset(); | 381 void Reset(); |
381 | 382 |
382 // Checks whether we should block in |stage|. If yes, returns an error code | 383 // Checks whether we should block in |stage|. If yes, returns an error code |
383 // and optionally sets up callback based on |block_mode_|. If no, returns OK. | 384 // and optionally sets up callback based on |block_mode_|. If no, returns OK. |
384 int MaybeBlockStage(Stage stage, const CompletionCallback& callback); | 385 int MaybeBlockStage(Stage stage, const CompletionCallback& callback); |
385 | 386 |
386 // Configuration parameters, can be adjusted by public methods: | 387 // Configuration parameters, can be adjusted by public methods: |
387 const BlockMode block_mode_; | 388 const BlockMode block_mode_; |
388 | 389 |
389 // Values returned on blocking stages when mode is SYNCHRONOUS or | 390 // Values returned on blocking stages when mode is SYNCHRONOUS or |
390 // AUTO_CALLBACK. For USER_CALLBACK these are set automatically to IO_PENDING. | 391 // AUTO_CALLBACK. For USER_CALLBACK these are set automatically to IO_PENDING. |
391 int retval_; // To be returned in non-auth stages. | 392 int retval_; // To be returned in non-auth stages. |
392 AuthRequiredResponse auth_retval_; | 393 AuthRequiredResponse auth_retval_; |
393 | 394 |
394 GURL redirect_url_; // Used if non-empty. | 395 GURL redirect_url_; // Used if non-empty during OnBeforeURLRequest. |
395 int block_on_; // Bit mask: in which stages to block. | 396 int block_on_; // Bit mask: in which stages to block. |
396 | 397 |
397 // |auth_credentials_| will be copied to |*target_auth_credential_| on | 398 // |auth_credentials_| will be copied to |*target_auth_credential_| on |
398 // callback. | 399 // callback. |
399 AuthCredentials auth_credentials_; | 400 AuthCredentials auth_credentials_; |
400 AuthCredentials* target_auth_credentials_; | 401 AuthCredentials* target_auth_credentials_; |
401 | 402 |
402 // Internal variables, not set by not the user: | 403 // Internal variables, not set by not the user: |
403 // Last blocked stage waiting for user callback (unused if |block_mode_| != | 404 // Last blocked stage waiting for user callback (unused if |block_mode_| != |
404 // USER_CALLBACK). | 405 // USER_CALLBACK). |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 HttpRequestHeaders* headers) { | 477 HttpRequestHeaders* headers) { |
477 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers); | 478 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers); |
478 | 479 |
479 return MaybeBlockStage(ON_BEFORE_SEND_HEADERS, callback); | 480 return MaybeBlockStage(ON_BEFORE_SEND_HEADERS, callback); |
480 } | 481 } |
481 | 482 |
482 int BlockingNetworkDelegate::OnHeadersReceived( | 483 int BlockingNetworkDelegate::OnHeadersReceived( |
483 URLRequest* request, | 484 URLRequest* request, |
484 const CompletionCallback& callback, | 485 const CompletionCallback& callback, |
485 const HttpResponseHeaders* original_response_headers, | 486 const HttpResponseHeaders* original_response_headers, |
486 scoped_refptr<HttpResponseHeaders>* override_response_headers) { | 487 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
487 TestNetworkDelegate::OnHeadersReceived( | 488 GURL* allowed_unsafe_redirect_url) { |
488 request, callback, original_response_headers, | 489 TestNetworkDelegate::OnHeadersReceived(request, |
489 override_response_headers); | 490 callback, |
491 original_response_headers, | |
492 override_response_headers, | |
493 allowed_unsafe_redirect_url); | |
490 | 494 |
491 return MaybeBlockStage(ON_HEADERS_RECEIVED, callback); | 495 return MaybeBlockStage(ON_HEADERS_RECEIVED, callback); |
492 } | 496 } |
493 | 497 |
494 NetworkDelegate::AuthRequiredResponse BlockingNetworkDelegate::OnAuthRequired( | 498 NetworkDelegate::AuthRequiredResponse BlockingNetworkDelegate::OnAuthRequired( |
495 URLRequest* request, | 499 URLRequest* request, |
496 const AuthChallengeInfo& auth_info, | 500 const AuthChallengeInfo& auth_info, |
497 const AuthCallback& callback, | 501 const AuthCallback& callback, |
498 AuthCredentials* credentials) { | 502 AuthCredentials* credentials) { |
499 TestNetworkDelegate::OnAuthRequired(request, auth_info, callback, | 503 TestNetworkDelegate::OnAuthRequired(request, auth_info, callback, |
(...skipping 1910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2410 public: | 2414 public: |
2411 explicit FixedDateNetworkDelegate(const std::string& fixed_date) | 2415 explicit FixedDateNetworkDelegate(const std::string& fixed_date) |
2412 : fixed_date_(fixed_date) {} | 2416 : fixed_date_(fixed_date) {} |
2413 virtual ~FixedDateNetworkDelegate() {} | 2417 virtual ~FixedDateNetworkDelegate() {} |
2414 | 2418 |
2415 // net::NetworkDelegate implementation | 2419 // net::NetworkDelegate implementation |
2416 virtual int OnHeadersReceived( | 2420 virtual int OnHeadersReceived( |
2417 net::URLRequest* request, | 2421 net::URLRequest* request, |
2418 const net::CompletionCallback& callback, | 2422 const net::CompletionCallback& callback, |
2419 const net::HttpResponseHeaders* original_response_headers, | 2423 const net::HttpResponseHeaders* original_response_headers, |
2420 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) | 2424 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
2421 OVERRIDE; | 2425 GURL* allowed_unsafe_redirect_url) OVERRIDE; |
2422 | 2426 |
2423 private: | 2427 private: |
2424 std::string fixed_date_; | 2428 std::string fixed_date_; |
2425 | 2429 |
2426 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate); | 2430 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate); |
2427 }; | 2431 }; |
2428 | 2432 |
2429 int FixedDateNetworkDelegate::OnHeadersReceived( | 2433 int FixedDateNetworkDelegate::OnHeadersReceived( |
2430 net::URLRequest* request, | 2434 net::URLRequest* request, |
2431 const net::CompletionCallback& callback, | 2435 const net::CompletionCallback& callback, |
2432 const net::HttpResponseHeaders* original_response_headers, | 2436 const net::HttpResponseHeaders* original_response_headers, |
2433 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 2437 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
2438 GURL* allowed_unsafe_redirect_url) { | |
2434 net::HttpResponseHeaders* new_response_headers = | 2439 net::HttpResponseHeaders* new_response_headers = |
2435 new net::HttpResponseHeaders(original_response_headers->raw_headers()); | 2440 new net::HttpResponseHeaders(original_response_headers->raw_headers()); |
2436 | 2441 |
2437 new_response_headers->RemoveHeader("Date"); | 2442 new_response_headers->RemoveHeader("Date"); |
2438 new_response_headers->AddHeader("Date: " + fixed_date_); | 2443 new_response_headers->AddHeader("Date: " + fixed_date_); |
2439 | 2444 |
2440 *override_response_headers = new_response_headers; | 2445 *override_response_headers = new_response_headers; |
2441 return TestNetworkDelegate::OnHeadersReceived(request, | 2446 return TestNetworkDelegate::OnHeadersReceived(request, |
2442 callback, | 2447 callback, |
2443 original_response_headers, | 2448 original_response_headers, |
2444 override_response_headers); | 2449 override_response_headers, |
2450 allowed_unsafe_redirect_url); | |
2445 } | 2451 } |
2446 | 2452 |
2447 // Test that cookie expiration times are adjusted for server/client clock | 2453 // Test that cookie expiration times are adjusted for server/client clock |
2448 // skew and that we handle incorrect timezone specifier "UTC" in HTTP Date | 2454 // skew and that we handle incorrect timezone specifier "UTC" in HTTP Date |
2449 // headers by defaulting to GMT. (crbug.com/135131) | 2455 // headers by defaulting to GMT. (crbug.com/135131) |
2450 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { | 2456 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { |
2451 LocalHttpTestServer test_server; | 2457 LocalHttpTestServer test_server; |
2452 ASSERT_TRUE(test_server.Start()); | 2458 ASSERT_TRUE(test_server.Start()); |
2453 | 2459 |
2454 // Set up an expired cookie. | 2460 // Set up an expired cookie. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 EXPECT_TRUE(test_server_.Stop()); | 2696 EXPECT_TRUE(test_server_.Stop()); |
2691 EXPECT_TRUE(test_server_.Start()); | 2697 EXPECT_TRUE(test_server_.Start()); |
2692 } | 2698 } |
2693 | 2699 |
2694 return is_success; | 2700 return is_success; |
2695 } | 2701 } |
2696 | 2702 |
2697 LocalHttpTestServer test_server_; | 2703 LocalHttpTestServer test_server_; |
2698 }; | 2704 }; |
2699 | 2705 |
2706 // Tests that redirection to an unsafe URL is allowed when it has been marked as | |
2707 // safe. | |
2708 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { | |
mmenke
2014/03/25 20:27:37
nit: These should go down with the other unsafere
| |
2709 ASSERT_TRUE(test_server_.Start()); | |
2710 | |
2711 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); | |
2712 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | |
2713 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | |
2714 | |
2715 TestDelegate d; | |
2716 { | |
2717 URLRequest r(test_server_.GetURL("whatever"), | |
2718 DEFAULT_PRIORITY, | |
2719 &d, | |
2720 &default_context_); | |
2721 | |
2722 r.Start(); | |
2723 base::RunLoop().Run(); | |
2724 | |
2725 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
2726 | |
2727 EXPECT_EQ(2U, r.url_chain().size()); | |
2728 EXPECT_EQ(net::OK, r.status().error()); | |
2729 EXPECT_EQ(unsafe_url, r.url()); | |
2730 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); | |
2731 } | |
2732 } | |
2733 | |
2734 // Tests that a redirect to a different unsafe URL is blocked, even after adding | |
2735 // some other URL to the whitelist. | |
2736 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { | |
2737 ASSERT_TRUE(test_server_.Start()); | |
2738 | |
2739 GURL unsafe_url("data:text/html,something"); | |
2740 GURL different_unsafe_url("data:text/html,something-else"); | |
2741 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | |
2742 default_network_delegate_.set_allowed_unsafe_redirect_url( | |
2743 different_unsafe_url); | |
2744 | |
2745 TestDelegate d; | |
2746 { | |
2747 URLRequest r(test_server_.GetURL("whatever"), | |
2748 DEFAULT_PRIORITY, | |
2749 &d, | |
2750 &default_context_); | |
2751 | |
2752 r.Start(); | |
2753 base::RunLoop().Run(); | |
2754 | |
2755 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | |
2756 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r.status().error()); | |
2757 } | |
2758 } | |
2759 | |
2700 // In this unit test, we're using the HTTPTestServer as a proxy server and | 2760 // In this unit test, we're using the HTTPTestServer as a proxy server and |
2701 // issuing a CONNECT request with the magic host name "www.redirect.com". | 2761 // issuing a CONNECT request with the magic host name "www.redirect.com". |
2702 // The HTTPTestServer will return a 302 response, which we should not | 2762 // The HTTPTestServer will return a 302 response, which we should not |
2703 // follow. | 2763 // follow. |
2704 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 2764 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
2705 ASSERT_TRUE(test_server_.Start()); | 2765 ASSERT_TRUE(test_server_.Start()); |
2706 | 2766 |
2707 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2767 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
2708 TestURLRequestContextWithProxy context( | 2768 TestURLRequestContextWithProxy context( |
2709 test_server_.host_port_pair().ToString(), &network_delegate); | 2769 test_server_.host_port_pair().ToString(), &network_delegate); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3001 EXPECT_EQ(original_url, r.original_url()); | 3061 EXPECT_EQ(original_url, r.original_url()); |
3002 EXPECT_EQ(2U, r.url_chain().size()); | 3062 EXPECT_EQ(2U, r.url_chain().size()); |
3003 EXPECT_EQ(1, network_delegate.created_requests()); | 3063 EXPECT_EQ(1, network_delegate.created_requests()); |
3004 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3064 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
3005 EXPECT_EQ("POST", r.method()); | 3065 EXPECT_EQ("POST", r.method()); |
3006 EXPECT_EQ(kData, d.data_received()); | 3066 EXPECT_EQ(kData, d.data_received()); |
3007 } | 3067 } |
3008 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3068 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
3009 } | 3069 } |
3010 | 3070 |
3071 // Tests that the network delegate can block and redirect a request to a new | |
3072 // URL during OnHeadersReceived. | |
3073 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { | |
3074 ASSERT_TRUE(test_server_.Start()); | |
3075 | |
3076 TestDelegate d; | |
3077 BlockingNetworkDelegate network_delegate( | |
3078 BlockingNetworkDelegate::AUTO_CALLBACK); | |
3079 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | |
3080 GURL redirect_url(test_server_.GetURL("simple.html")); | |
3081 network_delegate.set_redirect_on_headers_received_url(redirect_url); | |
3082 | |
3083 TestURLRequestContextWithProxy context( | |
3084 test_server_.host_port_pair().ToString(), &network_delegate); | |
3085 | |
3086 { | |
3087 GURL original_url(test_server_.GetURL("empty.html")); | |
3088 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); | |
3089 | |
3090 r.Start(); | |
3091 base::RunLoop().Run(); | |
3092 | |
3093 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
3094 EXPECT_EQ(net::OK, r.status().error()); | |
3095 EXPECT_EQ(redirect_url, r.url()); | |
3096 EXPECT_EQ(original_url, r.original_url()); | |
3097 EXPECT_EQ(2U, r.url_chain().size()); | |
3098 EXPECT_EQ(2, network_delegate.created_requests()); | |
3099 EXPECT_EQ(0, network_delegate.destroyed_requests()); | |
3100 } | |
3101 EXPECT_EQ(1, network_delegate.destroyed_requests()); | |
3102 } | |
3103 | |
3011 // Tests that the network delegate can synchronously complete OnAuthRequired | 3104 // Tests that the network delegate can synchronously complete OnAuthRequired |
3012 // by taking no action. This indicates that the NetworkDelegate does not want to | 3105 // by taking no action. This indicates that the NetworkDelegate does not want to |
3013 // handle the challenge, and is passing the buck along to the | 3106 // handle the challenge, and is passing the buck along to the |
3014 // URLRequest::Delegate. | 3107 // URLRequest::Delegate. |
3015 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { | 3108 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { |
3016 ASSERT_TRUE(test_server_.Start()); | 3109 ASSERT_TRUE(test_server_.Start()); |
3017 | 3110 |
3018 TestDelegate d; | 3111 TestDelegate d; |
3019 BlockingNetworkDelegate network_delegate( | 3112 BlockingNetworkDelegate network_delegate( |
3020 BlockingNetworkDelegate::SYNCHRONOUS); | 3113 BlockingNetworkDelegate::SYNCHRONOUS); |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3913 const CompletionCallback& callback, | 4006 const CompletionCallback& callback, |
3914 HttpRequestHeaders* headers) OVERRIDE { | 4007 HttpRequestHeaders* headers) OVERRIDE { |
3915 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers); | 4008 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers); |
3916 return RunCallbackAsynchronously(request, callback); | 4009 return RunCallbackAsynchronously(request, callback); |
3917 } | 4010 } |
3918 | 4011 |
3919 virtual int OnHeadersReceived( | 4012 virtual int OnHeadersReceived( |
3920 URLRequest* request, | 4013 URLRequest* request, |
3921 const CompletionCallback& callback, | 4014 const CompletionCallback& callback, |
3922 const HttpResponseHeaders* original_response_headers, | 4015 const HttpResponseHeaders* original_response_headers, |
3923 scoped_refptr<HttpResponseHeaders>* override_response_headers) OVERRIDE { | 4016 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
3924 TestNetworkDelegate::OnHeadersReceived(request, callback, | 4017 GURL* allowed_unsafe_redirect_url) OVERRIDE { |
4018 TestNetworkDelegate::OnHeadersReceived(request, | |
4019 callback, | |
3925 original_response_headers, | 4020 original_response_headers, |
3926 override_response_headers); | 4021 override_response_headers, |
4022 allowed_unsafe_redirect_url); | |
3927 return RunCallbackAsynchronously(request, callback); | 4023 return RunCallbackAsynchronously(request, callback); |
3928 } | 4024 } |
3929 | 4025 |
3930 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 4026 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
3931 URLRequest* request, | 4027 URLRequest* request, |
3932 const AuthChallengeInfo& auth_info, | 4028 const AuthChallengeInfo& auth_info, |
3933 const AuthCallback& callback, | 4029 const AuthCallback& callback, |
3934 AuthCredentials* credentials) OVERRIDE { | 4030 AuthCredentials* credentials) OVERRIDE { |
3935 AsyncDelegateLogger::Run( | 4031 AsyncDelegateLogger::Run( |
3936 request, | 4032 request, |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5228 req.Start(); | 5324 req.Start(); |
5229 base::RunLoop().Run(); | 5325 base::RunLoop().Run(); |
5230 | 5326 |
5231 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5327 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
5232 EXPECT_FALSE(req.was_cached()); | 5328 EXPECT_FALSE(req.was_cached()); |
5233 EXPECT_EQ(0, d.received_redirect_count()); | 5329 EXPECT_EQ(0, d.received_redirect_count()); |
5234 EXPECT_EQ(initial_url, req.url()); | 5330 EXPECT_EQ(initial_url, req.url()); |
5235 } | 5331 } |
5236 } | 5332 } |
5237 | 5333 |
5334 // Redirects from an URL with fragment to an unsafe URL without fragment should | |
5335 // be allowed. | |
5336 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithReferenceFragment) { | |
5337 ASSERT_TRUE(test_server_.Start()); | |
5338 | |
5339 GURL original_url(test_server_.GetURL("original#fragment")); | |
5340 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect"); | |
5341 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment"); | |
5342 | |
5343 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | |
5344 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | |
5345 | |
5346 TestDelegate d; | |
5347 { | |
5348 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | |
5349 | |
5350 r.Start(); | |
5351 base::RunLoop().Run(); | |
5352 | |
5353 EXPECT_EQ(2U, r.url_chain().size()); | |
5354 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
5355 EXPECT_EQ(net::OK, r.status().error()); | |
5356 EXPECT_EQ(original_url, r.original_url()); | |
5357 EXPECT_EQ(expected_url, r.url()); | |
5358 } | |
5359 } | |
5360 | |
5361 // Redirects from an URL with fragment to an unsafe URL with fragment should | |
5362 // be allowed, and the reference fragment of the target URL should be preserved. | |
5363 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { | |
5364 ASSERT_TRUE(test_server_.Start()); | |
5365 | |
5366 GURL original_url(test_server_.GetURL("original#fragment")); | |
mmenke
2014/03/25 20:27:37
Should make it so that the fragment here is not a
| |
5367 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | |
5368 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | |
5369 | |
5370 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | |
5371 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | |
5372 | |
5373 TestDelegate d; | |
5374 { | |
5375 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | |
5376 | |
5377 r.Start(); | |
5378 base::RunLoop().Run(); | |
5379 | |
5380 EXPECT_EQ(2U, r.url_chain().size()); | |
5381 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
5382 EXPECT_EQ(net::OK, r.status().error()); | |
5383 EXPECT_EQ(original_url, r.original_url()); | |
5384 EXPECT_EQ(expected_url, r.url()); | |
5385 } | |
5386 } | |
5387 | |
5388 // When a delegate has specified a safe redirect URL, but it does not match the | |
5389 // redirect target, then do not prevent the reference fragment from being added. | |
5390 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { | |
5391 ASSERT_TRUE(test_server_.Start()); | |
5392 | |
5393 GURL original_url(test_server_.GetURL("original#expected-fragment")); | |
5394 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); | |
5395 GURL redirect_url(test_server_.GetURL("target")); | |
5396 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); | |
5397 | |
5398 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | |
5399 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | |
5400 | |
5401 TestDelegate d; | |
5402 { | |
5403 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | |
5404 | |
5405 r.Start(); | |
5406 base::RunLoop().Run(); | |
5407 | |
5408 EXPECT_EQ(2U, r.url_chain().size()); | |
5409 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
5410 EXPECT_EQ(net::OK, r.status().error()); | |
5411 EXPECT_EQ(original_url, r.original_url()); | |
5412 EXPECT_EQ(expected_redirect_url, r.url()); | |
5413 } | |
5414 } | |
5415 | |
5238 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 5416 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
5239 ASSERT_TRUE(test_server_.Start()); | 5417 ASSERT_TRUE(test_server_.Start()); |
5240 | 5418 |
5241 TestDelegate d; | 5419 TestDelegate d; |
5242 URLRequest req(test_server_.GetURL("echoheader?Referer"), | 5420 URLRequest req(test_server_.GetURL("echoheader?Referer"), |
5243 DEFAULT_PRIORITY, | 5421 DEFAULT_PRIORITY, |
5244 &d, | 5422 &d, |
5245 &default_context_); | 5423 &default_context_); |
5246 req.SetReferrer("http://user:pass@foo.com/"); | 5424 req.SetReferrer("http://user:pass@foo.com/"); |
5247 req.Start(); | 5425 req.Start(); |
(...skipping 2491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7739 | 7917 |
7740 EXPECT_FALSE(r.is_pending()); | 7918 EXPECT_FALSE(r.is_pending()); |
7741 EXPECT_EQ(1, d->response_started_count()); | 7919 EXPECT_EQ(1, d->response_started_count()); |
7742 EXPECT_FALSE(d->received_data_before_response()); | 7920 EXPECT_FALSE(d->received_data_before_response()); |
7743 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7921 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
7744 } | 7922 } |
7745 } | 7923 } |
7746 #endif // !defined(DISABLE_FTP_SUPPORT) | 7924 #endif // !defined(DISABLE_FTP_SUPPORT) |
7747 | 7925 |
7748 } // namespace net | 7926 } // namespace net |
OLD | NEW |