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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 11339032: Account for server vs host clock skew in cookie expiration times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test on Android as there's no test server Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 1735 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
1736 == std::string::npos); 1736 == std::string::npos);
1737 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 1737 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
1738 != std::string::npos); 1738 != std::string::npos);
1739 1739
1740 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1740 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1741 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1741 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1742 } 1742 }
1743 } 1743 }
1744 1744
1745 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header
1746 // value for the |fixed_date| argument given to the constructor.
1747 class FixedDateNetworkDelegate : public TestNetworkDelegate {
1748 public:
1749 explicit FixedDateNetworkDelegate(const std::string& fixed_date)
1750 : fixed_date_(fixed_date) {}
1751 virtual ~FixedDateNetworkDelegate() {}
1752
1753 // net::NetworkDelegate implementation
1754 virtual int OnHeadersReceived(
1755 net::URLRequest* request,
1756 const net::CompletionCallback& callback,
1757 const net::HttpResponseHeaders* original_response_headers,
1758 scoped_refptr<net::HttpResponseHeaders>* override_response_headers)
1759 OVERRIDE;
1760
1761 private:
1762 std::string fixed_date_;
1763
1764 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate);
1765 };
1766
1767 int FixedDateNetworkDelegate::OnHeadersReceived(
1768 net::URLRequest* request,
1769 const net::CompletionCallback& callback,
1770 const net::HttpResponseHeaders* original_response_headers,
1771 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
1772 net::HttpResponseHeaders* new_response_headers =
1773 new net::HttpResponseHeaders(original_response_headers->raw_headers());
1774
1775 new_response_headers->RemoveHeader("Date");
1776 new_response_headers->AddHeader("Date: " + fixed_date_);
1777
1778 *override_response_headers = new_response_headers;
1779 return TestNetworkDelegate::OnHeadersReceived(request,
1780 callback,
1781 original_response_headers,
1782 override_response_headers);
1783 }
1784
1785 // Test that cookie expiration times are adjusted for server/client clock
1786 // skew and that we handle incorrect timezone specifier "UTC" in HTTP Date
1787 // headers by defaulting to GMT. (crbug.com/135131)
1788 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) {
1789 LocalHttpTestServer test_server;
1790 ASSERT_TRUE(test_server.Start());
1791
1792 // Set up an expired cookie.
1793 {
1794 TestNetworkDelegate network_delegate;
1795 default_context_.set_network_delegate(&network_delegate);
1796 TestDelegate d;
1797 URLRequest req(test_server.GetURL(
1798 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
1799 &d,
1800 &default_context_);
1801 req.Start();
1802 MessageLoop::current()->Run();
1803 }
1804 // Verify that the cookie is not set.
1805 {
1806 TestNetworkDelegate network_delegate;
1807 default_context_.set_network_delegate(&network_delegate);
1808 TestDelegate d;
1809 URLRequest req(
1810 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
1811 req.Start();
1812 MessageLoop::current()->Run();
1813
1814 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos);
1815 }
1816 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier.
1817 {
1818 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC");
1819 default_context_.set_network_delegate(&network_delegate);
1820 TestDelegate d;
1821 URLRequest req(test_server.GetURL(
1822 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
1823 &d,
1824 &default_context_);
1825 req.Start();
1826 MessageLoop::current()->Run();
1827 }
1828 // Verify that the cookie is set.
1829 {
1830 TestNetworkDelegate network_delegate;
1831 default_context_.set_network_delegate(&network_delegate);
1832 TestDelegate d;
1833 URLRequest req(
1834 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
1835 req.Start();
1836 MessageLoop::current()->Run();
1837
1838 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos);
1839 }
1840 }
1841
1842
1745 // Check that it is impossible to change the referrer in the extra headers of 1843 // Check that it is impossible to change the referrer in the extra headers of
1746 // an URLRequest. 1844 // an URLRequest.
1747 TEST_F(URLRequestTest, DoNotOverrideReferrer) { 1845 TEST_F(URLRequestTest, DoNotOverrideReferrer) {
1748 LocalHttpTestServer test_server; 1846 LocalHttpTestServer test_server;
1749 ASSERT_TRUE(test_server.Start()); 1847 ASSERT_TRUE(test_server.Start());
1750 1848
1751 // If extra headers contain referer and the request contains a referer, 1849 // If extra headers contain referer and the request contains a referer,
1752 // only the latter shall be respected. 1850 // only the latter shall be respected.
1753 { 1851 {
1754 TestDelegate d; 1852 TestDelegate d;
(...skipping 3133 matching lines...) Expand 10 before | Expand all | Expand 10 after
4888 4986
4889 EXPECT_FALSE(r.is_pending()); 4987 EXPECT_FALSE(r.is_pending());
4890 EXPECT_EQ(1, d->response_started_count()); 4988 EXPECT_EQ(1, d->response_started_count());
4891 EXPECT_FALSE(d->received_data_before_response()); 4989 EXPECT_FALSE(d->received_data_before_response());
4892 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4990 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4893 } 4991 }
4894 } 4992 }
4895 #endif // !defined(DISABLE_FTP_SUPPORT) 4993 #endif // !defined(DISABLE_FTP_SUPPORT)
4896 4994
4897 } // namespace net 4995 } // namespace net
OLDNEW
« 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