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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 655 } |
656 | 656 |
657 const GURL& latest_report_uri() { return latest_report_uri_; } | 657 const GURL& latest_report_uri() { return latest_report_uri_; } |
658 const std::string& latest_report() { return latest_report_; } | 658 const std::string& latest_report() { return latest_report_; } |
659 | 659 |
660 private: | 660 private: |
661 GURL latest_report_uri_; | 661 GURL latest_report_uri_; |
662 std::string latest_report_; | 662 std::string latest_report_; |
663 }; | 663 }; |
664 | 664 |
665 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { | |
666 public: | |
667 bool OnExperimentalFeaturesEnabled() const override { return true; } | |
668 }; | |
669 | |
670 void CheckCookiePresence(const std::string& cookie_name, | |
671 const base::Closure& callback, | |
672 const CookieList& cookie_list) { | |
673 bool found = false; | |
674 for (const auto& cookie : cookie_list) { | |
675 if (cookie.Name() == cookie_name) { | |
676 found = true; | |
677 break; | |
678 } | |
679 } | |
680 EXPECT_TRUE(found); | |
681 callback.Run(); | |
682 } | |
683 | |
665 } // namespace | 684 } // namespace |
666 | 685 |
667 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 686 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
668 class URLRequestTest : public PlatformTest { | 687 class URLRequestTest : public PlatformTest { |
669 public: | 688 public: |
670 URLRequestTest() : default_context_(true) { | 689 URLRequestTest() : default_context_(true) { |
671 default_context_.set_network_delegate(&default_network_delegate_); | 690 default_context_.set_network_delegate(&default_network_delegate_); |
672 default_context_.set_net_log(&net_log_); | 691 default_context_.set_net_log(&net_log_); |
673 job_factory_impl_ = new URLRequestJobFactoryImpl(); | 692 job_factory_impl_ = new URLRequestJobFactoryImpl(); |
674 job_factory_.reset(job_factory_impl_); | 693 job_factory_.reset(job_factory_impl_); |
(...skipping 8827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9502 AddTestInterceptor()->set_main_intercept_job(job); | 9521 AddTestInterceptor()->set_main_intercept_job(job); |
9503 | 9522 |
9504 req->Start(); | 9523 req->Start(); |
9505 req->Cancel(); | 9524 req->Cancel(); |
9506 job->DetachRequest(); | 9525 job->DetachRequest(); |
9507 base::RunLoop().RunUntilIdle(); | 9526 base::RunLoop().RunUntilIdle(); |
9508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9527 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9509 EXPECT_EQ(0, d.received_redirect_count()); | 9528 EXPECT_EQ(0, d.received_redirect_count()); |
9510 } | 9529 } |
9511 | 9530 |
9531 TEST_F(URLRequestTest, SecureCookiePrefix) { | |
9532 LocalHttpTestServer test_server; | |
9533 ASSERT_TRUE(test_server.Start()); | |
9534 | |
9535 // Without experimental features, there should be no restrictions on | |
9536 // $Secure- cookies. | |
9537 { | |
9538 TestNetworkDelegate network_delegate; | |
9539 default_context_.set_network_delegate(&network_delegate); | |
9540 TestDelegate d; | |
9541 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9542 test_server.GetURL("set-cookie?$Secure-not-experimental=1"), | |
9543 DEFAULT_PRIORITY, &d)); | |
9544 req->Start(); | |
9545 base::RunLoop().Run(); | |
9546 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9547 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9548 } | |
9549 | |
9550 // Verify that the cookie is set. | |
9551 { | |
9552 TestNetworkDelegate network_delegate; | |
9553 default_context_.set_network_delegate(&network_delegate); | |
9554 TestDelegate d; | |
9555 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9556 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
9557 req->Start(); | |
9558 base::RunLoop().Run(); | |
9559 | |
9560 EXPECT_TRUE(d.data_received().find("$Secure-not-experimental=1") != | |
9561 std::string::npos); | |
9562 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9563 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9564 } | |
9565 | |
9566 // Try to set a non-Secure $Secure- cookie, with experimental features | |
9567 // enabled. | |
9568 { | |
9569 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
Mike West
2015/10/09 15:41:33
This is better than what I did with the FPO cookie
| |
9570 default_context_.set_network_delegate(&network_delegate); | |
9571 TestDelegate d; | |
9572 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9573 test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d)); | |
9574 req->Start(); | |
9575 base::RunLoop().Run(); | |
9576 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9577 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9578 } | |
9579 | |
9580 // Verify that the cookie is not set. | |
9581 { | |
9582 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9583 default_context_.set_network_delegate(&network_delegate); | |
9584 TestDelegate d; | |
9585 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9586 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
9587 req->Start(); | |
9588 base::RunLoop().Run(); | |
9589 | |
9590 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); | |
9591 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9592 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9593 } | |
9594 | |
9595 // Try to set a Secure $Secure- cookie, with experimental features | |
9596 // enabled. | |
9597 { | |
9598 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9599 default_context_.set_network_delegate(&network_delegate); | |
9600 TestDelegate d; | |
9601 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9602 test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY, | |
9603 &d)); | |
9604 req->Start(); | |
9605 base::RunLoop().Run(); | |
9606 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9607 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9608 | |
9609 // Verify that the cookie is set. Cannot be done via a request | |
9610 // because the request would not be secure and so the cookie would | |
9611 // not be sent. | |
Mike West
2015/10/09 15:41:33
You can spawn an HTTPS test server. Take a look at
estark
2015/10/10 05:04:02
Done.
| |
9612 GURL http_url = test_server.GetURL("echoheader?Cookie"); | |
9613 GURL::Replacements replace_scheme; | |
9614 replace_scheme.SetSchemeStr("https"); | |
9615 GURL https_url = http_url.ReplaceComponents(replace_scheme); | |
9616 base::RunLoop run_loop; | |
9617 default_context_.cookie_store()->GetAllCookiesForURLAsync( | |
9618 https_url, base::Bind(&CheckCookiePresence, "$Secure-bar", | |
9619 run_loop.QuitClosure())); | |
9620 run_loop.Run(); | |
9621 } | |
9622 } | |
9623 | |
9512 } // namespace net | 9624 } // namespace net |
OLD | NEW |