[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5 | #include <math.h> // ceil |
| 6 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8 | #include "net/base/completion_callback.h" |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9 | #include "net/base/mock_host_resolver.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 10 | #include "net/base/request_priority.h" |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 11 | #include "net/base/ssl_config_service_defaults.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 12 | #include "net/base/ssl_info.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 13 | #include "net/base/test_completion_callback.h" |
| 14 | #include "net/base/upload_data.h" |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 15 | #include "net/flip/flip_session_pool.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 16 | #include "net/http/http_auth_handler_ntlm.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 17 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 18 | #include "net/http/http_network_session.h" |
| 19 | #include "net/http/http_network_transaction.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 20 | #include "net/http/http_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 21 | #include "net/http/http_transaction_unittest.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 22 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 23 | #include "net/socket/client_socket_factory.h" |
| 24 | #include "net/socket/socket_test_util.h" |
| 25 | #include "net/socket/ssl_client_socket.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 26 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 27 | #include "testing/platform_test.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 28 | |
| 29 | //----------------------------------------------------------------------------- |
| 30 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 31 | namespace net { |
| 32 | |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 33 | // Create a proxy service which fails on all requests (falls back to direct). |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 34 | ProxyService* CreateNullProxyService() { |
| 35 | return ProxyService::CreateNull(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | } |
| 37 | |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 38 | // Helper to manage the lifetimes of the dependencies for a |
| 39 | // HttpNetworkTransaction. |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 40 | class SessionDependencies { |
| 41 | public: |
| 42 | // Default set of dependencies -- "null" proxy service. |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 43 | SessionDependencies() |
| 44 | : host_resolver(new MockHostResolver), |
| 45 | proxy_service(CreateNullProxyService()), |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 46 | ssl_config_service(new SSLConfigServiceDefaults), |
| 47 | flip_session_pool(new FlipSessionPool) {} |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 48 | |
| 49 | // Custom proxy service dependency. |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 50 | explicit SessionDependencies(ProxyService* proxy_service) |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 51 | : host_resolver(new MockHostResolver), |
| 52 | proxy_service(proxy_service), |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 53 | ssl_config_service(new SSLConfigServiceDefaults), |
| 54 | flip_session_pool(new FlipSessionPool) {} |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 55 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 56 | scoped_refptr<MockHostResolverBase> host_resolver; |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 57 | scoped_refptr<ProxyService> proxy_service; |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 58 | scoped_refptr<SSLConfigService> ssl_config_service; |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 59 | MockClientSocketFactory socket_factory; |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 60 | scoped_refptr<FlipSessionPool> flip_session_pool; |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 61 | }; |
| 62 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 63 | ProxyService* CreateFixedProxyService(const std::string& proxy) { |
[email protected] | ab501a6a | 2009-05-12 15:07:50 | [diff] [blame] | 64 | net::ProxyConfig proxy_config; |
| 65 | proxy_config.proxy_rules.ParseFromString(proxy); |
[email protected] | 3e44697f | 2009-05-22 14:37:39 | [diff] [blame] | 66 | return ProxyService::CreateFixed(proxy_config); |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 70 | HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { |
[email protected] | 94a0d3d9 | 2009-06-27 01:50:14 | [diff] [blame] | 71 | return new HttpNetworkSession(session_deps->host_resolver, |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 72 | session_deps->proxy_service, |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 73 | &session_deps->socket_factory, |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 74 | session_deps->ssl_config_service, |
| 75 | session_deps->flip_session_pool); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | 89836e2 | 2008-09-25 20:33:42 | [diff] [blame] | 78 | class HttpNetworkTransactionTest : public PlatformTest { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 79 | public: |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 80 | virtual void TearDown() { |
| 81 | // Empty the current queue. |
| 82 | MessageLoop::current()->RunAllPending(); |
| 83 | PlatformTest::TearDown(); |
| 84 | } |
| 85 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 86 | protected: |
| 87 | void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 89 | struct SimpleGetHelperResult { |
| 90 | int rv; |
| 91 | std::string status_line; |
| 92 | std::string response_data; |
| 93 | }; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 94 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 95 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { |
| 96 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 97 | |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 98 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 99 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 100 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 101 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 102 | HttpRequestInfo request; |
| 103 | request.method = "GET"; |
| 104 | request.url = GURL("http://www.google.com/"); |
| 105 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 106 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 107 | StaticSocketDataProvider data(data_reads, NULL); |
| 108 | session_deps.socket_factory.AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 109 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 110 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 111 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 112 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 113 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 114 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 115 | out.rv = callback.WaitForResult(); |
| 116 | if (out.rv != OK) |
| 117 | return out; |
| 118 | |
| 119 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 120 | EXPECT_TRUE(response != NULL); |
| 121 | |
| 122 | EXPECT_TRUE(response->headers != NULL); |
| 123 | out.status_line = response->headers->GetStatusLine(); |
| 124 | |
| 125 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 126 | EXPECT_EQ(OK, rv); |
| 127 | |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 128 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 129 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 130 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 131 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 132 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 133 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 134 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 135 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 136 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 137 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 138 | void FillLargeHeadersString(std::string* str, int size) { |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 139 | const char* row = |
| 140 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 141 | const int sizeof_row = strlen(row); |
| 142 | const int num_rows = static_cast<int>( |
| 143 | ceil(static_cast<float>(size) / sizeof_row)); |
| 144 | const int sizeof_data = num_rows * sizeof_row; |
| 145 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 146 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 147 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 148 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 149 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 152 | // Alternative functions that eliminate randomness and dependency on the local |
| 153 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 154 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 155 | static const uint8 bytes[] = { |
| 156 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 157 | }; |
| 158 | static size_t current_byte = 0; |
| 159 | for (size_t i = 0; i < n; ++i) { |
| 160 | output[i] = bytes[current_byte++]; |
| 161 | current_byte %= arraysize(bytes); |
| 162 | } |
| 163 | } |
| 164 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 165 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 166 | static const uint8 bytes[] = { |
| 167 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 168 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 169 | }; |
| 170 | static size_t current_byte = 0; |
| 171 | for (size_t i = 0; i < n; ++i) { |
| 172 | output[i] = bytes[current_byte++]; |
| 173 | current_byte %= arraysize(bytes); |
| 174 | } |
| 175 | } |
| 176 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 177 | std::string MockGetHostName() { |
| 178 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 181 | class CaptureGroupNameSocketPool : public TCPClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 182 | public: |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 183 | CaptureGroupNameSocketPool() : TCPClientSocketPool(0, 0, NULL, NULL) {} |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 184 | const std::string last_group_name_received() const { |
| 185 | return last_group_name_; |
| 186 | } |
| 187 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 188 | virtual int RequestSocket(const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 189 | const void* socket_params, |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 190 | RequestPriority priority, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 191 | ClientSocketHandle* handle, |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 192 | CompletionCallback* callback, |
| 193 | LoadLog* load_log) { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 194 | last_group_name_ = group_name; |
| 195 | return ERR_IO_PENDING; |
| 196 | } |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 197 | virtual void CancelRequest(const std::string& group_name, |
| 198 | const ClientSocketHandle* handle) { } |
| 199 | virtual void ReleaseSocket(const std::string& group_name, |
| 200 | ClientSocket* socket) {} |
| 201 | virtual void CloseIdleSockets() {} |
| 202 | virtual HostResolver* GetHostResolver() const { |
| 203 | return NULL; |
| 204 | } |
| 205 | virtual int IdleSocketCount() const { |
| 206 | return 0; |
| 207 | } |
| 208 | virtual int IdleSocketCountInGroup(const std::string& group_name) const { |
| 209 | return 0; |
| 210 | } |
| 211 | virtual LoadState GetLoadState(const std::string& group_name, |
| 212 | const ClientSocketHandle* handle) const { |
| 213 | return LOAD_STATE_IDLE; |
| 214 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 215 | |
| 216 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 217 | std::string last_group_name_; |
| 218 | }; |
| 219 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 220 | //----------------------------------------------------------------------------- |
| 221 | |
| 222 | TEST_F(HttpNetworkTransactionTest, Basic) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 223 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 224 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 225 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
| 229 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 230 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 231 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 232 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 233 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 234 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 235 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 236 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 237 | EXPECT_EQ("hello world", out.response_data); |
| 238 | } |
| 239 | |
| 240 | // Response with no status line. |
| 241 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
| 242 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 243 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 244 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 245 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 246 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 247 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 248 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 249 | EXPECT_EQ("hello world", out.response_data); |
| 250 | } |
| 251 | |
| 252 | // Allow up to 4 bytes of junk to precede status line. |
| 253 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk2Bytes) { |
| 254 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 255 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 256 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 257 | }; |
| 258 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 259 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 260 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 261 | EXPECT_EQ("DATA", out.response_data); |
| 262 | } |
| 263 | |
| 264 | // Allow up to 4 bytes of junk to precede status line. |
| 265 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
| 266 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 267 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 268 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 269 | }; |
| 270 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 271 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 272 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 273 | EXPECT_EQ("DATA", out.response_data); |
| 274 | } |
| 275 | |
| 276 | // Beyond 4 bytes of slop and it should fail to find a status line. |
| 277 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
| 278 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 279 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 280 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 281 | }; |
| 282 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 283 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 284 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 285 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
| 289 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
| 290 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 291 | MockRead("\n"), |
| 292 | MockRead("\n"), |
| 293 | MockRead("Q"), |
| 294 | MockRead("J"), |
| 295 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 296 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 297 | }; |
| 298 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 299 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 300 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 301 | EXPECT_EQ("DATA", out.response_data); |
| 302 | } |
| 303 | |
| 304 | // Close the connection before enough bytes to have a status line. |
| 305 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
| 306 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 307 | MockRead("HTT"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 308 | MockRead(false, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 309 | }; |
| 310 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 311 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 312 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 313 | EXPECT_EQ("HTT", out.response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 314 | } |
| 315 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 316 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 317 | // persistent connection. The response should still terminate since a 204 |
| 318 | // cannot have a response body. |
| 319 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
| 320 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 321 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 322 | MockRead("junk"), // Should not be read!! |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 323 | MockRead(false, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 324 | }; |
| 325 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 326 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 327 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 328 | EXPECT_EQ("", out.response_data); |
| 329 | } |
| 330 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 331 | // A simple request using chunked encoding with some extra data after. |
| 332 | // (Like might be seen in a pipelined response.) |
| 333 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
| 334 | MockRead data_reads[] = { |
| 335 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 336 | MockRead("5\r\nHello\r\n"), |
| 337 | MockRead("1\r\n"), |
| 338 | MockRead(" \r\n"), |
| 339 | MockRead("5\r\nworld\r\n"), |
| 340 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
| 341 | MockRead(false, OK), |
| 342 | }; |
| 343 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
| 344 | EXPECT_EQ(OK, out.rv); |
| 345 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 346 | EXPECT_EQ("Hello world", out.response_data); |
| 347 | } |
| 348 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 349 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 350 | // message body (since HEAD has none). |
| 351 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 352 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 353 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 354 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 355 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 356 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 357 | request.method = "HEAD"; |
| 358 | request.url = GURL("http://www.google.com/"); |
| 359 | request.load_flags = 0; |
| 360 | |
| 361 | MockWrite data_writes1[] = { |
| 362 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 363 | "Host: www.google.com\r\n" |
| 364 | "Connection: keep-alive\r\n" |
| 365 | "Content-Length: 0\r\n\r\n"), |
| 366 | }; |
| 367 | MockRead data_reads1[] = { |
| 368 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 369 | MockRead("Server: Blah\r\n"), |
| 370 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 371 | |
| 372 | // No response body because the test stops reading here. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 373 | MockRead(false, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 374 | }; |
| 375 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 376 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 377 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 378 | |
| 379 | TestCompletionCallback callback1; |
| 380 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 381 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 382 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 383 | |
| 384 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 385 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 386 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 387 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 388 | EXPECT_FALSE(response == NULL); |
| 389 | |
| 390 | // Check that the headers got parsed. |
| 391 | EXPECT_TRUE(response->headers != NULL); |
| 392 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 393 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
| 394 | |
| 395 | std::string server_header; |
| 396 | void* iter = NULL; |
| 397 | bool has_server_header = response->headers->EnumerateHeader( |
| 398 | &iter, "Server", &server_header); |
| 399 | EXPECT_TRUE(has_server_header); |
| 400 | EXPECT_EQ("Blah", server_header); |
| 401 | |
| 402 | // Reading should give EOF right away, since there is no message body |
| 403 | // (despite non-zero content-length). |
| 404 | std::string response_data; |
| 405 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 406 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 407 | EXPECT_EQ("", response_data); |
| 408 | } |
| 409 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 410 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 411 | SessionDependencies session_deps; |
| 412 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 413 | |
| 414 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 415 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 416 | MockRead("hello"), |
| 417 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 418 | MockRead("world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 419 | MockRead(false, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 420 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 421 | StaticSocketDataProvider data(data_reads, NULL); |
| 422 | session_deps.socket_factory.AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 423 | |
| 424 | const char* kExpectedResponseData[] = { |
| 425 | "hello", "world" |
| 426 | }; |
| 427 | |
| 428 | for (int i = 0; i < 2; ++i) { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 429 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 430 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 431 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 432 | request.method = "GET"; |
| 433 | request.url = GURL("http://www.google.com/"); |
| 434 | request.load_flags = 0; |
| 435 | |
| 436 | TestCompletionCallback callback; |
| 437 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 438 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 440 | |
| 441 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 442 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 443 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 444 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 445 | EXPECT_TRUE(response != NULL); |
| 446 | |
| 447 | EXPECT_TRUE(response->headers != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 448 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 449 | |
| 450 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 451 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 452 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 453 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
| 457 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 458 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 459 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 460 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 462 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | request.method = "POST"; |
| 464 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 465 | request.upload_data = new UploadData; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 466 | request.upload_data->AppendBytes("foo", 3); |
| 467 | request.load_flags = 0; |
| 468 | |
| 469 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 470 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 471 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 472 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 473 | MockRead(false, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 475 | StaticSocketDataProvider data(data_reads, NULL); |
| 476 | session_deps.socket_factory.AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 477 | |
| 478 | TestCompletionCallback callback; |
| 479 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 480 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 482 | |
| 483 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 484 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 485 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 487 | EXPECT_TRUE(response != NULL); |
| 488 | |
| 489 | EXPECT_TRUE(response->headers != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 490 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 491 | |
| 492 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 493 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 494 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 495 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 496 | } |
| 497 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 498 | // This test is almost the same as Ignores100 above, but the response contains |
| 499 | // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 500 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 501 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 502 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 503 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 504 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 505 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 506 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 507 | request.method = "GET"; |
| 508 | request.url = GURL("http://www.foo.com/"); |
| 509 | request.load_flags = 0; |
| 510 | |
| 511 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 512 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 513 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 514 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 515 | MockRead(false, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 516 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 517 | StaticSocketDataProvider data(data_reads, NULL); |
| 518 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 519 | |
| 520 | TestCompletionCallback callback; |
| 521 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 522 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 523 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 524 | |
| 525 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 526 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 527 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 528 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 529 | EXPECT_TRUE(response != NULL); |
| 530 | |
| 531 | EXPECT_TRUE(response->headers != NULL); |
| 532 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 533 | |
| 534 | std::string response_data; |
| 535 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 536 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 537 | EXPECT_EQ("hello world", response_data); |
| 538 | } |
| 539 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 540 | // read_failure specifies a read failure that should cause the network |
| 541 | // transaction to resend the request. |
| 542 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
| 543 | const MockRead& read_failure) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 544 | SessionDependencies session_deps; |
| 545 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 546 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 547 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 548 | request.method = "GET"; |
| 549 | request.url = GURL("http://www.foo.com/"); |
| 550 | request.load_flags = 0; |
| 551 | |
| 552 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 553 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 554 | MockRead("hello"), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 555 | read_failure, // Now, we reuse the connection and fail the first read. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 556 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 557 | StaticSocketDataProvider data1(data1_reads, NULL); |
| 558 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 559 | |
| 560 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 561 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 562 | MockRead("world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 563 | MockRead(true, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 564 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 565 | StaticSocketDataProvider data2(data2_reads, NULL); |
| 566 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 567 | |
| 568 | const char* kExpectedResponseData[] = { |
| 569 | "hello", "world" |
| 570 | }; |
| 571 | |
| 572 | for (int i = 0; i < 2; ++i) { |
| 573 | TestCompletionCallback callback; |
| 574 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 575 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 576 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 577 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 578 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 579 | |
| 580 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 581 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 582 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 583 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 584 | EXPECT_TRUE(response != NULL); |
| 585 | |
| 586 | EXPECT_TRUE(response->headers != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 587 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 588 | |
| 589 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 590 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 591 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 592 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 593 | } |
| 594 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 595 | |
| 596 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 597 | MockRead read_failure(true, ERR_CONNECTION_RESET); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 598 | KeepAliveConnectionResendRequestTest(read_failure); |
| 599 | } |
| 600 | |
| 601 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 602 | MockRead read_failure(false, OK); // EOF |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 603 | KeepAliveConnectionResendRequestTest(read_failure); |
| 604 | } |
| 605 | |
| 606 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 607 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 608 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 609 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 610 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 611 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 612 | request.method = "GET"; |
| 613 | request.url = GURL("http://www.google.com/"); |
| 614 | request.load_flags = 0; |
| 615 | |
| 616 | MockRead data_reads[] = { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 617 | MockRead(true, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 618 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 619 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 620 | MockRead(false, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 621 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 622 | StaticSocketDataProvider data(data_reads, NULL); |
| 623 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 624 | |
| 625 | TestCompletionCallback callback; |
| 626 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 627 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 628 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 629 | |
| 630 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 631 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 632 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 633 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 634 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | // What do various browsers do when the server closes a non-keepalive |
| 638 | // connection without sending any response header or body? |
| 639 | // |
| 640 | // IE7: error page |
| 641 | // Safari 3.1.2 (Windows): error page |
| 642 | // Firefox 3.0.1: blank page |
| 643 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 644 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 645 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 646 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
| 647 | MockRead data_reads[] = { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 648 | MockRead(false, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 649 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 650 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 651 | MockRead(false, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 652 | }; |
| 653 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 654 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 655 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 656 | |
| 657 | // Test the request-challenge-retry sequence for basic auth. |
| 658 | // (basic auth is the easiest to mock, because it has no randomness). |
| 659 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 660 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 661 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 662 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 663 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 664 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 665 | request.method = "GET"; |
| 666 | request.url = GURL("http://www.google.com/"); |
| 667 | request.load_flags = 0; |
| 668 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 669 | MockWrite data_writes1[] = { |
| 670 | MockWrite("GET / HTTP/1.1\r\n" |
| 671 | "Host: www.google.com\r\n" |
| 672 | "Connection: keep-alive\r\n\r\n"), |
| 673 | }; |
| 674 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 675 | MockRead data_reads1[] = { |
| 676 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 677 | // Give a couple authenticate options (only the middle one is actually |
| 678 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 679 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 680 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 681 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 682 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 683 | // Large content-length -- won't matter, as connection will be reset. |
| 684 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 685 | MockRead(false, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | // After calling trans->RestartWithAuth(), this is the request we should |
| 689 | // be issuing -- the final header line contains the credentials. |
| 690 | MockWrite data_writes2[] = { |
| 691 | MockWrite("GET / HTTP/1.1\r\n" |
| 692 | "Host: www.google.com\r\n" |
| 693 | "Connection: keep-alive\r\n" |
| 694 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 695 | }; |
| 696 | |
| 697 | // Lastly, the server responds with the actual content. |
| 698 | MockRead data_reads2[] = { |
| 699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 702 | MockRead(false, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 703 | }; |
| 704 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 705 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 706 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 707 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 708 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 709 | |
| 710 | TestCompletionCallback callback1; |
| 711 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 712 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 713 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 714 | |
| 715 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 716 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 717 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 718 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 719 | EXPECT_FALSE(response == NULL); |
| 720 | |
| 721 | // The password prompt info should have been set in response->auth_challenge. |
| 722 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 723 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 724 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 725 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 726 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 727 | |
| 728 | TestCompletionCallback callback2; |
| 729 | |
| 730 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 732 | |
| 733 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 734 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 735 | |
| 736 | response = trans->GetResponseInfo(); |
| 737 | EXPECT_FALSE(response == NULL); |
| 738 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 739 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 740 | } |
| 741 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 742 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
| 743 | SessionDependencies session_deps; |
| 744 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 745 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 746 | |
| 747 | HttpRequestInfo request; |
| 748 | request.method = "GET"; |
| 749 | request.url = GURL("http://www.google.com/"); |
| 750 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 751 | |
| 752 | MockWrite data_writes[] = { |
| 753 | MockWrite("GET / HTTP/1.1\r\n" |
| 754 | "Host: www.google.com\r\n" |
| 755 | "Connection: keep-alive\r\n\r\n"), |
| 756 | }; |
| 757 | |
| 758 | MockRead data_reads[] = { |
| 759 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 760 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 761 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 762 | // Large content-length -- won't matter, as connection will be reset. |
| 763 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 764 | MockRead(false, ERR_FAILED), |
| 765 | }; |
| 766 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 767 | StaticSocketDataProvider data(data_reads, data_writes); |
| 768 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 769 | TestCompletionCallback callback; |
| 770 | |
| 771 | int rv = trans->Start(&request, &callback, NULL); |
| 772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 773 | |
| 774 | rv = callback.WaitForResult(); |
| 775 | EXPECT_EQ(0, rv); |
| 776 | |
| 777 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 778 | ASSERT_FALSE(response == NULL); |
| 779 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 780 | } |
| 781 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 782 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 783 | // connection. |
| 784 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 785 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 786 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 787 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 788 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 789 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 790 | request.method = "GET"; |
| 791 | request.url = GURL("http://www.google.com/"); |
| 792 | request.load_flags = 0; |
| 793 | |
| 794 | MockWrite data_writes1[] = { |
| 795 | MockWrite("GET / HTTP/1.1\r\n" |
| 796 | "Host: www.google.com\r\n" |
| 797 | "Connection: keep-alive\r\n\r\n"), |
| 798 | |
| 799 | // After calling trans->RestartWithAuth(), this is the request we should |
| 800 | // be issuing -- the final header line contains the credentials. |
| 801 | MockWrite("GET / HTTP/1.1\r\n" |
| 802 | "Host: www.google.com\r\n" |
| 803 | "Connection: keep-alive\r\n" |
| 804 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 805 | }; |
| 806 | |
| 807 | MockRead data_reads1[] = { |
| 808 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 809 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 810 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 811 | MockRead("Content-Length: 14\r\n\r\n"), |
| 812 | MockRead("Unauthorized\r\n"), |
| 813 | |
| 814 | // Lastly, the server responds with the actual content. |
| 815 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 817 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 818 | MockRead(false, OK), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 819 | }; |
| 820 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 821 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 822 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 823 | |
| 824 | TestCompletionCallback callback1; |
| 825 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 826 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 827 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 828 | |
| 829 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 830 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 831 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 832 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 833 | EXPECT_FALSE(response == NULL); |
| 834 | |
| 835 | // The password prompt info should have been set in response->auth_challenge. |
| 836 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 837 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 838 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 839 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 840 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 841 | |
| 842 | TestCompletionCallback callback2; |
| 843 | |
| 844 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 846 | |
| 847 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 848 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 849 | |
| 850 | response = trans->GetResponseInfo(); |
| 851 | EXPECT_FALSE(response == NULL); |
| 852 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 853 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 854 | } |
| 855 | |
| 856 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 857 | // connection and with no response body to drain. |
| 858 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 859 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 861 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 862 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 863 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 864 | request.method = "GET"; |
| 865 | request.url = GURL("http://www.google.com/"); |
| 866 | request.load_flags = 0; |
| 867 | |
| 868 | MockWrite data_writes1[] = { |
| 869 | MockWrite("GET / HTTP/1.1\r\n" |
| 870 | "Host: www.google.com\r\n" |
| 871 | "Connection: keep-alive\r\n\r\n"), |
| 872 | |
| 873 | // After calling trans->RestartWithAuth(), this is the request we should |
| 874 | // be issuing -- the final header line contains the credentials. |
| 875 | MockWrite("GET / HTTP/1.1\r\n" |
| 876 | "Host: www.google.com\r\n" |
| 877 | "Connection: keep-alive\r\n" |
| 878 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 879 | }; |
| 880 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 881 | MockRead data_reads1[] = { |
| 882 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 883 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 884 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 885 | |
| 886 | // Lastly, the server responds with the actual content. |
| 887 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 888 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 889 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 890 | MockRead(false, OK), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 891 | }; |
| 892 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 893 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 894 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 895 | |
| 896 | TestCompletionCallback callback1; |
| 897 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 898 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 900 | |
| 901 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 902 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 903 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 904 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 905 | EXPECT_FALSE(response == NULL); |
| 906 | |
| 907 | // The password prompt info should have been set in response->auth_challenge. |
| 908 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 909 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 910 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 911 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 912 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 913 | |
| 914 | TestCompletionCallback callback2; |
| 915 | |
| 916 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 918 | |
| 919 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 920 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 921 | |
| 922 | response = trans->GetResponseInfo(); |
| 923 | EXPECT_FALSE(response == NULL); |
| 924 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 925 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 926 | } |
| 927 | |
| 928 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 929 | // connection and with a large response body to drain. |
| 930 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 931 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 932 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 933 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 934 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 935 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 936 | request.method = "GET"; |
| 937 | request.url = GURL("http://www.google.com/"); |
| 938 | request.load_flags = 0; |
| 939 | |
| 940 | MockWrite data_writes1[] = { |
| 941 | MockWrite("GET / HTTP/1.1\r\n" |
| 942 | "Host: www.google.com\r\n" |
| 943 | "Connection: keep-alive\r\n\r\n"), |
| 944 | |
| 945 | // After calling trans->RestartWithAuth(), this is the request we should |
| 946 | // be issuing -- the final header line contains the credentials. |
| 947 | MockWrite("GET / HTTP/1.1\r\n" |
| 948 | "Host: www.google.com\r\n" |
| 949 | "Connection: keep-alive\r\n" |
| 950 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 951 | }; |
| 952 | |
| 953 | // Respond with 5 kb of response body. |
| 954 | std::string large_body_string("Unauthorized"); |
| 955 | large_body_string.append(5 * 1024, ' '); |
| 956 | large_body_string.append("\r\n"); |
| 957 | |
| 958 | MockRead data_reads1[] = { |
| 959 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 960 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 961 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 962 | // 5134 = 12 + 5 * 1024 + 2 |
| 963 | MockRead("Content-Length: 5134\r\n\r\n"), |
| 964 | MockRead(true, large_body_string.data(), large_body_string.size()), |
| 965 | |
| 966 | // Lastly, the server responds with the actual content. |
| 967 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 968 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 969 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 970 | MockRead(false, OK), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 971 | }; |
| 972 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 973 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 974 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 975 | |
| 976 | TestCompletionCallback callback1; |
| 977 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 978 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 979 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 980 | |
| 981 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 982 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 983 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 984 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 985 | EXPECT_FALSE(response == NULL); |
| 986 | |
| 987 | // The password prompt info should have been set in response->auth_challenge. |
| 988 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 989 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 990 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 991 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 992 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 993 | |
| 994 | TestCompletionCallback callback2; |
| 995 | |
| 996 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 998 | |
| 999 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1000 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1001 | |
| 1002 | response = trans->GetResponseInfo(); |
| 1003 | EXPECT_FALSE(response == NULL); |
| 1004 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1005 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 1006 | } |
| 1007 | |
| 1008 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1009 | // connection, but the server gets impatient and closes the connection. |
| 1010 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
| 1011 | SessionDependencies session_deps; |
| 1012 | scoped_ptr<HttpTransaction> trans( |
| 1013 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 1014 | |
| 1015 | HttpRequestInfo request; |
| 1016 | request.method = "GET"; |
| 1017 | request.url = GURL("http://www.google.com/"); |
| 1018 | request.load_flags = 0; |
| 1019 | |
| 1020 | MockWrite data_writes1[] = { |
| 1021 | MockWrite("GET / HTTP/1.1\r\n" |
| 1022 | "Host: www.google.com\r\n" |
| 1023 | "Connection: keep-alive\r\n\r\n"), |
| 1024 | // This simulates the seemingly successful write to a closed connection |
| 1025 | // if the bug is not fixed. |
| 1026 | MockWrite("GET / HTTP/1.1\r\n" |
| 1027 | "Host: www.google.com\r\n" |
| 1028 | "Connection: keep-alive\r\n" |
| 1029 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1030 | }; |
| 1031 | |
| 1032 | MockRead data_reads1[] = { |
| 1033 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1034 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1035 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1036 | MockRead("Content-Length: 14\r\n\r\n"), |
| 1037 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
| 1038 | MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1039 | MockRead("Unauthorized\r\n"), |
| 1040 | MockRead(false, OK), // The server closes the connection. |
| 1041 | }; |
| 1042 | |
| 1043 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1044 | // be issuing -- the final header line contains the credentials. |
| 1045 | MockWrite data_writes2[] = { |
| 1046 | MockWrite("GET / HTTP/1.1\r\n" |
| 1047 | "Host: www.google.com\r\n" |
| 1048 | "Connection: keep-alive\r\n" |
| 1049 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1050 | }; |
| 1051 | |
| 1052 | // Lastly, the server responds with the actual content. |
| 1053 | MockRead data_reads2[] = { |
| 1054 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1055 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1056 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1057 | MockRead(false, OK), |
| 1058 | }; |
| 1059 | |
| 1060 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1061 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 1062 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1063 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
| 1064 | |
| 1065 | TestCompletionCallback callback1; |
| 1066 | |
| 1067 | int rv = trans->Start(&request, &callback1, NULL); |
| 1068 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1069 | |
| 1070 | rv = callback1.WaitForResult(); |
| 1071 | EXPECT_EQ(OK, rv); |
| 1072 | |
| 1073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1074 | EXPECT_FALSE(response == NULL); |
| 1075 | |
| 1076 | // The password prompt info should have been set in response->auth_challenge. |
| 1077 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1078 | |
| 1079 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
| 1080 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 1081 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 1082 | |
| 1083 | TestCompletionCallback callback2; |
| 1084 | |
| 1085 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
| 1086 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1087 | |
| 1088 | rv = callback2.WaitForResult(); |
| 1089 | EXPECT_EQ(OK, rv); |
| 1090 | |
| 1091 | response = trans->GetResponseInfo(); |
| 1092 | ASSERT_FALSE(response == NULL); |
| 1093 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1094 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 1095 | } |
| 1096 | |
| 1097 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1098 | // proxy connection, when setting up an SSL tunnel. |
| 1099 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
| 1100 | // Configure against proxy server "myproxy:70". |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1101 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
| 1102 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1103 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1104 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1105 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1106 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1107 | request.method = "GET"; |
| 1108 | request.url = GURL("https://www.google.com/"); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1109 | // Ensure that proxy authentication is attempted even |
| 1110 | // when the no authentication data flag is set. |
| 1111 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1112 | |
| 1113 | // Since we have proxy, should try to establish tunnel. |
| 1114 | MockWrite data_writes1[] = { |
| 1115 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1116 | "Host: www.google.com\r\n" |
| 1117 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1118 | |
| 1119 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1120 | // be issuing -- the final header line contains the credentials. |
| 1121 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1122 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1123 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1124 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 1125 | }; |
| 1126 | |
| 1127 | // The proxy responds to the connect with a 407, using a persistent |
| 1128 | // connection. |
| 1129 | MockRead data_reads1[] = { |
| 1130 | // No credentials. |
| 1131 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 1132 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1133 | MockRead("Content-Length: 10\r\n\r\n"), |
| 1134 | MockRead("0123456789"), |
| 1135 | |
| 1136 | // Wrong credentials (wrong password). |
| 1137 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 1138 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1139 | MockRead("Content-Length: 10\r\n\r\n"), |
| 1140 | // No response body because the test stops reading here. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1141 | MockRead(false, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1142 | }; |
| 1143 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1144 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1145 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1146 | |
| 1147 | TestCompletionCallback callback1; |
| 1148 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1149 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1150 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1151 | |
| 1152 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1153 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1154 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1156 | EXPECT_FALSE(response == NULL); |
| 1157 | |
| 1158 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 1159 | EXPECT_EQ(407, response->headers->response_code()); |
| 1160 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1161 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1162 | |
| 1163 | // The password prompt info should have been set in response->auth_challenge. |
| 1164 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1165 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1166 | EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1167 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 1168 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 1169 | |
| 1170 | TestCompletionCallback callback2; |
| 1171 | |
| 1172 | // Wrong password (should be "bar"). |
| 1173 | rv = trans->RestartWithAuth(L"foo", L"baz", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1175 | |
| 1176 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1178 | |
| 1179 | response = trans->GetResponseInfo(); |
| 1180 | EXPECT_FALSE(response == NULL); |
| 1181 | |
| 1182 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 1183 | EXPECT_EQ(407, response->headers->response_code()); |
| 1184 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1185 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1186 | |
| 1187 | // The password prompt info should have been set in response->auth_challenge. |
| 1188 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1189 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1190 | EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1191 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 1192 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 1193 | } |
| 1194 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1195 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 1196 | // even if the user cancels the proxy's auth attempt. |
| 1197 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
| 1198 | // Configure against proxy server "myproxy:70". |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1199 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1200 | |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1201 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1202 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1203 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1204 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1205 | HttpRequestInfo request; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1206 | request.method = "GET"; |
| 1207 | request.url = GURL("https://www.google.com/"); |
| 1208 | request.load_flags = 0; |
| 1209 | |
| 1210 | // Since we have proxy, should try to establish tunnel. |
| 1211 | MockWrite data_writes[] = { |
| 1212 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1213 | "Host: www.google.com\r\n" |
| 1214 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1215 | }; |
| 1216 | |
| 1217 | // The proxy responds to the connect with a 407. |
| 1218 | MockRead data_reads[] = { |
| 1219 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 1220 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1221 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1222 | MockRead(false, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1223 | }; |
| 1224 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1225 | StaticSocketDataProvider data(data_reads, data_writes); |
| 1226 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1227 | |
| 1228 | TestCompletionCallback callback; |
| 1229 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1230 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1232 | |
| 1233 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1234 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1235 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1236 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1237 | EXPECT_FALSE(response == NULL); |
| 1238 | |
| 1239 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 1240 | EXPECT_EQ(407, response->headers->response_code()); |
| 1241 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1242 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1243 | |
| 1244 | std::string response_data; |
| 1245 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1246 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 1247 | } |
| 1248 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 1249 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1250 | const MockRead& status, int expected_status) { |
| 1251 | // Configure against proxy server "myproxy:70". |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1252 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1253 | |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1254 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1255 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1256 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1257 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1258 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1259 | request.method = "GET"; |
| 1260 | request.url = GURL("https://www.google.com/"); |
| 1261 | request.load_flags = 0; |
| 1262 | |
| 1263 | // Since we have proxy, should try to establish tunnel. |
| 1264 | MockWrite data_writes[] = { |
| 1265 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1266 | "Host: www.google.com\r\n" |
| 1267 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1268 | }; |
| 1269 | |
| 1270 | MockRead data_reads[] = { |
| 1271 | status, |
| 1272 | MockRead("Content-Length: 10\r\n\r\n"), |
| 1273 | // No response body because the test stops reading here. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1274 | MockRead(false, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1275 | }; |
| 1276 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1277 | StaticSocketDataProvider data(data_reads, data_writes); |
| 1278 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1279 | |
| 1280 | TestCompletionCallback callback; |
| 1281 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1282 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1283 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1284 | |
| 1285 | rv = callback.WaitForResult(); |
| 1286 | EXPECT_EQ(expected_status, rv); |
| 1287 | } |
| 1288 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 1289 | void HttpNetworkTransactionTest::ConnectStatusHelper(const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1290 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1291 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
| 1295 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 1296 | } |
| 1297 | |
| 1298 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
| 1299 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 1300 | } |
| 1301 | |
| 1302 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
| 1303 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 1304 | } |
| 1305 | |
| 1306 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
| 1307 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 1308 | } |
| 1309 | |
| 1310 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
| 1311 | ConnectStatusHelper( |
| 1312 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 1313 | } |
| 1314 | |
| 1315 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
| 1316 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 1317 | } |
| 1318 | |
| 1319 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
| 1320 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 1321 | } |
| 1322 | |
| 1323 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
| 1324 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 1325 | } |
| 1326 | |
| 1327 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
| 1328 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 1329 | } |
| 1330 | |
| 1331 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
| 1332 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 1333 | } |
| 1334 | |
| 1335 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
| 1336 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 1337 | } |
| 1338 | |
| 1339 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
| 1340 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 1341 | } |
| 1342 | |
| 1343 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
| 1344 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 1345 | } |
| 1346 | |
| 1347 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
| 1348 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 1349 | } |
| 1350 | |
| 1351 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
| 1352 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 1353 | } |
| 1354 | |
| 1355 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
| 1356 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 1357 | } |
| 1358 | |
| 1359 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
| 1360 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 1361 | } |
| 1362 | |
| 1363 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
| 1364 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 1365 | } |
| 1366 | |
| 1367 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
| 1368 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 1369 | } |
| 1370 | |
| 1371 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
| 1372 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 1373 | } |
| 1374 | |
| 1375 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
| 1376 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 1377 | } |
| 1378 | |
| 1379 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
| 1380 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 1381 | } |
| 1382 | |
| 1383 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
| 1384 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 1385 | } |
| 1386 | |
| 1387 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
| 1388 | ConnectStatusHelperWithExpectedStatus( |
| 1389 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1390 | ERR_PROXY_AUTH_REQUESTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
| 1394 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 1395 | } |
| 1396 | |
| 1397 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
| 1398 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 1399 | } |
| 1400 | |
| 1401 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
| 1402 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 1403 | } |
| 1404 | |
| 1405 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
| 1406 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 1407 | } |
| 1408 | |
| 1409 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
| 1410 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 1411 | } |
| 1412 | |
| 1413 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
| 1414 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 1415 | } |
| 1416 | |
| 1417 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
| 1418 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 1419 | } |
| 1420 | |
| 1421 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
| 1422 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 1423 | } |
| 1424 | |
| 1425 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
| 1426 | ConnectStatusHelper( |
| 1427 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 1428 | } |
| 1429 | |
| 1430 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
| 1431 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 1432 | } |
| 1433 | |
| 1434 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
| 1435 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 1436 | } |
| 1437 | |
| 1438 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
| 1439 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 1440 | } |
| 1441 | |
| 1442 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
| 1443 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 1444 | } |
| 1445 | |
| 1446 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
| 1447 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 1448 | } |
| 1449 | |
| 1450 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
| 1451 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 1452 | } |
| 1453 | |
| 1454 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
| 1455 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 1456 | } |
| 1457 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1458 | // Test the flow when both the proxy server AND origin server require |
| 1459 | // authentication. Again, this uses basic auth for both since that is |
| 1460 | // the simplest to mock. |
| 1461 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1462 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 1463 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1464 | // Configure against proxy server "myproxy:70". |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1465 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1466 | CreateSession(&session_deps))); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1467 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1468 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1469 | request.method = "GET"; |
| 1470 | request.url = GURL("http://www.google.com/"); |
| 1471 | request.load_flags = 0; |
| 1472 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1473 | MockWrite data_writes1[] = { |
| 1474 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 1475 | "Host: www.google.com\r\n" |
| 1476 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 1477 | }; |
| 1478 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1479 | MockRead data_reads1[] = { |
| 1480 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 1481 | // Give a couple authenticate options (only the middle one is actually |
| 1482 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1483 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1484 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1485 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1487 | // Large content-length -- won't matter, as connection will be reset. |
| 1488 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1489 | MockRead(false, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1490 | }; |
| 1491 | |
| 1492 | // After calling trans->RestartWithAuth() the first time, this is the |
| 1493 | // request we should be issuing -- the final header line contains the |
| 1494 | // proxy's credentials. |
| 1495 | MockWrite data_writes2[] = { |
| 1496 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 1497 | "Host: www.google.com\r\n" |
| 1498 | "Proxy-Connection: keep-alive\r\n" |
| 1499 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1500 | }; |
| 1501 | |
| 1502 | // Now the proxy server lets the request pass through to origin server. |
| 1503 | // The origin server responds with a 401. |
| 1504 | MockRead data_reads2[] = { |
| 1505 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1506 | // Note: We are using the same realm-name as the proxy server. This is |
| 1507 | // completely valid, as realms are unique across hosts. |
| 1508 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1509 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1510 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1511 | MockRead(false, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1512 | }; |
| 1513 | |
| 1514 | // After calling trans->RestartWithAuth() the second time, we should send |
| 1515 | // the credentials for both the proxy and origin server. |
| 1516 | MockWrite data_writes3[] = { |
| 1517 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 1518 | "Host: www.google.com\r\n" |
| 1519 | "Proxy-Connection: keep-alive\r\n" |
| 1520 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 1521 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 1522 | }; |
| 1523 | |
| 1524 | // Lastly we get the desired content. |
| 1525 | MockRead data_reads3[] = { |
| 1526 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1527 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1528 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1529 | MockRead(false, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1530 | }; |
| 1531 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1532 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1533 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 1534 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 1535 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1536 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
| 1537 | session_deps.socket_factory.AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1538 | |
| 1539 | TestCompletionCallback callback1; |
| 1540 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1541 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1543 | |
| 1544 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1545 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1546 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1547 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1548 | EXPECT_FALSE(response == NULL); |
| 1549 | |
| 1550 | // The password prompt info should have been set in response->auth_challenge. |
| 1551 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1552 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1553 | EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1554 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 1555 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 1556 | |
| 1557 | TestCompletionCallback callback2; |
| 1558 | |
| 1559 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1560 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1561 | |
| 1562 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1563 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1564 | |
| 1565 | response = trans->GetResponseInfo(); |
| 1566 | EXPECT_FALSE(response == NULL); |
| 1567 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1568 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1569 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1570 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 1571 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 1572 | |
| 1573 | TestCompletionCallback callback3; |
| 1574 | |
| 1575 | rv = trans->RestartWithAuth(L"foo2", L"bar2", &callback3); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1576 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1577 | |
| 1578 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1579 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1580 | |
| 1581 | response = trans->GetResponseInfo(); |
| 1582 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1583 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1584 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1585 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1586 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 1587 | // can't hook into its internals to cause it to generate predictable NTLM |
| 1588 | // authorization headers. |
| 1589 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1590 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1591 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 1592 | // bytes in the debugger. |
| 1593 | |
| 1594 | // Enter the correct password and authenticate successfully. |
| 1595 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1596 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 1597 | MockGetHostName); |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1598 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 1599 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1600 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1601 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1602 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1603 | request.method = "GET"; |
| 1604 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1605 | request.load_flags = 0; |
| 1606 | |
| 1607 | MockWrite data_writes1[] = { |
| 1608 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1609 | "Host: 172.22.68.17\r\n" |
| 1610 | "Connection: keep-alive\r\n\r\n"), |
| 1611 | }; |
| 1612 | |
| 1613 | MockRead data_reads1[] = { |
| 1614 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1615 | // Negotiate and NTLM are often requested together. We only support NTLM. |
| 1616 | MockRead("WWW-Authenticate: Negotiate\r\n"), |
| 1617 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 1618 | MockRead("Connection: close\r\n"), |
| 1619 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1620 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1621 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1622 | MockRead(false, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1623 | }; |
| 1624 | |
| 1625 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1626 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1627 | // request we should be issuing -- the final header line contains a Type |
| 1628 | // 1 message. |
| 1629 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1630 | "Host: 172.22.68.17\r\n" |
| 1631 | "Connection: keep-alive\r\n" |
| 1632 | "Authorization: NTLM " |
| 1633 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1634 | |
| 1635 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1636 | // (the credentials for the origin server). The second request continues |
| 1637 | // on the same connection. |
| 1638 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1639 | "Host: 172.22.68.17\r\n" |
| 1640 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1641 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1642 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1643 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 1644 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 1645 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1646 | }; |
| 1647 | |
| 1648 | MockRead data_reads2[] = { |
| 1649 | // The origin server responds with a Type 2 message. |
| 1650 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1651 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1652 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1653 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1654 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1655 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1656 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1657 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1658 | "BtAAAAAAA=\r\n"), |
| 1659 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1660 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1661 | MockRead("You are not authorized to view this page\r\n"), |
| 1662 | |
| 1663 | // Lastly we get the desired content. |
| 1664 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1665 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 1666 | MockRead("Content-Length: 13\r\n\r\n"), |
| 1667 | MockRead("Please Login\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1668 | MockRead(false, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1669 | }; |
| 1670 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1671 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1672 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 1673 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1674 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1675 | |
| 1676 | TestCompletionCallback callback1; |
| 1677 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1678 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1680 | |
| 1681 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1682 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1683 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1684 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 1685 | TestCompletionCallback callback2; |
| 1686 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1688 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1689 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1690 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 1691 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1693 | EXPECT_FALSE(response == NULL); |
| 1694 | |
| 1695 | // The password prompt info should have been set in response->auth_challenge. |
| 1696 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1697 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1698 | EXPECT_EQ(L"172.22.68.17:80", response->auth_challenge->host_and_port); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1699 | EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1700 | EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1701 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1702 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1703 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1704 | rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback3); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1705 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1706 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1707 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1708 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1709 | |
| 1710 | response = trans->GetResponseInfo(); |
| 1711 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1712 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1713 | } |
| 1714 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1715 | // Enter a wrong password, and then the correct one. |
| 1716 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1717 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 1718 | MockGetHostName); |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1719 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 1720 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1721 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1722 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1723 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1724 | request.method = "GET"; |
| 1725 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1726 | request.load_flags = 0; |
| 1727 | |
| 1728 | MockWrite data_writes1[] = { |
| 1729 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1730 | "Host: 172.22.68.17\r\n" |
| 1731 | "Connection: keep-alive\r\n\r\n"), |
| 1732 | }; |
| 1733 | |
| 1734 | MockRead data_reads1[] = { |
| 1735 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1736 | // Negotiate and NTLM are often requested together. We only support NTLM. |
| 1737 | MockRead("WWW-Authenticate: Negotiate\r\n"), |
| 1738 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 1739 | MockRead("Connection: close\r\n"), |
| 1740 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1741 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1742 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1743 | MockRead(false, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1744 | }; |
| 1745 | |
| 1746 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1747 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1748 | // request we should be issuing -- the final header line contains a Type |
| 1749 | // 1 message. |
| 1750 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1751 | "Host: 172.22.68.17\r\n" |
| 1752 | "Connection: keep-alive\r\n" |
| 1753 | "Authorization: NTLM " |
| 1754 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1755 | |
| 1756 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1757 | // (the credentials for the origin server). The second request continues |
| 1758 | // on the same connection. |
| 1759 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1760 | "Host: 172.22.68.17\r\n" |
| 1761 | "Connection: keep-alive\r\n" |
| 1762 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1763 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1764 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 1765 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 1766 | "4Ww7b7E=\r\n\r\n"), |
| 1767 | }; |
| 1768 | |
| 1769 | MockRead data_reads2[] = { |
| 1770 | // The origin server responds with a Type 2 message. |
| 1771 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1772 | MockRead("WWW-Authenticate: NTLM " |
| 1773 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 1774 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1775 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1776 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1777 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1778 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1779 | "BtAAAAAAA=\r\n"), |
| 1780 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1781 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1782 | MockRead("You are not authorized to view this page\r\n"), |
| 1783 | |
| 1784 | // Wrong password. |
| 1785 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1786 | MockRead("WWW-Authenticate: Negotiate\r\n"), |
| 1787 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 1788 | MockRead("Connection: close\r\n"), |
| 1789 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1790 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1791 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1792 | MockRead(false, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1793 | }; |
| 1794 | |
| 1795 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1796 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1797 | // request we should be issuing -- the final header line contains a Type |
| 1798 | // 1 message. |
| 1799 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1800 | "Host: 172.22.68.17\r\n" |
| 1801 | "Connection: keep-alive\r\n" |
| 1802 | "Authorization: NTLM " |
| 1803 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1804 | |
| 1805 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1806 | // (the credentials for the origin server). The second request continues |
| 1807 | // on the same connection. |
| 1808 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1809 | "Host: 172.22.68.17\r\n" |
| 1810 | "Connection: keep-alive\r\n" |
| 1811 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1812 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1813 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 1814 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 1815 | "+4MUm7c=\r\n\r\n"), |
| 1816 | }; |
| 1817 | |
| 1818 | MockRead data_reads3[] = { |
| 1819 | // The origin server responds with a Type 2 message. |
| 1820 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1821 | MockRead("WWW-Authenticate: NTLM " |
| 1822 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 1823 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1824 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1825 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1826 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1827 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1828 | "BtAAAAAAA=\r\n"), |
| 1829 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 1830 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1831 | MockRead("You are not authorized to view this page\r\n"), |
| 1832 | |
| 1833 | // Lastly we get the desired content. |
| 1834 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1835 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 1836 | MockRead("Content-Length: 13\r\n\r\n"), |
| 1837 | MockRead("Please Login\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1838 | MockRead(false, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1839 | }; |
| 1840 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1841 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1842 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 1843 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 1844 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1845 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
| 1846 | session_deps.socket_factory.AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1847 | |
| 1848 | TestCompletionCallback callback1; |
| 1849 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1850 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1851 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1852 | |
| 1853 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1854 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1855 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1856 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1857 | TestCompletionCallback callback2; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1858 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1860 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1861 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1862 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1863 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1865 | EXPECT_FALSE(response == NULL); |
| 1866 | |
| 1867 | // The password prompt info should have been set in response->auth_challenge. |
| 1868 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1869 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1870 | EXPECT_EQ(L"172.22.68.17:80", response->auth_challenge->host_and_port); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1871 | EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1872 | EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1873 | |
| 1874 | TestCompletionCallback callback3; |
| 1875 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1876 | // Enter the wrong password. |
| 1877 | rv = trans->RestartWithAuth(L"testing-ntlm", L"wrongpassword", &callback3); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1879 | |
| 1880 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1881 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1882 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1883 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 1884 | TestCompletionCallback callback4; |
| 1885 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback4); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1886 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1887 | rv = callback4.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1888 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1889 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 1890 | |
| 1891 | response = trans->GetResponseInfo(); |
| 1892 | EXPECT_FALSE(response == NULL); |
| 1893 | |
| 1894 | // The password prompt info should have been set in response->auth_challenge. |
| 1895 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1896 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1897 | EXPECT_EQ(L"172.22.68.17:80", response->auth_challenge->host_and_port); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1898 | EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1899 | EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1900 | |
| 1901 | TestCompletionCallback callback5; |
| 1902 | |
| 1903 | // Now enter the right password. |
| 1904 | rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback5); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1906 | |
| 1907 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1908 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1909 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1910 | response = trans->GetResponseInfo(); |
| 1911 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1912 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1913 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1914 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 1915 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1916 | // Test reading a server response which has only headers, and no body. |
| 1917 | // After some maximum number of bytes is consumed, the transaction should |
| 1918 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
| 1919 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1920 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 1921 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1922 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1923 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1924 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1925 | request.method = "GET"; |
| 1926 | request.url = GURL("http://www.google.com/"); |
| 1927 | request.load_flags = 0; |
| 1928 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 1929 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 1930 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 1931 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1932 | |
| 1933 | MockRead data_reads[] = { |
| 1934 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 1935 | MockRead(true, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1936 | MockRead("\r\nBODY"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1937 | MockRead(false, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1938 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1939 | StaticSocketDataProvider data(data_reads, NULL); |
| 1940 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1941 | |
| 1942 | TestCompletionCallback callback; |
| 1943 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1944 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1945 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1946 | |
| 1947 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1948 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1949 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1950 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1951 | EXPECT_TRUE(response == NULL); |
| 1952 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1953 | |
| 1954 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 1955 | // establish tunnel. |
| 1956 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
| 1957 | TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { |
| 1958 | // Configure against proxy server "myproxy:70". |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1959 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 1960 | |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 1961 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1962 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 1963 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1964 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1965 | HttpRequestInfo request; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1966 | request.method = "GET"; |
| 1967 | request.url = GURL("https://www.google.com/"); |
| 1968 | request.load_flags = 0; |
| 1969 | |
| 1970 | // Since we have proxy, should try to establish tunnel. |
| 1971 | MockWrite data_writes1[] = { |
| 1972 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 1973 | "Host: www.google.com\r\n" |
| 1974 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1975 | }; |
| 1976 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 1977 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1978 | // connection. Usually a proxy would return 501 (not implemented), |
| 1979 | // or 200 (tunnel established). |
| 1980 | MockRead data_reads1[] = { |
| 1981 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1982 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1983 | MockRead(false, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1984 | }; |
| 1985 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 1986 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 1987 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1988 | |
| 1989 | TestCompletionCallback callback1; |
| 1990 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 1991 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1992 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1993 | |
| 1994 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1995 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1996 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1998 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 1999 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2000 | // Empty the current queue. This is necessary because idle sockets are |
| 2001 | // added to the connection pool asynchronously with a PostTask. |
| 2002 | MessageLoop::current()->RunAllPending(); |
| 2003 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 2004 | // We now check to make sure the TCPClientSocket was not added back to |
| 2005 | // the pool. |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2006 | EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 2007 | trans.reset(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2008 | MessageLoop::current()->RunAllPending(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 2009 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2010 | EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 2011 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2012 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2013 | // Make sure that we recycle a socket after reading all of the response body. |
| 2014 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2015 | SessionDependencies session_deps; |
| 2016 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2017 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2018 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2019 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2020 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2021 | request.method = "GET"; |
| 2022 | request.url = GURL("http://www.google.com/"); |
| 2023 | request.load_flags = 0; |
| 2024 | |
| 2025 | MockRead data_reads[] = { |
| 2026 | // A part of the response body is received with the response headers. |
| 2027 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 2028 | // The rest of the response body is received in two parts. |
| 2029 | MockRead("lo"), |
| 2030 | MockRead(" world"), |
| 2031 | MockRead("junk"), // Should not be read!! |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2032 | MockRead(false, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2033 | }; |
| 2034 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2035 | StaticSocketDataProvider data(data_reads, NULL); |
| 2036 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2037 | |
| 2038 | TestCompletionCallback callback; |
| 2039 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2040 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2042 | |
| 2043 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2044 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2045 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2046 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2047 | EXPECT_TRUE(response != NULL); |
| 2048 | |
| 2049 | EXPECT_TRUE(response->headers != NULL); |
| 2050 | std::string status_line = response->headers->GetStatusLine(); |
| 2051 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 2052 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2053 | EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2054 | |
| 2055 | std::string response_data; |
| 2056 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2057 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2058 | EXPECT_EQ("hello world", response_data); |
| 2059 | |
| 2060 | // Empty the current queue. This is necessary because idle sockets are |
| 2061 | // added to the connection pool asynchronously with a PostTask. |
| 2062 | MessageLoop::current()->RunAllPending(); |
| 2063 | |
| 2064 | // We now check to make sure the socket was added back to the pool. |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2065 | EXPECT_EQ(1, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 2066 | } |
| 2067 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2068 | // Make sure that we recycle a socket after a zero-length response. |
| 2069 | // http://crbug.com/9880 |
| 2070 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2071 | SessionDependencies session_deps; |
| 2072 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2073 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2074 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2075 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2076 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2077 | request.method = "GET"; |
| 2078 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 2079 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 2080 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 2081 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 2082 | request.load_flags = 0; |
| 2083 | |
| 2084 | MockRead data_reads[] = { |
| 2085 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 2086 | "Content-Length: 0\r\n" |
| 2087 | "Content-Type: text/html\r\n\r\n"), |
| 2088 | MockRead("junk"), // Should not be read!! |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2089 | MockRead(false, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2090 | }; |
| 2091 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2092 | StaticSocketDataProvider data(data_reads, NULL); |
| 2093 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2094 | |
| 2095 | TestCompletionCallback callback; |
| 2096 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2097 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2098 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2099 | |
| 2100 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2101 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2102 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2103 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2104 | EXPECT_TRUE(response != NULL); |
| 2105 | |
| 2106 | EXPECT_TRUE(response->headers != NULL); |
| 2107 | std::string status_line = response->headers->GetStatusLine(); |
| 2108 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 2109 | |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2110 | EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2111 | |
| 2112 | std::string response_data; |
| 2113 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2114 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2115 | EXPECT_EQ("", response_data); |
| 2116 | |
| 2117 | // Empty the current queue. This is necessary because idle sockets are |
| 2118 | // added to the connection pool asynchronously with a PostTask. |
| 2119 | MessageLoop::current()->RunAllPending(); |
| 2120 | |
| 2121 | // We now check to make sure the socket was added back to the pool. |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 2122 | EXPECT_EQ(1, session->tcp_socket_pool()->IdleSocketCount()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 2123 | } |
| 2124 | |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2125 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2126 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2127 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 2128 | // after use. |
| 2129 | request[0].method = "GET"; |
| 2130 | request[0].url = GURL("http://www.google.com/"); |
| 2131 | request[0].load_flags = 0; |
| 2132 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 2133 | // transaction 1. The first attempts fails when writing the POST data. |
| 2134 | // This causes the transaction to retry with a new socket. The second |
| 2135 | // attempt succeeds. |
| 2136 | request[1].method = "POST"; |
| 2137 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2138 | request[1].upload_data = new UploadData; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2139 | request[1].upload_data->AppendBytes("foo", 3); |
| 2140 | request[1].load_flags = 0; |
| 2141 | |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2142 | SessionDependencies session_deps; |
| 2143 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2144 | |
| 2145 | // The first socket is used for transaction 1 and the first attempt of |
| 2146 | // transaction 2. |
| 2147 | |
| 2148 | // The response of transaction 1. |
| 2149 | MockRead data_reads1[] = { |
| 2150 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 2151 | MockRead("hello world"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2152 | MockRead(false, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2153 | }; |
| 2154 | // The mock write results of transaction 1 and the first attempt of |
| 2155 | // transaction 2. |
| 2156 | MockWrite data_writes1[] = { |
| 2157 | MockWrite(false, 64), // GET |
| 2158 | MockWrite(false, 93), // POST |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2159 | MockWrite(false, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2160 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2161 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2162 | |
| 2163 | // The second socket is used for the second attempt of transaction 2. |
| 2164 | |
| 2165 | // The response of transaction 2. |
| 2166 | MockRead data_reads2[] = { |
| 2167 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 2168 | MockRead("welcome"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2169 | MockRead(false, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2170 | }; |
| 2171 | // The mock write results of the second attempt of transaction 2. |
| 2172 | MockWrite data_writes2[] = { |
| 2173 | MockWrite(false, 93), // POST |
| 2174 | MockWrite(false, 3), // POST data |
| 2175 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2176 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2177 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2178 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2179 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2180 | |
| 2181 | const char* kExpectedResponseData[] = { |
| 2182 | "hello world", "welcome" |
| 2183 | }; |
| 2184 | |
| 2185 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2186 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2187 | new HttpNetworkTransaction(session)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2188 | |
| 2189 | TestCompletionCallback callback; |
| 2190 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2191 | int rv = trans->Start(&request[i], &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2192 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2193 | |
| 2194 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2195 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2196 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2198 | EXPECT_TRUE(response != NULL); |
| 2199 | |
| 2200 | EXPECT_TRUE(response->headers != NULL); |
| 2201 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2202 | |
| 2203 | std::string response_data; |
| 2204 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2205 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 2206 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 2207 | } |
| 2208 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2209 | |
| 2210 | // Test the request-challenge-retry sequence for basic auth when there is |
| 2211 | // an identity in the URL. The request should be sent as normal, but when |
| 2212 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2213 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2214 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2215 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2216 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2217 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2218 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2219 | request.method = "GET"; |
| 2220 | // Note: the URL has a username:password in it. |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 2221 | request.url = GURL("http://foo:b@[email protected]/"); |
| 2222 | |
| 2223 | // The password contains an escaped character -- for this test to pass it |
| 2224 | // will need to be unescaped by HttpNetworkTransaction. |
| 2225 | EXPECT_EQ("b%40r", request.url.password()); |
| 2226 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2227 | request.load_flags = LOAD_NORMAL; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2228 | |
| 2229 | MockWrite data_writes1[] = { |
| 2230 | MockWrite("GET / HTTP/1.1\r\n" |
| 2231 | "Host: www.google.com\r\n" |
| 2232 | "Connection: keep-alive\r\n\r\n"), |
| 2233 | }; |
| 2234 | |
| 2235 | MockRead data_reads1[] = { |
| 2236 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2237 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2238 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2239 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2240 | }; |
| 2241 | |
| 2242 | // After the challenge above, the transaction will be restarted using the |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2243 | // identity from the url (foo, b@r) to answer the challenge. |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2244 | MockWrite data_writes2[] = { |
| 2245 | MockWrite("GET / HTTP/1.1\r\n" |
| 2246 | "Host: www.google.com\r\n" |
| 2247 | "Connection: keep-alive\r\n" |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 2248 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2249 | }; |
| 2250 | |
| 2251 | MockRead data_reads2[] = { |
| 2252 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2253 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2254 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2255 | }; |
| 2256 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2257 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2258 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2259 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2260 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2261 | |
| 2262 | TestCompletionCallback callback1; |
| 2263 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2264 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2266 | |
| 2267 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2268 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2269 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2270 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 2271 | TestCompletionCallback callback2; |
| 2272 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2274 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2275 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2276 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 2277 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2278 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2279 | EXPECT_FALSE(response == NULL); |
| 2280 | |
| 2281 | // There is no challenge info, since the identity in URL worked. |
| 2282 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2283 | |
| 2284 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2285 | |
| 2286 | // Empty the current queue. |
| 2287 | MessageLoop::current()->RunAllPending(); |
| 2288 | } |
| 2289 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2290 | // Test the request-challenge-retry sequence for basic auth when there is |
| 2291 | // an incorrect identity in the URL. The identity from the URL should be used |
| 2292 | // only once. |
| 2293 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
| 2294 | SessionDependencies session_deps; |
| 2295 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2296 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2297 | |
| 2298 | HttpRequestInfo request; |
| 2299 | request.method = "GET"; |
| 2300 | // Note: the URL has a username:password in it. The password "baz" is |
| 2301 | // wrong (should be "bar"). |
| 2302 | request.url = GURL("http://foo:[email protected]/"); |
| 2303 | |
| 2304 | request.load_flags = LOAD_NORMAL; |
| 2305 | |
| 2306 | MockWrite data_writes1[] = { |
| 2307 | MockWrite("GET / HTTP/1.1\r\n" |
| 2308 | "Host: www.google.com\r\n" |
| 2309 | "Connection: keep-alive\r\n\r\n"), |
| 2310 | }; |
| 2311 | |
| 2312 | MockRead data_reads1[] = { |
| 2313 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2314 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2315 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2316 | MockRead(false, ERR_FAILED), |
| 2317 | }; |
| 2318 | |
| 2319 | // After the challenge above, the transaction will be restarted using the |
| 2320 | // identity from the url (foo, baz) to answer the challenge. |
| 2321 | MockWrite data_writes2[] = { |
| 2322 | MockWrite("GET / HTTP/1.1\r\n" |
| 2323 | "Host: www.google.com\r\n" |
| 2324 | "Connection: keep-alive\r\n" |
| 2325 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2326 | }; |
| 2327 | |
| 2328 | MockRead data_reads2[] = { |
| 2329 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2330 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2331 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2332 | MockRead(false, ERR_FAILED), |
| 2333 | }; |
| 2334 | |
| 2335 | // After the challenge above, the transaction will be restarted using the |
| 2336 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 2337 | MockWrite data_writes3[] = { |
| 2338 | MockWrite("GET / HTTP/1.1\r\n" |
| 2339 | "Host: www.google.com\r\n" |
| 2340 | "Connection: keep-alive\r\n" |
| 2341 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2342 | }; |
| 2343 | |
| 2344 | MockRead data_reads3[] = { |
| 2345 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2346 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2347 | MockRead(false, OK), |
| 2348 | }; |
| 2349 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2350 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2351 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2352 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 2353 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2354 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
| 2355 | session_deps.socket_factory.AddSocketDataProvider(&data3); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 2356 | |
| 2357 | TestCompletionCallback callback1; |
| 2358 | |
| 2359 | int rv = trans->Start(&request, &callback1, NULL); |
| 2360 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2361 | |
| 2362 | rv = callback1.WaitForResult(); |
| 2363 | EXPECT_EQ(OK, rv); |
| 2364 | |
| 2365 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 2366 | TestCompletionCallback callback2; |
| 2367 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
| 2368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2369 | rv = callback2.WaitForResult(); |
| 2370 | EXPECT_EQ(OK, rv); |
| 2371 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 2372 | |
| 2373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2374 | EXPECT_FALSE(response == NULL); |
| 2375 | // The password prompt info should have been set in response->auth_challenge. |
| 2376 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 2377 | |
| 2378 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
| 2379 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 2380 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 2381 | |
| 2382 | TestCompletionCallback callback3; |
| 2383 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback3); |
| 2384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2385 | rv = callback3.WaitForResult(); |
| 2386 | EXPECT_EQ(OK, rv); |
| 2387 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 2388 | |
| 2389 | response = trans->GetResponseInfo(); |
| 2390 | EXPECT_FALSE(response == NULL); |
| 2391 | |
| 2392 | // There is no challenge info, since the identity worked. |
| 2393 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2394 | |
| 2395 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2396 | |
| 2397 | // Empty the current queue. |
| 2398 | MessageLoop::current()->RunAllPending(); |
| 2399 | } |
| 2400 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2401 | // Test that previously tried username/passwords for a realm get re-used. |
| 2402 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2403 | SessionDependencies session_deps; |
| 2404 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2405 | |
| 2406 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 2407 | { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2408 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2409 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2410 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2411 | request.method = "GET"; |
| 2412 | request.url = GURL("http://www.google.com/x/y/z"); |
| 2413 | request.load_flags = 0; |
| 2414 | |
| 2415 | MockWrite data_writes1[] = { |
| 2416 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 2417 | "Host: www.google.com\r\n" |
| 2418 | "Connection: keep-alive\r\n\r\n"), |
| 2419 | }; |
| 2420 | |
| 2421 | MockRead data_reads1[] = { |
| 2422 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2423 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2424 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2425 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2426 | }; |
| 2427 | |
| 2428 | // Resend with authorization (username=foo, password=bar) |
| 2429 | MockWrite data_writes2[] = { |
| 2430 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 2431 | "Host: www.google.com\r\n" |
| 2432 | "Connection: keep-alive\r\n" |
| 2433 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2434 | }; |
| 2435 | |
| 2436 | // Sever accepts the authorization. |
| 2437 | MockRead data_reads2[] = { |
| 2438 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2439 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2440 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2441 | }; |
| 2442 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2443 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2444 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2445 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2446 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2447 | |
| 2448 | TestCompletionCallback callback1; |
| 2449 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2450 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2451 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2452 | |
| 2453 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2454 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2455 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2456 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2457 | EXPECT_FALSE(response == NULL); |
| 2458 | |
| 2459 | // The password prompt info should have been set in |
| 2460 | // response->auth_challenge. |
| 2461 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 2462 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 2463 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2464 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 2465 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 2466 | |
| 2467 | TestCompletionCallback callback2; |
| 2468 | |
| 2469 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2470 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2471 | |
| 2472 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2473 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2474 | |
| 2475 | response = trans->GetResponseInfo(); |
| 2476 | EXPECT_FALSE(response == NULL); |
| 2477 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2478 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2479 | } |
| 2480 | |
| 2481 | // ------------------------------------------------------------------------ |
| 2482 | |
| 2483 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 2484 | { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2485 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2486 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2487 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2488 | request.method = "GET"; |
| 2489 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 2490 | // protection space as MyRealm1. |
| 2491 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 2492 | request.load_flags = 0; |
| 2493 | |
| 2494 | MockWrite data_writes1[] = { |
| 2495 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 2496 | "Host: www.google.com\r\n" |
| 2497 | "Connection: keep-alive\r\n" |
| 2498 | // Send preemptive authorization for MyRealm1 |
| 2499 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2500 | }; |
| 2501 | |
| 2502 | // The server didn't like the preemptive authorization, and |
| 2503 | // challenges us for a different realm (MyRealm2). |
| 2504 | MockRead data_reads1[] = { |
| 2505 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2506 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 2507 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2508 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2509 | }; |
| 2510 | |
| 2511 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 2512 | MockWrite data_writes2[] = { |
| 2513 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 2514 | "Host: www.google.com\r\n" |
| 2515 | "Connection: keep-alive\r\n" |
| 2516 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 2517 | }; |
| 2518 | |
| 2519 | // Sever accepts the authorization. |
| 2520 | MockRead data_reads2[] = { |
| 2521 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2522 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2523 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2524 | }; |
| 2525 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2526 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2527 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2528 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2529 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2530 | |
| 2531 | TestCompletionCallback callback1; |
| 2532 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2533 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2534 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2535 | |
| 2536 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2537 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2538 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2539 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2540 | EXPECT_FALSE(response == NULL); |
| 2541 | |
| 2542 | // The password prompt info should have been set in |
| 2543 | // response->auth_challenge. |
| 2544 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 2545 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 2546 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2547 | EXPECT_EQ(L"MyRealm2", response->auth_challenge->realm); |
| 2548 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 2549 | |
| 2550 | TestCompletionCallback callback2; |
| 2551 | |
| 2552 | rv = trans->RestartWithAuth(L"foo2", L"bar2", &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2553 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2554 | |
| 2555 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2556 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2557 | |
| 2558 | response = trans->GetResponseInfo(); |
| 2559 | EXPECT_FALSE(response == NULL); |
| 2560 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2561 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2562 | } |
| 2563 | |
| 2564 | // ------------------------------------------------------------------------ |
| 2565 | |
| 2566 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 2567 | // succeed with preemptive authorization. |
| 2568 | { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2569 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2570 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2571 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2572 | request.method = "GET"; |
| 2573 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 2574 | request.load_flags = 0; |
| 2575 | |
| 2576 | MockWrite data_writes1[] = { |
| 2577 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 2578 | "Host: www.google.com\r\n" |
| 2579 | "Connection: keep-alive\r\n" |
| 2580 | // The authorization for MyRealm1 gets sent preemptively |
| 2581 | // (since the url is in the same protection space) |
| 2582 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2583 | }; |
| 2584 | |
| 2585 | // Sever accepts the preemptive authorization |
| 2586 | MockRead data_reads1[] = { |
| 2587 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2588 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2589 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2590 | }; |
| 2591 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2592 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2593 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2594 | |
| 2595 | TestCompletionCallback callback1; |
| 2596 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2597 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2599 | |
| 2600 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2601 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2602 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2604 | EXPECT_FALSE(response == NULL); |
| 2605 | |
| 2606 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2607 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2608 | } |
| 2609 | |
| 2610 | // ------------------------------------------------------------------------ |
| 2611 | |
| 2612 | // Transaction 4: request another URL in MyRealm (however the |
| 2613 | // url is not known to belong to the protection space, so no pre-auth). |
| 2614 | { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2615 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2616 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2617 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2618 | request.method = "GET"; |
| 2619 | request.url = GURL("http://www.google.com/x/1"); |
| 2620 | request.load_flags = 0; |
| 2621 | |
| 2622 | MockWrite data_writes1[] = { |
| 2623 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 2624 | "Host: www.google.com\r\n" |
| 2625 | "Connection: keep-alive\r\n\r\n"), |
| 2626 | }; |
| 2627 | |
| 2628 | MockRead data_reads1[] = { |
| 2629 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2630 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2631 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2632 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2633 | }; |
| 2634 | |
| 2635 | // Resend with authorization from MyRealm's cache. |
| 2636 | MockWrite data_writes2[] = { |
| 2637 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 2638 | "Host: www.google.com\r\n" |
| 2639 | "Connection: keep-alive\r\n" |
| 2640 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2641 | }; |
| 2642 | |
| 2643 | // Sever accepts the authorization. |
| 2644 | MockRead data_reads2[] = { |
| 2645 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2646 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2647 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2648 | }; |
| 2649 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2650 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2651 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2652 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2653 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2654 | |
| 2655 | TestCompletionCallback callback1; |
| 2656 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2657 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2659 | |
| 2660 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2661 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2662 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2663 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 2664 | TestCompletionCallback callback2; |
| 2665 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2666 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2667 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2668 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2669 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 2670 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2671 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2672 | EXPECT_FALSE(response == NULL); |
| 2673 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2674 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2675 | } |
| 2676 | |
| 2677 | // ------------------------------------------------------------------------ |
| 2678 | |
| 2679 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 2680 | // cached identity. Should invalidate and re-prompt. |
| 2681 | { |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2682 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2683 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2684 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2685 | request.method = "GET"; |
| 2686 | request.url = GURL("http://www.google.com/p/q/t"); |
| 2687 | request.load_flags = 0; |
| 2688 | |
| 2689 | MockWrite data_writes1[] = { |
| 2690 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 2691 | "Host: www.google.com\r\n" |
| 2692 | "Connection: keep-alive\r\n\r\n"), |
| 2693 | }; |
| 2694 | |
| 2695 | MockRead data_reads1[] = { |
| 2696 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2697 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2698 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2699 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2700 | }; |
| 2701 | |
| 2702 | // Resend with authorization from cache for MyRealm. |
| 2703 | MockWrite data_writes2[] = { |
| 2704 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 2705 | "Host: www.google.com\r\n" |
| 2706 | "Connection: keep-alive\r\n" |
| 2707 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2708 | }; |
| 2709 | |
| 2710 | // Sever rejects the authorization. |
| 2711 | MockRead data_reads2[] = { |
| 2712 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2713 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2714 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2715 | MockRead(false, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2716 | }; |
| 2717 | |
| 2718 | // At this point we should prompt for new credentials for MyRealm. |
| 2719 | // Restart with username=foo3, password=foo4. |
| 2720 | MockWrite data_writes3[] = { |
| 2721 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 2722 | "Host: www.google.com\r\n" |
| 2723 | "Connection: keep-alive\r\n" |
| 2724 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 2725 | }; |
| 2726 | |
| 2727 | // Sever accepts the authorization. |
| 2728 | MockRead data_reads3[] = { |
| 2729 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2730 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2731 | MockRead(false, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2732 | }; |
| 2733 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2734 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2735 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 2736 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 2737 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 2738 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
| 2739 | session_deps.socket_factory.AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2740 | |
| 2741 | TestCompletionCallback callback1; |
| 2742 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2743 | int rv = trans->Start(&request, &callback1, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2745 | |
| 2746 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2747 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2748 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2749 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 2750 | TestCompletionCallback callback2; |
| 2751 | rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2752 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2753 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2754 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2755 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 2756 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2757 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2758 | EXPECT_FALSE(response == NULL); |
| 2759 | |
| 2760 | // The password prompt info should have been set in |
| 2761 | // response->auth_challenge. |
| 2762 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 2763 | |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 2764 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2765 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 2766 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 2767 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2768 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2769 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2770 | rv = trans->RestartWithAuth(L"foo3", L"bar3", &callback3); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2771 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2772 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 2773 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2774 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2775 | |
| 2776 | response = trans->GetResponseInfo(); |
| 2777 | EXPECT_FALSE(response == NULL); |
| 2778 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2779 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2780 | } |
| 2781 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2782 | |
| 2783 | // Test the ResetStateForRestart() private method. |
| 2784 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
| 2785 | // Create a transaction (the dependencies aren't important). |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2786 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2787 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2788 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2789 | |
| 2790 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2791 | trans->read_buf_ = new IOBuffer(15); |
| 2792 | trans->read_buf_len_ = 15; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 2793 | trans->request_headers_ = "Authorization: NTLM"; |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2794 | |
| 2795 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame^] | 2796 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 2797 | response->auth_challenge = new AuthChallengeInfo(); |
| 2798 | response->ssl_info.cert_status = -15; |
| 2799 | response->response_time = base::Time::Now(); |
| 2800 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2801 | |
| 2802 | { // Setup state for response_.vary_data |
| 2803 | HttpRequestInfo request; |
| 2804 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 2805 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 2806 | scoped_refptr<HttpResponseHeaders> headers = new HttpResponseHeaders(temp); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2807 | request.extra_headers = "Foo: 1\nbar: 23"; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 2808 | EXPECT_TRUE(response->vary_data.Init(request, *headers)); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | // Cause the above state to be reset. |
| 2812 | trans->ResetStateForRestart(); |
| 2813 | |
| 2814 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 2815 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2816 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 2817 | EXPECT_EQ(0U, trans->request_headers_.size()); |
| 2818 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2819 | EXPECT_TRUE(response->headers.get() == NULL); |
| 2820 | EXPECT_EQ(false, response->was_cached); |
| 2821 | EXPECT_EQ(0, response->ssl_info.cert_status); |
| 2822 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 2823 | } |
| 2824 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2825 | // Test HTTPS connections to a site with a bad certificate |
| 2826 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2827 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2828 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2829 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2830 | |
| 2831 | HttpRequestInfo request; |
| 2832 | request.method = "GET"; |
| 2833 | request.url = GURL("https://www.google.com/"); |
| 2834 | request.load_flags = 0; |
| 2835 | |
| 2836 | MockWrite data_writes[] = { |
| 2837 | MockWrite("GET / HTTP/1.1\r\n" |
| 2838 | "Host: www.google.com\r\n" |
| 2839 | "Connection: keep-alive\r\n\r\n"), |
| 2840 | }; |
| 2841 | |
| 2842 | MockRead data_reads[] = { |
| 2843 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2845 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2846 | MockRead(false, OK), |
| 2847 | }; |
| 2848 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2849 | StaticSocketDataProvider ssl_bad_certificate; |
| 2850 | StaticSocketDataProvider data(data_reads, data_writes); |
| 2851 | SSLSocketDataProvider ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); |
| 2852 | SSLSocketDataProvider ssl(true, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2853 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2854 | session_deps.socket_factory.AddSocketDataProvider(&ssl_bad_certificate); |
| 2855 | session_deps.socket_factory.AddSocketDataProvider(&data); |
| 2856 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad); |
| 2857 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2858 | |
| 2859 | TestCompletionCallback callback; |
| 2860 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2861 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2863 | |
| 2864 | rv = callback.WaitForResult(); |
| 2865 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 2866 | |
| 2867 | rv = trans->RestartIgnoringLastError(&callback); |
| 2868 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2869 | |
| 2870 | rv = callback.WaitForResult(); |
| 2871 | EXPECT_EQ(OK, rv); |
| 2872 | |
| 2873 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2874 | |
| 2875 | EXPECT_FALSE(response == NULL); |
| 2876 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2877 | } |
| 2878 | |
| 2879 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 2880 | // proxy |
| 2881 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2882 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2883 | |
| 2884 | HttpRequestInfo request; |
| 2885 | request.method = "GET"; |
| 2886 | request.url = GURL("https://www.google.com/"); |
| 2887 | request.load_flags = 0; |
| 2888 | |
| 2889 | MockWrite proxy_writes[] = { |
| 2890 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2891 | "Host: www.google.com\r\n" |
| 2892 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2893 | }; |
| 2894 | |
| 2895 | MockRead proxy_reads[] = { |
| 2896 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2897 | MockRead(false, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2898 | }; |
| 2899 | |
| 2900 | MockWrite data_writes[] = { |
| 2901 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2902 | "Host: www.google.com\r\n" |
| 2903 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2904 | MockWrite("GET / HTTP/1.1\r\n" |
| 2905 | "Host: www.google.com\r\n" |
| 2906 | "Connection: keep-alive\r\n\r\n"), |
| 2907 | }; |
| 2908 | |
| 2909 | MockRead data_reads[] = { |
| 2910 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 2911 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2912 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2913 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2914 | MockRead(false, OK), |
| 2915 | }; |
| 2916 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2917 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 2918 | StaticSocketDataProvider data(data_reads, data_writes); |
| 2919 | SSLSocketDataProvider ssl_bad(true, ERR_CERT_AUTHORITY_INVALID); |
| 2920 | SSLSocketDataProvider ssl(true, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2921 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2922 | session_deps.socket_factory.AddSocketDataProvider(&ssl_bad_certificate); |
| 2923 | session_deps.socket_factory.AddSocketDataProvider(&data); |
| 2924 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad); |
| 2925 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2926 | |
| 2927 | TestCompletionCallback callback; |
| 2928 | |
| 2929 | for (int i = 0; i < 2; i++) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2930 | session_deps.socket_factory.ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2931 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2932 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2933 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2934 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2935 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 2936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2937 | |
| 2938 | rv = callback.WaitForResult(); |
| 2939 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 2940 | |
| 2941 | rv = trans->RestartIgnoringLastError(&callback); |
| 2942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2943 | |
| 2944 | rv = callback.WaitForResult(); |
| 2945 | EXPECT_EQ(OK, rv); |
| 2946 | |
| 2947 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2948 | |
| 2949 | EXPECT_FALSE(response == NULL); |
| 2950 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2951 | } |
| 2952 | } |
| 2953 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2954 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2955 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2956 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2957 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2958 | |
| 2959 | HttpRequestInfo request; |
| 2960 | request.method = "GET"; |
| 2961 | request.url = GURL("http://www.google.com/"); |
| 2962 | request.user_agent = "Chromium Ultra Awesome X Edition"; |
| 2963 | |
| 2964 | MockWrite data_writes[] = { |
| 2965 | MockWrite("GET / HTTP/1.1\r\n" |
| 2966 | "Host: www.google.com\r\n" |
| 2967 | "Connection: keep-alive\r\n" |
| 2968 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 2969 | }; |
| 2970 | |
| 2971 | // Lastly, the server responds with the actual content. |
| 2972 | MockRead data_reads[] = { |
| 2973 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2974 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2975 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2976 | MockRead(false, OK), |
| 2977 | }; |
| 2978 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 2979 | StaticSocketDataProvider data(data_reads, data_writes); |
| 2980 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2981 | |
| 2982 | TestCompletionCallback callback; |
| 2983 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 2984 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2986 | |
| 2987 | rv = callback.WaitForResult(); |
| 2988 | EXPECT_EQ(OK, rv); |
| 2989 | } |
| 2990 | |
| 2991 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 2992 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 2993 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 2994 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2995 | |
| 2996 | HttpRequestInfo request; |
| 2997 | request.method = "GET"; |
| 2998 | request.url = GURL("http://www.google.com/"); |
| 2999 | request.load_flags = 0; |
| 3000 | request.referrer = GURL("http://the.previous.site.com/"); |
| 3001 | |
| 3002 | MockWrite data_writes[] = { |
| 3003 | MockWrite("GET / HTTP/1.1\r\n" |
| 3004 | "Host: www.google.com\r\n" |
| 3005 | "Connection: keep-alive\r\n" |
| 3006 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 3007 | }; |
| 3008 | |
| 3009 | // Lastly, the server responds with the actual content. |
| 3010 | MockRead data_reads[] = { |
| 3011 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3012 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3013 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3014 | MockRead(false, OK), |
| 3015 | }; |
| 3016 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3017 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3018 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3019 | |
| 3020 | TestCompletionCallback callback; |
| 3021 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3022 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3023 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3024 | |
| 3025 | rv = callback.WaitForResult(); |
| 3026 | EXPECT_EQ(OK, rv); |
| 3027 | } |
| 3028 | |
| 3029 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3030 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3031 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3032 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3033 | |
| 3034 | HttpRequestInfo request; |
| 3035 | request.method = "POST"; |
| 3036 | request.url = GURL("http://www.google.com/"); |
| 3037 | |
| 3038 | MockWrite data_writes[] = { |
| 3039 | MockWrite("POST / HTTP/1.1\r\n" |
| 3040 | "Host: www.google.com\r\n" |
| 3041 | "Connection: keep-alive\r\n" |
| 3042 | "Content-Length: 0\r\n\r\n"), |
| 3043 | }; |
| 3044 | |
| 3045 | // Lastly, the server responds with the actual content. |
| 3046 | MockRead data_reads[] = { |
| 3047 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3048 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3049 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3050 | MockRead(false, OK), |
| 3051 | }; |
| 3052 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3053 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3054 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3055 | |
| 3056 | TestCompletionCallback callback; |
| 3057 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3058 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3059 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3060 | |
| 3061 | rv = callback.WaitForResult(); |
| 3062 | EXPECT_EQ(OK, rv); |
| 3063 | } |
| 3064 | |
| 3065 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3066 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3067 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3068 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3069 | |
| 3070 | HttpRequestInfo request; |
| 3071 | request.method = "PUT"; |
| 3072 | request.url = GURL("http://www.google.com/"); |
| 3073 | |
| 3074 | MockWrite data_writes[] = { |
| 3075 | MockWrite("PUT / HTTP/1.1\r\n" |
| 3076 | "Host: www.google.com\r\n" |
| 3077 | "Connection: keep-alive\r\n" |
| 3078 | "Content-Length: 0\r\n\r\n"), |
| 3079 | }; |
| 3080 | |
| 3081 | // Lastly, the server responds with the actual content. |
| 3082 | MockRead data_reads[] = { |
| 3083 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3084 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3085 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3086 | MockRead(false, OK), |
| 3087 | }; |
| 3088 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3089 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3090 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3091 | |
| 3092 | TestCompletionCallback callback; |
| 3093 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3094 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3096 | |
| 3097 | rv = callback.WaitForResult(); |
| 3098 | EXPECT_EQ(OK, rv); |
| 3099 | } |
| 3100 | |
| 3101 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3102 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3103 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3104 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3105 | |
| 3106 | HttpRequestInfo request; |
| 3107 | request.method = "HEAD"; |
| 3108 | request.url = GURL("http://www.google.com/"); |
| 3109 | |
| 3110 | MockWrite data_writes[] = { |
| 3111 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 3112 | "Host: www.google.com\r\n" |
| 3113 | "Connection: keep-alive\r\n" |
| 3114 | "Content-Length: 0\r\n\r\n"), |
| 3115 | }; |
| 3116 | |
| 3117 | // Lastly, the server responds with the actual content. |
| 3118 | MockRead data_reads[] = { |
| 3119 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3120 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3121 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3122 | MockRead(false, OK), |
| 3123 | }; |
| 3124 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3125 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3126 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3127 | |
| 3128 | TestCompletionCallback callback; |
| 3129 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3130 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3132 | |
| 3133 | rv = callback.WaitForResult(); |
| 3134 | EXPECT_EQ(OK, rv); |
| 3135 | } |
| 3136 | |
| 3137 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3138 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3139 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3140 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3141 | |
| 3142 | HttpRequestInfo request; |
| 3143 | request.method = "GET"; |
| 3144 | request.url = GURL("http://www.google.com/"); |
| 3145 | request.load_flags = LOAD_BYPASS_CACHE; |
| 3146 | |
| 3147 | MockWrite data_writes[] = { |
| 3148 | MockWrite("GET / HTTP/1.1\r\n" |
| 3149 | "Host: www.google.com\r\n" |
| 3150 | "Connection: keep-alive\r\n" |
| 3151 | "Pragma: no-cache\r\n" |
| 3152 | "Cache-Control: no-cache\r\n\r\n"), |
| 3153 | }; |
| 3154 | |
| 3155 | // Lastly, the server responds with the actual content. |
| 3156 | MockRead data_reads[] = { |
| 3157 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3158 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3159 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3160 | MockRead(false, OK), |
| 3161 | }; |
| 3162 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3163 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3164 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3165 | |
| 3166 | TestCompletionCallback callback; |
| 3167 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3168 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3169 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3170 | |
| 3171 | rv = callback.WaitForResult(); |
| 3172 | EXPECT_EQ(OK, rv); |
| 3173 | } |
| 3174 | |
| 3175 | TEST_F(HttpNetworkTransactionTest, |
| 3176 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3177 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3178 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3179 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3180 | |
| 3181 | HttpRequestInfo request; |
| 3182 | request.method = "GET"; |
| 3183 | request.url = GURL("http://www.google.com/"); |
| 3184 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 3185 | |
| 3186 | MockWrite data_writes[] = { |
| 3187 | MockWrite("GET / HTTP/1.1\r\n" |
| 3188 | "Host: www.google.com\r\n" |
| 3189 | "Connection: keep-alive\r\n" |
| 3190 | "Cache-Control: max-age=0\r\n\r\n"), |
| 3191 | }; |
| 3192 | |
| 3193 | // Lastly, the server responds with the actual content. |
| 3194 | MockRead data_reads[] = { |
| 3195 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3196 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3197 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3198 | MockRead(false, OK), |
| 3199 | }; |
| 3200 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3201 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3202 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3203 | |
| 3204 | TestCompletionCallback callback; |
| 3205 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3206 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3207 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3208 | |
| 3209 | rv = callback.WaitForResult(); |
| 3210 | EXPECT_EQ(OK, rv); |
| 3211 | } |
| 3212 | |
| 3213 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 228ff74 | 2009-06-05 01:19:59 | [diff] [blame] | 3214 | SessionDependencies session_deps; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 3215 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3216 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3217 | |
| 3218 | HttpRequestInfo request; |
| 3219 | request.method = "GET"; |
| 3220 | request.url = GURL("http://www.google.com/"); |
| 3221 | request.extra_headers = "FooHeader: Bar\r\n"; |
| 3222 | |
| 3223 | MockWrite data_writes[] = { |
| 3224 | MockWrite("GET / HTTP/1.1\r\n" |
| 3225 | "Host: www.google.com\r\n" |
| 3226 | "Connection: keep-alive\r\n" |
| 3227 | "FooHeader: Bar\r\n\r\n"), |
| 3228 | }; |
| 3229 | |
| 3230 | // Lastly, the server responds with the actual content. |
| 3231 | MockRead data_reads[] = { |
| 3232 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3233 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3234 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3235 | MockRead(false, OK), |
| 3236 | }; |
| 3237 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3238 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3239 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3240 | |
| 3241 | TestCompletionCallback callback; |
| 3242 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3243 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3245 | |
| 3246 | rv = callback.WaitForResult(); |
| 3247 | EXPECT_EQ(OK, rv); |
| 3248 | } |
| 3249 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3250 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 3251 | SessionDependencies session_deps( |
| 3252 | CreateFixedProxyService("socks4://myproxy:1080")); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3253 | |
| 3254 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3255 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3256 | |
| 3257 | HttpRequestInfo request; |
| 3258 | request.method = "GET"; |
| 3259 | request.url = GURL("http://www.google.com/"); |
| 3260 | request.load_flags = 0; |
| 3261 | |
| 3262 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 3263 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 3264 | |
| 3265 | MockWrite data_writes[] = { |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3266 | MockWrite(true, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3267 | MockWrite("GET / HTTP/1.1\r\n" |
| 3268 | "Host: www.google.com\r\n" |
| 3269 | "Connection: keep-alive\r\n\r\n") |
| 3270 | }; |
| 3271 | |
| 3272 | MockRead data_reads[] = { |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3273 | MockRead(true, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3274 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3275 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 3276 | MockRead("Payload"), |
| 3277 | MockRead(false, OK) |
| 3278 | }; |
| 3279 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3280 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3281 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3282 | |
| 3283 | TestCompletionCallback callback; |
| 3284 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3285 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3286 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3287 | |
| 3288 | rv = callback.WaitForResult(); |
| 3289 | EXPECT_EQ(OK, rv); |
| 3290 | |
| 3291 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3292 | EXPECT_FALSE(response == NULL); |
| 3293 | |
| 3294 | std::string response_text; |
| 3295 | rv = ReadTransaction(trans.get(), &response_text); |
| 3296 | EXPECT_EQ(OK, rv); |
| 3297 | EXPECT_EQ("Payload", response_text); |
| 3298 | } |
| 3299 | |
| 3300 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 3301 | SessionDependencies session_deps( |
| 3302 | CreateFixedProxyService("socks4://myproxy:1080")); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3303 | |
| 3304 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3305 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3306 | |
| 3307 | HttpRequestInfo request; |
| 3308 | request.method = "GET"; |
| 3309 | request.url = GURL("https://www.google.com/"); |
| 3310 | request.load_flags = 0; |
| 3311 | |
| 3312 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 3313 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 3314 | |
| 3315 | MockWrite data_writes[] = { |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3316 | MockWrite(true, reinterpret_cast<char*>(write_buffer), |
| 3317 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3318 | MockWrite("GET / HTTP/1.1\r\n" |
| 3319 | "Host: www.google.com\r\n" |
| 3320 | "Connection: keep-alive\r\n\r\n") |
| 3321 | }; |
| 3322 | |
| 3323 | MockRead data_reads[] = { |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3324 | MockWrite(true, reinterpret_cast<char*>(read_buffer), |
| 3325 | arraysize(read_buffer)), |
| 3326 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3327 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 3328 | MockRead("Payload"), |
| 3329 | MockRead(false, OK) |
| 3330 | }; |
| 3331 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3332 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3333 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3334 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3335 | SSLSocketDataProvider ssl(true, OK); |
| 3336 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3337 | |
| 3338 | TestCompletionCallback callback; |
| 3339 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3340 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3342 | |
| 3343 | rv = callback.WaitForResult(); |
| 3344 | EXPECT_EQ(OK, rv); |
| 3345 | |
| 3346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3347 | EXPECT_FALSE(response == NULL); |
| 3348 | |
| 3349 | std::string response_text; |
| 3350 | rv = ReadTransaction(trans.get(), &response_text); |
| 3351 | EXPECT_EQ(OK, rv); |
| 3352 | EXPECT_EQ("Payload", response_text); |
| 3353 | } |
| 3354 | |
| 3355 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 3356 | SessionDependencies session_deps( |
| 3357 | CreateFixedProxyService("socks5://myproxy:1080")); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3358 | |
| 3359 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3360 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3361 | |
| 3362 | HttpRequestInfo request; |
| 3363 | request.method = "GET"; |
| 3364 | request.url = GURL("http://www.google.com/"); |
| 3365 | request.load_flags = 0; |
| 3366 | |
| 3367 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 3368 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
| 3369 | const char kSOCKS5OkRequest[] = |
| 3370 | { 0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 3371 | const char kSOCKS5OkResponse[] = |
| 3372 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 3373 | |
| 3374 | MockWrite data_writes[] = { |
| 3375 | MockWrite(true, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 3376 | MockWrite(true, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 3377 | MockWrite("GET / HTTP/1.1\r\n" |
| 3378 | "Host: www.google.com\r\n" |
| 3379 | "Connection: keep-alive\r\n\r\n") |
| 3380 | }; |
| 3381 | |
| 3382 | MockRead data_reads[] = { |
| 3383 | MockWrite(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 3384 | MockWrite(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
| 3385 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3386 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 3387 | MockRead("Payload"), |
| 3388 | MockRead(false, OK) |
| 3389 | }; |
| 3390 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3391 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3392 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3393 | |
| 3394 | TestCompletionCallback callback; |
| 3395 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3396 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3397 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3398 | |
| 3399 | rv = callback.WaitForResult(); |
| 3400 | EXPECT_EQ(OK, rv); |
| 3401 | |
| 3402 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3403 | EXPECT_FALSE(response == NULL); |
| 3404 | |
| 3405 | std::string response_text; |
| 3406 | rv = ReadTransaction(trans.get(), &response_text); |
| 3407 | EXPECT_EQ(OK, rv); |
| 3408 | EXPECT_EQ("Payload", response_text); |
| 3409 | } |
| 3410 | |
| 3411 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 3412 | SessionDependencies session_deps( |
| 3413 | CreateFixedProxyService("socks5://myproxy:1080")); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3414 | |
| 3415 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3416 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 3417 | |
| 3418 | HttpRequestInfo request; |
| 3419 | request.method = "GET"; |
| 3420 | request.url = GURL("https://www.google.com/"); |
| 3421 | request.load_flags = 0; |
| 3422 | |
| 3423 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 3424 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
| 3425 | const unsigned char kSOCKS5OkRequest[] = |
| 3426 | { 0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x01, 0xBB }; |
| 3427 | const char kSOCKS5OkResponse[] = |
| 3428 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 3429 | |
| 3430 | MockWrite data_writes[] = { |
| 3431 | MockWrite(true, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 3432 | MockWrite(true, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 3433 | arraysize(kSOCKS5OkRequest)), |
| 3434 | MockWrite("GET / HTTP/1.1\r\n" |
| 3435 | "Host: www.google.com\r\n" |
| 3436 | "Connection: keep-alive\r\n\r\n") |
| 3437 | }; |
| 3438 | |
| 3439 | MockRead data_reads[] = { |
| 3440 | MockWrite(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 3441 | MockWrite(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3442 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3443 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 3444 | MockRead("Payload"), |
| 3445 | MockRead(false, OK) |
| 3446 | }; |
| 3447 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3448 | StaticSocketDataProvider data(data_reads, data_writes); |
| 3449 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3450 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3451 | SSLSocketDataProvider ssl(true, OK); |
| 3452 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3453 | |
| 3454 | TestCompletionCallback callback; |
| 3455 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3456 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 3457 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3458 | |
| 3459 | rv = callback.WaitForResult(); |
| 3460 | EXPECT_EQ(OK, rv); |
| 3461 | |
| 3462 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3463 | EXPECT_FALSE(response == NULL); |
| 3464 | |
| 3465 | std::string response_text; |
| 3466 | rv = ReadTransaction(trans.get(), &response_text); |
| 3467 | EXPECT_EQ(OK, rv); |
| 3468 | EXPECT_EQ("Payload", response_text); |
| 3469 | } |
| 3470 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 3471 | // Tests that for connection endpoints the group names are correctly set. |
| 3472 | TEST_F(HttpNetworkTransactionTest, GroupNameForProxyConnections) { |
| 3473 | const struct { |
| 3474 | const std::string proxy_server; |
| 3475 | const std::string url; |
| 3476 | const std::string expected_group_name; |
| 3477 | } tests[] = { |
| 3478 | { |
| 3479 | "", // no proxy (direct) |
| 3480 | "http://www.google.com/direct", |
| 3481 | "http://www.google.com/", |
| 3482 | }, |
| 3483 | { |
| 3484 | "http_proxy", |
| 3485 | "http://www.google.com/http_proxy_normal", |
| 3486 | "proxy/http_proxy:80/", |
| 3487 | }, |
| 3488 | { |
| 3489 | "socks4://socks_proxy:1080", |
| 3490 | "http://www.google.com/socks4_direct", |
| 3491 | "proxy/socks4://socks_proxy:1080/http://www.google.com/", |
| 3492 | }, |
| 3493 | |
| 3494 | // SSL Tests |
| 3495 | { |
| 3496 | "", |
| 3497 | "https://www.google.com/direct_ssl", |
| 3498 | "https://www.google.com/", |
| 3499 | }, |
| 3500 | { |
| 3501 | "http_proxy", |
| 3502 | "https://www.google.com/http_connect_ssl", |
| 3503 | "proxy/http_proxy:80/https://www.google.com/", |
| 3504 | }, |
| 3505 | { |
| 3506 | "socks4://socks_proxy:1080", |
| 3507 | "https://www.google.com/socks4_ssl", |
| 3508 | "proxy/socks4://socks_proxy:1080/https://www.google.com/", |
| 3509 | }, |
| 3510 | }; |
| 3511 | |
| 3512 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 3513 | SessionDependencies session_deps( |
| 3514 | CreateFixedProxyService(tests[i].proxy_server)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 3515 | |
| 3516 | scoped_refptr<CaptureGroupNameSocketPool> conn_pool( |
| 3517 | new CaptureGroupNameSocketPool()); |
| 3518 | |
| 3519 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
[email protected] | a937a06d | 2009-08-19 21:19:24 | [diff] [blame] | 3520 | session->tcp_socket_pool_ = conn_pool.get(); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 3521 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3522 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 3523 | |
| 3524 | HttpRequestInfo request; |
| 3525 | request.method = "GET"; |
| 3526 | request.url = GURL(tests[i].url); |
| 3527 | request.load_flags = 0; |
| 3528 | |
| 3529 | TestCompletionCallback callback; |
| 3530 | |
| 3531 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3532 | EXPECT_EQ(ERR_IO_PENDING, trans->Start(&request, &callback, NULL)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 3533 | EXPECT_EQ(tests[i].expected_group_name, |
| 3534 | conn_pool->last_group_name_received()); |
| 3535 | } |
| 3536 | } |
| 3537 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 3538 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | 5c6a17e | 2009-06-10 00:54:54 | [diff] [blame] | 3539 | SessionDependencies session_deps( |
| 3540 | CreateFixedProxyService("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 3541 | |
| 3542 | session_deps.host_resolver->rules()->AddSimulatedFailure("*"); |
| 3543 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 3544 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3545 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 3546 | |
| 3547 | HttpRequestInfo request; |
| 3548 | request.method = "GET"; |
| 3549 | request.url = GURL("http://www.google.com/"); |
| 3550 | |
| 3551 | TestCompletionCallback callback; |
| 3552 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3553 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 3554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3555 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 3556 | rv = callback.WaitForResult(); |
| 3557 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 3558 | } |
| 3559 | |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3560 | // Host resolution observer used by |
| 3561 | // HttpNetworkTransactionTest.ResolveMadeWithReferrer to check that host |
| 3562 | // resovle requests are issued with a referrer of |expected_referrer|. |
| 3563 | class ResolutionReferrerObserver : public HostResolver::Observer { |
| 3564 | public: |
| 3565 | explicit ResolutionReferrerObserver(const GURL& expected_referrer) |
| 3566 | : expected_referrer_(expected_referrer), |
| 3567 | called_start_with_referrer_(false), |
| 3568 | called_finish_with_referrer_(false) { |
| 3569 | } |
| 3570 | |
| 3571 | virtual void OnStartResolution(int id, |
| 3572 | const HostResolver::RequestInfo& info) { |
| 3573 | if (info.referrer() == expected_referrer_) |
| 3574 | called_start_with_referrer_ = true; |
| 3575 | } |
| 3576 | |
| 3577 | virtual void OnFinishResolutionWithStatus( |
| 3578 | int id, bool was_resolved, const HostResolver::RequestInfo& info ) { |
| 3579 | if (info.referrer() == expected_referrer_) |
| 3580 | called_finish_with_referrer_ = true; |
| 3581 | } |
| 3582 | |
[email protected] | eb255d3 | 2009-06-17 02:11:03 | [diff] [blame] | 3583 | virtual void OnCancelResolution(int id, |
| 3584 | const HostResolver::RequestInfo& info ) { |
| 3585 | FAIL() << "Should not be cancelling any requests!"; |
| 3586 | } |
| 3587 | |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3588 | bool did_complete_with_expected_referrer() const { |
| 3589 | return called_start_with_referrer_ && called_finish_with_referrer_; |
| 3590 | } |
| 3591 | |
| 3592 | private: |
| 3593 | GURL expected_referrer_; |
| 3594 | bool called_start_with_referrer_; |
| 3595 | bool called_finish_with_referrer_; |
| 3596 | |
| 3597 | DISALLOW_COPY_AND_ASSIGN(ResolutionReferrerObserver); |
| 3598 | }; |
| 3599 | |
| 3600 | // Make sure that when HostResolver::Resolve() is invoked, it passes through |
| 3601 | // the "referrer". This is depended on by the DNS prefetch observer. |
| 3602 | TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) { |
| 3603 | GURL referrer = GURL("http://expected-referrer/"); |
| 3604 | EXPECT_TRUE(referrer.is_valid()); |
| 3605 | ResolutionReferrerObserver resolution_observer(referrer); |
| 3606 | |
| 3607 | SessionDependencies session_deps; |
| 3608 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3609 | CreateSession(&session_deps))); |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3610 | |
| 3611 | // Attach an observer to watch the host resolutions being made. |
[email protected] | 94a0d3d9 | 2009-06-27 01:50:14 | [diff] [blame] | 3612 | session_deps.host_resolver->AddObserver(&resolution_observer); |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3613 | |
| 3614 | // Connect up a mock socket which will fail when reading. |
| 3615 | MockRead data_reads[] = { |
| 3616 | MockRead(false, ERR_FAILED), |
| 3617 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3618 | StaticSocketDataProvider data(data_reads, NULL); |
| 3619 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3620 | |
| 3621 | // Issue a request, containing an HTTP referrer. |
| 3622 | HttpRequestInfo request; |
| 3623 | request.method = "GET"; |
| 3624 | request.referrer = referrer; |
| 3625 | request.url = GURL("http://www.google.com/"); |
| 3626 | |
| 3627 | // Run the request until it fails reading from the socket. |
| 3628 | TestCompletionCallback callback; |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3629 | int rv = trans->Start(&request, &callback, NULL); |
[email protected] | f3e6c1e | 2009-06-15 20:52:12 | [diff] [blame] | 3630 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3631 | rv = callback.WaitForResult(); |
| 3632 | EXPECT_EQ(ERR_FAILED, rv); |
| 3633 | |
| 3634 | // Check that the host resolution observer saw |referrer|. |
| 3635 | EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer()); |
| 3636 | } |
| 3637 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3638 | // Make sure that when the load flags contain LOAD_BYPASS_CACHE, the resolver's |
| 3639 | // host cache is bypassed. |
| 3640 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
| 3641 | SessionDependencies session_deps; |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 3642 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 3643 | // Select a host resolver that does caching. |
| 3644 | session_deps.host_resolver = new MockCachingHostResolver; |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 3645 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3646 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 3647 | CreateSession(&session_deps))); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3648 | |
| 3649 | // Warm up the host cache so it has an entry for "www.google.com" (by doing |
| 3650 | // a synchronous lookup.) |
| 3651 | AddressList addrlist; |
[email protected] | 94a0d3d9 | 2009-06-27 01:50:14 | [diff] [blame] | 3652 | int rv = session_deps.host_resolver->Resolve( |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3653 | HostResolver::RequestInfo("www.google.com", 80), &addrlist, |
| 3654 | NULL, NULL, NULL); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3655 | EXPECT_EQ(OK, rv); |
| 3656 | |
| 3657 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 3658 | // and confirming it completes synchronously. |
| 3659 | TestCompletionCallback resolve_callback; |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3660 | rv = session_deps.host_resolver->Resolve( |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3661 | HostResolver::RequestInfo("www.google.com", 80), &addrlist, |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3662 | &resolve_callback, NULL, NULL); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 3663 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3664 | |
| 3665 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 3666 | // we can tell if the next lookup hit the cache, or the "network". |
| 3667 | // (cache --> success, "network" --> failure). |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 3668 | session_deps.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3669 | |
| 3670 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 3671 | // first read -- this won't be reached as the host resolution will fail first. |
| 3672 | MockRead data_reads[] = { MockRead(false, ERR_UNEXPECTED) }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3673 | StaticSocketDataProvider data(data_reads, NULL); |
| 3674 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3675 | |
| 3676 | // Issue a request, asking to bypass the cache(s). |
| 3677 | HttpRequestInfo request; |
| 3678 | request.method = "GET"; |
| 3679 | request.load_flags = LOAD_BYPASS_CACHE; |
| 3680 | request.url = GURL("http://www.google.com/"); |
| 3681 | |
| 3682 | // Run the request. |
| 3683 | TestCompletionCallback callback; |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 3684 | rv = trans->Start(&request, &callback, NULL); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 3685 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 3686 | rv = callback.WaitForResult(); |
| 3687 | |
| 3688 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 3689 | // "www.google.com". |
| 3690 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 3691 | } |
| 3692 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3693 | // Make sure we can handle an error when writing the request. |
| 3694 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
| 3695 | SessionDependencies session_deps; |
| 3696 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
| 3697 | |
| 3698 | HttpRequestInfo request; |
| 3699 | request.method = "GET"; |
| 3700 | request.url = GURL("http://www.foo.com/"); |
| 3701 | request.load_flags = 0; |
| 3702 | |
| 3703 | MockWrite write_failure[] = { |
| 3704 | MockWrite(true, ERR_CONNECTION_RESET), |
| 3705 | }; |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3706 | StaticSocketDataProvider data(NULL, write_failure); |
| 3707 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3708 | |
| 3709 | TestCompletionCallback callback; |
| 3710 | |
| 3711 | scoped_ptr<HttpTransaction> trans( |
| 3712 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3713 | |
| 3714 | int rv = trans->Start(&request, &callback, NULL); |
| 3715 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3716 | |
| 3717 | rv = callback.WaitForResult(); |
| 3718 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 3719 | } |
| 3720 | |
| 3721 | // Check that a connection closed after the start of the headers finishes ok. |
| 3722 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
| 3723 | SessionDependencies session_deps; |
| 3724 | scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); |
| 3725 | |
| 3726 | HttpRequestInfo request; |
| 3727 | request.method = "GET"; |
| 3728 | request.url = GURL("http://www.foo.com/"); |
| 3729 | request.load_flags = 0; |
| 3730 | |
| 3731 | MockRead data_reads[] = { |
| 3732 | MockRead("HTTP/1."), |
| 3733 | MockRead(false, OK), |
| 3734 | }; |
| 3735 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3736 | StaticSocketDataProvider data(data_reads, NULL); |
| 3737 | session_deps.socket_factory.AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3738 | |
| 3739 | TestCompletionCallback callback; |
| 3740 | |
| 3741 | scoped_ptr<HttpTransaction> trans( |
| 3742 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3743 | |
| 3744 | int rv = trans->Start(&request, &callback, NULL); |
| 3745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3746 | |
| 3747 | rv = callback.WaitForResult(); |
| 3748 | EXPECT_EQ(OK, rv); |
| 3749 | |
| 3750 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3751 | EXPECT_TRUE(response != NULL); |
| 3752 | |
| 3753 | EXPECT_TRUE(response->headers != NULL); |
| 3754 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 3755 | |
| 3756 | std::string response_data; |
| 3757 | rv = ReadTransaction(trans.get(), &response_data); |
| 3758 | EXPECT_EQ(OK, rv); |
| 3759 | EXPECT_EQ("", response_data); |
| 3760 | } |
| 3761 | |
| 3762 | // Make sure that a dropped connection while draining the body for auth |
| 3763 | // restart does the right thing. |
| 3764 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
| 3765 | SessionDependencies session_deps; |
| 3766 | scoped_ptr<HttpTransaction> trans( |
| 3767 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3768 | |
| 3769 | HttpRequestInfo request; |
| 3770 | request.method = "GET"; |
| 3771 | request.url = GURL("http://www.google.com/"); |
| 3772 | request.load_flags = 0; |
| 3773 | |
| 3774 | MockWrite data_writes1[] = { |
| 3775 | MockWrite("GET / HTTP/1.1\r\n" |
| 3776 | "Host: www.google.com\r\n" |
| 3777 | "Connection: keep-alive\r\n\r\n"), |
| 3778 | }; |
| 3779 | |
| 3780 | MockRead data_reads1[] = { |
| 3781 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3782 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3783 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3784 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3785 | MockRead("Unauth"), |
| 3786 | MockRead(true, ERR_CONNECTION_RESET), |
| 3787 | }; |
| 3788 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3789 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3790 | session_deps.socket_factory.AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3791 | |
| 3792 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3793 | // be issuing -- the final header line contains the credentials. |
| 3794 | MockWrite data_writes2[] = { |
| 3795 | MockWrite("GET / HTTP/1.1\r\n" |
| 3796 | "Host: www.google.com\r\n" |
| 3797 | "Connection: keep-alive\r\n" |
| 3798 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3799 | }; |
| 3800 | |
| 3801 | // Lastly, the server responds with the actual content. |
| 3802 | MockRead data_reads2[] = { |
| 3803 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3804 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3805 | MockRead("Content-Length: 100\r\n\r\n"), |
| 3806 | MockRead(false, OK), |
| 3807 | }; |
| 3808 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3809 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 3810 | session_deps.socket_factory.AddSocketDataProvider(&data2); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3811 | |
| 3812 | TestCompletionCallback callback1; |
| 3813 | |
| 3814 | int rv = trans->Start(&request, &callback1, NULL); |
| 3815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3816 | |
| 3817 | rv = callback1.WaitForResult(); |
| 3818 | EXPECT_EQ(OK, rv); |
| 3819 | |
| 3820 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3821 | EXPECT_FALSE(response == NULL); |
| 3822 | |
| 3823 | // The password prompt info should have been set in response->auth_challenge. |
| 3824 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 3825 | |
| 3826 | EXPECT_EQ(L"www.google.com:80", response->auth_challenge->host_and_port); |
| 3827 | EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
| 3828 | EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
| 3829 | |
| 3830 | TestCompletionCallback callback2; |
| 3831 | |
| 3832 | rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); |
| 3833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3834 | |
| 3835 | rv = callback2.WaitForResult(); |
| 3836 | EXPECT_EQ(OK, rv); |
| 3837 | |
| 3838 | response = trans->GetResponseInfo(); |
| 3839 | EXPECT_FALSE(response == NULL); |
| 3840 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3841 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3842 | } |
| 3843 | |
| 3844 | // Test HTTPS connections going through a proxy that sends extra data. |
| 3845 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
| 3846 | SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
| 3847 | |
| 3848 | HttpRequestInfo request; |
| 3849 | request.method = "GET"; |
| 3850 | request.url = GURL("https://www.google.com/"); |
| 3851 | request.load_flags = 0; |
| 3852 | |
| 3853 | MockRead proxy_reads[] = { |
| 3854 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
| 3855 | MockRead(false, OK) |
| 3856 | }; |
| 3857 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3858 | StaticSocketDataProvider data(proxy_reads, NULL); |
| 3859 | SSLSocketDataProvider ssl(true, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3860 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 3861 | session_deps.socket_factory.AddSocketDataProvider(&data); |
| 3862 | session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 3863 | |
| 3864 | TestCompletionCallback callback; |
| 3865 | |
| 3866 | session_deps.socket_factory.ResetNextMockIndexes(); |
| 3867 | |
| 3868 | scoped_ptr<HttpTransaction> trans( |
| 3869 | new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3870 | |
| 3871 | int rv = trans->Start(&request, &callback, NULL); |
| 3872 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3873 | |
| 3874 | rv = callback.WaitForResult(); |
| 3875 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3876 | } |
| 3877 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 3878 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
| 3879 | MockRead data_reads[] = { |
| 3880 | MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), |
| 3881 | MockRead(false, OK), |
| 3882 | }; |
| 3883 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
| 3884 | EXPECT_EQ(OK, out.rv); |
| 3885 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 3886 | EXPECT_EQ("", out.response_data); |
| 3887 | } |
| 3888 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 3889 | } // namespace net |