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

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

Issue 51004: Respect cookies set in a 401 responses when restarting the http transaction.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address rest of wtc's comments (had missed some in previous patchset) Created 11 years, 9 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 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/url_request/url_request_unittest.h" 5 #include "net/url_request/url_request_unittest.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #include <shlobj.h> 11 #include <shlobj.h>
12 #elif defined(OS_LINUX) 12 #elif defined(OS_LINUX)
13 #include "base/nss_init.h" 13 #include "base/nss_init.h"
14 #endif 14 #endif
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <string> 17 #include <string>
18 18
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/process_util.h" 21 #include "base/process_util.h"
22 #include "base/string_piece.h" 22 #include "base/string_piece.h"
23 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "net/base/cookie_monster.h"
24 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
25 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
26 #include "net/base/net_module.h" 27 #include "net/base/net_module.h"
27 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
28 #include "net/base/ssl_test_util.h" 29 #include "net/base/ssl_test_util.h"
29 #include "net/disk_cache/disk_cache.h" 30 #include "net/disk_cache/disk_cache.h"
30 #include "net/http/http_cache.h" 31 #include "net/http/http_cache.h"
31 #include "net/http/http_network_layer.h" 32 #include "net/http/http_network_layer.h"
32 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
33 #include "net/proxy/proxy_service.h" 34 #include "net/proxy/proxy_service.h"
34 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 #include "testing/platform_test.h" 37 #include "testing/platform_test.h"
37 38
38 using base::Time; 39 using base::Time;
39 40
40 namespace { 41 namespace {
41 42
42 class URLRequestHttpCacheContext : public URLRequestContext { 43 class URLRequestHttpCacheContext : public URLRequestContext {
43 public: 44 public:
44 URLRequestHttpCacheContext() { 45 URLRequestHttpCacheContext() {
45 proxy_service_ = net::ProxyService::CreateNull(); 46 proxy_service_ = net::ProxyService::CreateNull();
46 http_transaction_factory_ = 47 http_transaction_factory_ =
47 new net::HttpCache(net::HttpNetworkLayer::CreateFactory(proxy_service_), 48 new net::HttpCache(net::HttpNetworkLayer::CreateFactory(proxy_service_),
48 disk_cache::CreateInMemoryCacheBackend(0)); 49 disk_cache::CreateInMemoryCacheBackend(0));
50 // In-memory cookie store.
51 cookie_store_ = new net::CookieMonster();
49 } 52 }
50 53
51 virtual ~URLRequestHttpCacheContext() { 54 virtual ~URLRequestHttpCacheContext() {
55 delete cookie_store_;
52 delete http_transaction_factory_; 56 delete http_transaction_factory_;
53 delete proxy_service_; 57 delete proxy_service_;
54 } 58 }
55 }; 59 };
56 60
57 class TestURLRequest : public URLRequest { 61 class TestURLRequest : public URLRequest {
58 public: 62 public:
59 TestURLRequest(const GURL& url, Delegate* delegate) 63 TestURLRequest(const GURL& url, Delegate* delegate)
60 : URLRequest(url, delegate) { 64 : URLRequest(url, delegate) {
61 set_context(new URLRequestHttpCacheContext()); 65 set_context(new URLRequestHttpCacheContext());
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 MessageLoop::current()->Run(); 928 MessageLoop::current()->Run();
925 929
926 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 930 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
927 931
928 // Should be the same cached document, which means that the response time 932 // Should be the same cached document, which means that the response time
929 // should not have changed. 933 // should not have changed.
930 EXPECT_TRUE(response_time == r.response_time()); 934 EXPECT_TRUE(response_time == r.response_time());
931 } 935 }
932 } 936 }
933 937
938 // Check that Set-Cookie headers in 401 responses are respected.
939 // http://crbug.com/6450
940 TEST_F(URLRequestTest, BasicAuthWithCookies) {
941 scoped_refptr<HTTPTestServer> server =
942 HTTPTestServer::CreateServer(L"", NULL);
943 ASSERT_TRUE(NULL != server.get());
944
945 GURL url_requiring_auth =
946 server->TestServerPage("auth-basic?set-cookie-if-challenged");
947
948 // Request a page that will give a 401 containing a Set-Cookie header.
949 // Verify that when the transaction is restarted, it includes the new cookie.
950 {
951 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext();
952 TestDelegate d;
953 d.set_username(L"user");
954 d.set_password(L"secret");
955
956 URLRequest r(url_requiring_auth, &d);
957 r.set_context(context);
958 r.Start();
959
960 MessageLoop::current()->Run();
961
962 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
963
964 // Make sure we sent the cookie in the restarted transaction.
965 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
966 != std::string::npos);
967 }
968
969 // Same test as above, except this time the restart is initiated earlier
970 // (without user intervention since identity is embedded in the URL).
971 {
972 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext();
973 TestDelegate d;
974
975 GURL::Replacements replacements;
976 std::string username("user2");
977 std::string password("secret");
978 replacements.SetUsernameStr(username);
979 replacements.SetPasswordStr(password);
980 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements);
981
982 URLRequest r(url_with_identity, &d);
983 r.set_context(context);
984 r.Start();
985
986 MessageLoop::current()->Run();
987
988 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos);
989
990 // Make sure we sent the cookie in the restarted transaction.
991 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
992 != std::string::npos);
993 }
994 }
995
934 // In this test, we do a POST which the server will 302 redirect. 996 // In this test, we do a POST which the server will 302 redirect.
935 // The subsequent transaction should use GET, and should not send the 997 // The subsequent transaction should use GET, and should not send the
936 // Content-Type header. 998 // Content-Type header.
937 // http://code.google.com/p/chromium/issues/detail?id=843 999 // http://code.google.com/p/chromium/issues/detail?id=843
938 TEST_F(URLRequestTest, Post302RedirectGet) { 1000 TEST_F(URLRequestTest, Post302RedirectGet) {
939 scoped_refptr<HTTPTestServer> server = 1001 scoped_refptr<HTTPTestServer> server =
940 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); 1002 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL);
941 ASSERT_TRUE(NULL != server.get()); 1003 ASSERT_TRUE(NULL != server.get());
942 TestDelegate d; 1004 TestDelegate d;
943 TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d); 1005 TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1154
1093 int64 file_size = 0; 1155 int64 file_size = 0;
1094 file_util::GetFileSize(app_path, &file_size); 1156 file_util::GetFileSize(app_path, &file_size);
1095 1157
1096 EXPECT_TRUE(!r.is_pending()); 1158 EXPECT_TRUE(!r.is_pending());
1097 EXPECT_EQ(1, d.response_started_count()); 1159 EXPECT_EQ(1, d.response_started_count());
1098 EXPECT_FALSE(d.received_data_before_response()); 1160 EXPECT_FALSE(d.received_data_before_response());
1099 EXPECT_EQ(d.bytes_received(), 0); 1161 EXPECT_EQ(d.bytes_received(), 0);
1100 } 1162 }
1101 } 1163 }
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