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

Unified Diff: net/url_request/url_request_unittest.cc

Issue 1393193005: Implement $Secure- cookie prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: limit prefixed cookies to secure origins Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_unittest.cc
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 41dca32bed173c4ecc06fff6571b4697375ce0c1..57c4b352ad0c0999c8abc92841ff1544b7a1949f 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -662,6 +662,11 @@ class MockCertificateReportSender
std::string latest_report_;
};
+class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate {
+ public:
+ bool OnExperimentalCookieFeaturesEnabled() const override { return true; }
+};
+
} // namespace
// Inherit PlatformTest since we require the autorelease pool on Mac OS X.
@@ -9509,4 +9514,173 @@ TEST_F(URLRequestTest, URLRequestRedirectJobDetachRequestNoCrash) {
EXPECT_EQ(0, d.received_redirect_count());
}
+TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) {
+ SpawnedTestServer test_server(
+ SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ ASSERT_TRUE(test_server.Start());
+
+ // Without experimental features, there should be no restrictions on
+ // $Secure- cookies.
+ {
+ TestNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
mmenke 2015/10/12 14:21:56 It's not a good idea to modify a context after ini
estark 2015/10/12 14:36:32 Will fix for these tests, but it looks to me like
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("set-cookie?$Secure-nonsecure-not-experimental=1"),
+ DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ {
+ TestNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL(
+ "set-cookie?$Secure-secure-not-experimental=1;Secure"),
+ DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookies are set.
+ {
+ TestNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_TRUE(d.data_received().find("$Secure-secure-not-experimental=1") !=
+ std::string::npos);
+ EXPECT_TRUE(
+ d.data_received().find("$Secure-nonsecure-not-experimental=1") !=
+ std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+}
+
+TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonSecure) {
+ SpawnedTestServer test_server(
+ SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ ASSERT_TRUE(test_server.Start());
+
+ // Try to set a non-Secure $Secure- cookie, with experimental features
+ // enabled.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookie is not set.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+}
+
+TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) {
+ SpawnedTestServer test_server(
+ SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ ASSERT_TRUE(test_server.Start());
+
+ // Try to set a Secure $Secure- cookie, with experimental features
+ // enabled.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY,
+ &d));
+ req->Start();
+ base::RunLoop().Run();
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookie is set.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+}
+
+// Tests that $Secure- cookies can't be set on non-secure origins.
+TEST_F(URLRequestTest, SecureCookiePrefixOnNonsecureOrigin) {
+ LocalHttpTestServer test_server;
+ ASSERT_TRUE(test_server.Start());
+ SpawnedTestServer test_server_https(
+ SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ ASSERT_TRUE(test_server_https.Start());
+
+ // Try to set a Secure $Secure- cookie, with experimental features
+ // enabled.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("set-cookie?$Secure-nonsecure-origin=1;Secure"),
+ DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookie is not set.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
+ default_context_.set_network_delegate(&network_delegate);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server_https.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_TRUE(d.data_received().find("$Secure-nonsecure-origin=1") ==
+ std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+}
+
} // namespace net
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698