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

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: add another test 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
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 87ad8ebe878e645cf7b60725e11b6e8014e1a900..ec79e52c63c255ff0ff5b62672c4996caf5bdf22 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -662,6 +662,25 @@ class MockCertificateReportSender
std::string latest_report_;
};
+class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate {
+ public:
+ bool OnExperimentalFeaturesEnabled() const override { return true; }
+};
+
+void CheckCookiePresence(const std::string& cookie_name,
+ const base::Closure& callback,
+ const CookieList& cookie_list) {
+ bool found = false;
+ for (const auto& cookie : cookie_list) {
+ if (cookie.Name() == cookie_name) {
+ found = true;
+ break;
+ }
+ }
+ EXPECT_TRUE(found);
+ callback.Run();
+}
+
} // namespace
// Inherit PlatformTest since we require the autorelease pool on Mac OS X.
@@ -9509,4 +9528,97 @@ TEST_F(URLRequestTest, URLRequestRedirectJobDetachRequestNoCrash) {
EXPECT_EQ(0, d.received_redirect_count());
}
+TEST_F(URLRequestTest, SecureCookiePrefix) {
+ LocalHttpTestServer test_server;
+ 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);
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("set-cookie?$Secure-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());
+ }
+
+ // Verify that the cookie is 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-not-experimental=1") !=
+ std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Try to set a non-Secure $Secure- cookie, with experimental features
+ // enabled.
+ {
+ TestExperimentalFeaturesNetworkDelegate network_delegate;
Mike West 2015/10/09 15:41:33 This is better than what I did with the FPO cookie
+ 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());
+ }
+
+ // 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. Cannot be done via a request
+ // because the request would not be secure and so the cookie would
+ // 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.
+ GURL http_url = test_server.GetURL("echoheader?Cookie");
+ GURL::Replacements replace_scheme;
+ replace_scheme.SetSchemeStr("https");
+ GURL https_url = http_url.ReplaceComponents(replace_scheme);
+ base::RunLoop run_loop;
+ default_context_.cookie_store()->GetAllCookiesForURLAsync(
+ https_url, base::Bind(&CheckCookiePresence, "$Secure-bar",
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ }
+}
+
} // namespace net
« net/url_request/url_request_test_util.cc ('K') | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698