Chromium Code Reviews| 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 OnAreExperimentalCookieFeaturesEnabled() const override { return true; } | |
| 668 }; | |
| 669 | |
| 665 } // namespace | 670 } // namespace |
| 666 | 671 |
| 667 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 672 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
| 668 class URLRequestTest : public PlatformTest { | 673 class URLRequestTest : public PlatformTest { |
| 669 public: | 674 public: |
| 670 URLRequestTest() : default_context_(true) { | 675 URLRequestTest() : default_context_(true) { |
| 671 default_context_.set_network_delegate(&default_network_delegate_); | 676 default_context_.set_network_delegate(&default_network_delegate_); |
| 672 default_context_.set_net_log(&net_log_); | 677 default_context_.set_net_log(&net_log_); |
| 673 job_factory_impl_ = new URLRequestJobFactoryImpl(); | 678 job_factory_impl_ = new URLRequestJobFactoryImpl(); |
| 674 job_factory_.reset(job_factory_impl_); | 679 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); | 9507 AddTestInterceptor()->set_main_intercept_job(job); |
| 9503 | 9508 |
| 9504 req->Start(); | 9509 req->Start(); |
| 9505 req->Cancel(); | 9510 req->Cancel(); |
| 9506 job->DetachRequest(); | 9511 job->DetachRequest(); |
| 9507 base::RunLoop().RunUntilIdle(); | 9512 base::RunLoop().RunUntilIdle(); |
| 9508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9513 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9509 EXPECT_EQ(0, d.received_redirect_count()); | 9514 EXPECT_EQ(0, d.received_redirect_count()); |
| 9510 } | 9515 } |
| 9511 | 9516 |
| 9517 TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) { | |
| 9518 SpawnedTestServer test_server( | |
| 9519 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 9520 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 9521 ASSERT_TRUE(test_server.Start()); | |
| 9522 | |
| 9523 TestNetworkDelegate network_delegate; | |
| 9524 TestURLRequestContext context(true); | |
| 9525 context.set_network_delegate(&network_delegate); | |
| 9526 context.Init(); | |
| 9527 | |
| 9528 // Without experimental features, there should be no restrictions on | |
| 9529 // $Secure- cookies. | |
| 9530 { | |
| 9531 TestDelegate d; | |
| 9532 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9533 test_server.GetURL("set-cookie?$Secure-nonsecure-not-experimental=1"), | |
| 9534 DEFAULT_PRIORITY, &d)); | |
| 9535 req->Start(); | |
| 9536 base::RunLoop().Run(); | |
| 9537 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9538 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9539 } | |
| 9540 | |
| 9541 { | |
| 9542 TestDelegate d; | |
| 9543 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9544 test_server.GetURL( | |
| 9545 "set-cookie?$Secure-secure-not-experimental=1;Secure"), | |
| 9546 DEFAULT_PRIORITY, &d)); | |
| 9547 req->Start(); | |
| 9548 base::RunLoop().Run(); | |
| 9549 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9550 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9551 } | |
| 9552 | |
| 9553 // Verify that the cookies are set. | |
| 9554 { | |
| 9555 TestDelegate d; | |
| 9556 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9557 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
| 9558 req->Start(); | |
| 9559 base::RunLoop().Run(); | |
| 9560 | |
| 9561 EXPECT_TRUE(d.data_received().find("$Secure-secure-not-experimental=1") != | |
| 9562 std::string::npos); | |
| 9563 EXPECT_TRUE( | |
| 9564 d.data_received().find("$Secure-nonsecure-not-experimental=1") != | |
| 9565 std::string::npos); | |
| 9566 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9567 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9568 } | |
| 9569 } | |
| 9570 | |
| 9571 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonSecure) { | |
|
mmenke
2015/10/15 15:58:35
nit: Be consistent about captialization.
In this
| |
| 9572 SpawnedTestServer test_server( | |
| 9573 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 9574 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 9575 ASSERT_TRUE(test_server.Start()); | |
| 9576 | |
| 9577 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
| 9578 TestURLRequestContext context(true); | |
| 9579 context.set_network_delegate(&network_delegate); | |
| 9580 context.Init(); | |
| 9581 | |
| 9582 // Try to set a non-Secure $Secure- cookie, with experimental features | |
| 9583 // enabled. | |
| 9584 { | |
| 9585 TestDelegate d; | |
| 9586 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9587 test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d)); | |
| 9588 req->Start(); | |
| 9589 base::RunLoop().Run(); | |
| 9590 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9591 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9592 } | |
| 9593 | |
| 9594 // Verify that the cookie is not set. | |
| 9595 { | |
| 9596 TestDelegate d; | |
| 9597 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9598 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
| 9599 req->Start(); | |
| 9600 base::RunLoop().Run(); | |
| 9601 | |
| 9602 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); | |
| 9603 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9604 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9605 } | |
| 9606 } | |
| 9607 | |
| 9608 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) { | |
| 9609 SpawnedTestServer test_server( | |
| 9610 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 9611 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 9612 ASSERT_TRUE(test_server.Start()); | |
| 9613 | |
| 9614 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
| 9615 TestURLRequestContext context(true); | |
| 9616 context.set_network_delegate(&network_delegate); | |
| 9617 context.Init(); | |
| 9618 | |
| 9619 // Try to set a Secure $Secure- cookie, with experimental features | |
| 9620 // enabled. | |
| 9621 { | |
| 9622 TestDelegate d; | |
| 9623 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9624 test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY, | |
| 9625 &d)); | |
| 9626 req->Start(); | |
| 9627 base::RunLoop().Run(); | |
| 9628 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9629 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9630 } | |
| 9631 | |
| 9632 // Verify that the cookie is set. | |
| 9633 { | |
| 9634 TestDelegate d; | |
| 9635 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9636 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
| 9637 req->Start(); | |
| 9638 base::RunLoop().Run(); | |
| 9639 | |
| 9640 EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos); | |
| 9641 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9642 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9643 } | |
| 9644 } | |
| 9645 | |
| 9646 // Tests that $Secure- cookies can't be set on non-secure origins. | |
| 9647 TEST_F(URLRequestTest, SecureCookiePrefixOnNonsecureOrigin) { | |
| 9648 LocalHttpTestServer test_server; | |
| 9649 ASSERT_TRUE(test_server.Start()); | |
| 9650 SpawnedTestServer test_server_https( | |
| 9651 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 9652 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 9653 ASSERT_TRUE(test_server_https.Start()); | |
| 9654 | |
| 9655 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
| 9656 TestURLRequestContext context(true); | |
| 9657 context.set_network_delegate(&network_delegate); | |
| 9658 context.Init(); | |
| 9659 | |
| 9660 // Try to set a Secure $Secure- cookie, with experimental features | |
| 9661 // enabled. | |
| 9662 { | |
| 9663 TestDelegate d; | |
| 9664 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9665 test_server.GetURL("set-cookie?$Secure-nonsecure-origin=1;Secure"), | |
| 9666 DEFAULT_PRIORITY, &d)); | |
| 9667 req->Start(); | |
| 9668 base::RunLoop().Run(); | |
| 9669 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9670 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9671 } | |
| 9672 | |
| 9673 // Verify that the cookie is not set. | |
| 9674 { | |
| 9675 TestDelegate d; | |
| 9676 scoped_ptr<URLRequest> req(context.CreateRequest( | |
| 9677 test_server_https.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
| 9678 req->Start(); | |
| 9679 base::RunLoop().Run(); | |
| 9680 | |
| 9681 EXPECT_TRUE(d.data_received().find("$Secure-nonsecure-origin=1") == | |
| 9682 std::string::npos); | |
| 9683 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
| 9684 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
| 9685 } | |
| 9686 } | |
| 9687 | |
| 9512 } // namespace net | 9688 } // namespace net |
| OLD | NEW |