Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
| 6 | 6 |
| 7 #include "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
| 8 #include "net/base/host_resolver.h" | 8 #include "net/base/host_resolver.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_log.h" | 10 #include "net/base/net_log.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 TestCompletionCallback callback; | 59 TestCompletionCallback callback; |
| 60 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 60 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 61 net::ClientSocket* transport = new net::TCPClientSocket( | 61 net::ClientSocket* transport = new net::TCPClientSocket( |
| 62 addr, &log, net::NetLog::Source()); | 62 addr, &log, net::NetLog::Source()); |
| 63 int rv = transport->Connect(&callback); | 63 int rv = transport->Connect(&callback); |
| 64 if (rv == net::ERR_IO_PENDING) | 64 if (rv == net::ERR_IO_PENDING) |
| 65 rv = callback.WaitForResult(); | 65 rv = callback.WaitForResult(); |
| 66 EXPECT_EQ(net::OK, rv); | 66 EXPECT_EQ(net::OK, rv); |
| 67 | 67 |
| 68 scoped_ptr<net::SSLClientSocket> sock( | 68 scoped_ptr<net::SSLClientSocket> sock( |
| 69 socket_factory_->CreateSSLClientSocket(transport, | 69 socket_factory_->CreateSSLClientSocket( |
| 70 test_server.host_port_pair().host(), kDefaultSSLConfig, | 70 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 71 NULL /* ssl_host_info */)); | 71 NULL)); |
| 72 | 72 |
| 73 EXPECT_FALSE(sock->IsConnected()); | 73 EXPECT_FALSE(sock->IsConnected()); |
| 74 | 74 |
| 75 rv = sock->Connect(&callback); | 75 rv = sock->Connect(&callback); |
| 76 EXPECT_TRUE(net::LogContainsBeginEvent( | 76 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 77 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 77 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 78 if (rv != net::OK) { | 78 if (rv == net::ERR_IO_PENDING) |
| 79 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
| 80 EXPECT_FALSE(sock->IsConnected()); | |
| 81 EXPECT_FALSE(net::LogContainsEndEvent( | |
| 82 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT)); | |
| 83 | |
| 84 rv = callback.WaitForResult(); | 79 rv = callback.WaitForResult(); |
| 85 EXPECT_EQ(net::OK, rv); | 80 EXPECT_EQ(net::OK, rv); |
| 86 } | |
| 87 | |
| 88 EXPECT_TRUE(sock->IsConnected()); | 81 EXPECT_TRUE(sock->IsConnected()); |
| 89 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); | 82 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); |
| 90 | 83 |
| 91 sock->Disconnect(); | 84 sock->Disconnect(); |
| 92 EXPECT_FALSE(sock->IsConnected()); | 85 EXPECT_FALSE(sock->IsConnected()); |
| 93 } | 86 } |
| 94 | 87 |
| 95 TEST_F(SSLClientSocketTest, ConnectExpired) { | 88 TEST_F(SSLClientSocketTest, ConnectExpired) { |
| 96 net::TestServer::HTTPSOptions https_options( | 89 net::TestServer::HTTPSOptions https_options( |
| 97 net::TestServer::HTTPSOptions::CERT_EXPIRED); | 90 net::TestServer::HTTPSOptions::CERT_EXPIRED); |
| 98 net::TestServer test_server(https_options, FilePath()); | 91 net::TestServer test_server(https_options, FilePath()); |
| 99 ASSERT_TRUE(test_server.Start()); | 92 ASSERT_TRUE(test_server.Start()); |
| 100 | 93 |
| 101 net::AddressList addr; | 94 net::AddressList addr; |
| 102 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 95 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 103 | 96 |
| 104 TestCompletionCallback callback; | 97 TestCompletionCallback callback; |
| 105 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 98 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 106 net::ClientSocket* transport = new net::TCPClientSocket( | 99 net::ClientSocket* transport = new net::TCPClientSocket( |
| 107 addr, &log, net::NetLog::Source()); | 100 addr, &log, net::NetLog::Source()); |
| 108 int rv = transport->Connect(&callback); | 101 int rv = transport->Connect(&callback); |
| 109 if (rv == net::ERR_IO_PENDING) | 102 if (rv == net::ERR_IO_PENDING) |
| 110 rv = callback.WaitForResult(); | 103 rv = callback.WaitForResult(); |
| 111 EXPECT_EQ(net::OK, rv); | 104 EXPECT_EQ(net::OK, rv); |
| 112 | 105 |
| 113 scoped_ptr<net::SSLClientSocket> sock( | 106 scoped_ptr<net::SSLClientSocket> sock( |
| 114 socket_factory_->CreateSSLClientSocket(transport, | 107 socket_factory_->CreateSSLClientSocket( |
| 115 test_server.host_port_pair().host(), kDefaultSSLConfig, | 108 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 116 NULL /* ssl_host_info */)); | 109 NULL)); |
| 117 | 110 |
| 118 EXPECT_FALSE(sock->IsConnected()); | 111 EXPECT_FALSE(sock->IsConnected()); |
| 119 | 112 |
| 120 rv = sock->Connect(&callback); | 113 rv = sock->Connect(&callback); |
| 121 EXPECT_TRUE(net::LogContainsBeginEvent( | 114 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 122 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 115 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 123 if (rv != net::OK) { | 116 if (rv == net::ERR_IO_PENDING) |
| 124 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 117 rv = callback.WaitForResult(); |
| 125 EXPECT_FALSE(sock->IsConnected()); | |
| 126 EXPECT_FALSE(net::LogContainsEndEvent( | |
| 127 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT)); | |
| 128 | 118 |
| 129 rv = callback.WaitForResult(); | 119 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); |
| 130 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); | |
| 131 } | |
| 132 | 120 |
| 133 // We cannot test sock->IsConnected(), as the NSS implementation disconnects | 121 // Rather than testing whether or not the underlying socket, test that the |
|
wtc
2010/11/10 01:05:50
Nit: "whether or not the underlying socket" is inc
| |
| 134 // the socket when it encounters an error, whereas other implementations | 122 // handshake has finished. This is because it may be desirable to |
| 135 // leave it connected. | 123 // disconnect the socket before showing a user prompt, since the user may |
| 124 // take indefinitely long to respond. | |
| 136 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); | 125 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); |
| 137 } | 126 } |
| 138 | 127 |
| 139 TEST_F(SSLClientSocketTest, ConnectMismatched) { | 128 TEST_F(SSLClientSocketTest, ConnectMismatched) { |
| 140 net::TestServer::HTTPSOptions https_options( | 129 net::TestServer::HTTPSOptions https_options( |
| 141 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 130 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 142 net::TestServer test_server(https_options, FilePath()); | 131 net::TestServer test_server(https_options, FilePath()); |
| 143 ASSERT_TRUE(test_server.Start()); | 132 ASSERT_TRUE(test_server.Start()); |
| 144 | 133 |
| 145 net::AddressList addr; | 134 net::AddressList addr; |
| 146 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 135 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 147 | 136 |
| 148 TestCompletionCallback callback; | 137 TestCompletionCallback callback; |
| 149 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 138 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 150 net::ClientSocket* transport = new net::TCPClientSocket( | 139 net::ClientSocket* transport = new net::TCPClientSocket( |
| 151 addr, &log, net::NetLog::Source()); | 140 addr, &log, net::NetLog::Source()); |
| 152 int rv = transport->Connect(&callback); | 141 int rv = transport->Connect(&callback); |
| 153 if (rv == net::ERR_IO_PENDING) | 142 if (rv == net::ERR_IO_PENDING) |
| 154 rv = callback.WaitForResult(); | 143 rv = callback.WaitForResult(); |
| 155 EXPECT_EQ(net::OK, rv); | 144 EXPECT_EQ(net::OK, rv); |
| 156 | 145 |
| 157 scoped_ptr<net::SSLClientSocket> sock( | 146 scoped_ptr<net::SSLClientSocket> sock( |
| 158 socket_factory_->CreateSSLClientSocket(transport, | 147 socket_factory_->CreateSSLClientSocket( |
| 159 test_server.host_port_pair().host(), kDefaultSSLConfig, | 148 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 160 NULL /* ssl_host_info */)); | 149 NULL)); |
| 161 | 150 |
| 162 EXPECT_FALSE(sock->IsConnected()); | 151 EXPECT_FALSE(sock->IsConnected()); |
| 163 | 152 |
| 164 rv = sock->Connect(&callback); | 153 rv = sock->Connect(&callback); |
| 165 | 154 |
| 166 EXPECT_TRUE(net::LogContainsBeginEvent( | 155 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 167 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 156 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 168 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { | 157 if (rv == net::ERR_IO_PENDING) |
| 169 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 158 rv = callback.WaitForResult(); |
| 170 EXPECT_FALSE(sock->IsConnected()); | |
|
wtc
2010/11/10 01:05:50
On second thought, I think these two EXPECT statem
| |
| 171 EXPECT_FALSE(net::LogContainsEndEvent( | |
| 172 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT)); | |
| 173 | 159 |
| 174 rv = callback.WaitForResult(); | 160 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv); |
| 175 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv); | |
| 176 } | |
| 177 | 161 |
| 178 // We cannot test sock->IsConnected(), as the NSS implementation disconnects | 162 // Rather than testing whether or not the underlying socket, test that the |
| 179 // the socket when it encounters an error, whereas other implementations | 163 // handshake has finished. This is because it may be desirable to |
| 180 // leave it connected. | 164 // disconnect the socket before showing a user prompt, since the user may |
| 165 // take indefinitely long to respond. | |
| 181 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); | 166 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); |
| 182 } | 167 } |
| 183 | 168 |
| 184 // Attempt to connect to a page which requests a client certificate. It should | 169 // Attempt to connect to a page which requests a client certificate. It should |
| 185 // return an error code on connect. | 170 // return an error code on connect. |
| 186 // Flaky: http://crbug.com/54445 | 171 // Flaky: http://crbug.com/54445 |
| 187 TEST_F(SSLClientSocketTest, FLAKY_ConnectClientAuthCertRequested) { | 172 TEST_F(SSLClientSocketTest, FLAKY_ConnectClientAuthCertRequested) { |
| 188 net::TestServer::HTTPSOptions https_options; | 173 net::TestServer::HTTPSOptions https_options; |
| 189 https_options.request_client_certificate = true; | 174 https_options.request_client_certificate = true; |
| 190 net::TestServer test_server(https_options, FilePath()); | 175 net::TestServer test_server(https_options, FilePath()); |
| 191 ASSERT_TRUE(test_server.Start()); | 176 ASSERT_TRUE(test_server.Start()); |
| 192 | 177 |
| 193 net::AddressList addr; | 178 net::AddressList addr; |
| 194 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 179 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 195 | 180 |
| 196 TestCompletionCallback callback; | 181 TestCompletionCallback callback; |
| 197 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 182 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 198 net::ClientSocket* transport = new net::TCPClientSocket( | 183 net::ClientSocket* transport = new net::TCPClientSocket( |
| 199 addr, &log, net::NetLog::Source()); | 184 addr, &log, net::NetLog::Source()); |
| 200 int rv = transport->Connect(&callback); | 185 int rv = transport->Connect(&callback); |
| 201 if (rv == net::ERR_IO_PENDING) | 186 if (rv == net::ERR_IO_PENDING) |
| 202 rv = callback.WaitForResult(); | 187 rv = callback.WaitForResult(); |
| 203 EXPECT_EQ(net::OK, rv); | 188 EXPECT_EQ(net::OK, rv); |
| 204 | 189 |
| 205 scoped_ptr<net::SSLClientSocket> sock( | 190 scoped_ptr<net::SSLClientSocket> sock( |
| 206 socket_factory_->CreateSSLClientSocket(transport, | 191 socket_factory_->CreateSSLClientSocket( |
| 207 test_server.host_port_pair().host(), kDefaultSSLConfig, | 192 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 208 NULL /* ssl_host_info */)); | 193 NULL)); |
| 209 | 194 |
| 210 EXPECT_FALSE(sock->IsConnected()); | 195 EXPECT_FALSE(sock->IsConnected()); |
| 211 | 196 |
| 212 rv = sock->Connect(&callback); | 197 rv = sock->Connect(&callback); |
| 213 EXPECT_TRUE(net::LogContainsBeginEvent( | 198 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 214 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 199 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 215 if (rv != net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 200 if (rv == net::ERR_IO_PENDING) |
| 216 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 201 rv = callback.WaitForResult(); |
| 217 EXPECT_FALSE(sock->IsConnected()); | |
| 218 EXPECT_FALSE(net::LogContainsEndEvent( | |
| 219 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT)); | |
| 220 | 202 |
| 221 rv = callback.WaitForResult(); | 203 EXPECT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 222 EXPECT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | 204 EXPECT_FALSE(sock->IsConnected()); |
| 223 } | |
| 224 | |
| 225 // We cannot test sock->IsConnected(), as the NSS implementation disconnects | |
| 226 // the socket when it encounters an error, whereas other implementations | |
| 227 // leave it connected. | |
| 228 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); | |
| 229 } | 205 } |
| 230 | 206 |
| 231 // Connect to a server requesting optional client authentication. Send it a | 207 // Connect to a server requesting optional client authentication. Send it a |
| 232 // null certificate. It should allow the connection. | 208 // null certificate. It should allow the connection. |
| 233 // | 209 // |
| 234 // TODO(davidben): Also test providing an actual certificate. | 210 // TODO(davidben): Also test providing an actual certificate. |
| 235 TEST_F(SSLClientSocketTest, ConnectClientAuthSendNullCert) { | 211 TEST_F(SSLClientSocketTest, ConnectClientAuthSendNullCert) { |
| 236 net::TestServer::HTTPSOptions https_options; | 212 net::TestServer::HTTPSOptions https_options; |
| 237 https_options.request_client_certificate = true; | 213 https_options.request_client_certificate = true; |
| 238 net::TestServer test_server(https_options, FilePath()); | 214 net::TestServer test_server(https_options, FilePath()); |
| 239 ASSERT_TRUE(test_server.Start()); | 215 ASSERT_TRUE(test_server.Start()); |
| 240 | 216 |
| 241 net::AddressList addr; | 217 net::AddressList addr; |
| 242 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 218 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 243 | 219 |
| 244 TestCompletionCallback callback; | 220 TestCompletionCallback callback; |
| 245 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 221 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 246 net::ClientSocket* transport = new net::TCPClientSocket( | 222 net::ClientSocket* transport = new net::TCPClientSocket( |
| 247 addr, &log, net::NetLog::Source()); | 223 addr, &log, net::NetLog::Source()); |
| 248 int rv = transport->Connect(&callback); | 224 int rv = transport->Connect(&callback); |
| 249 if (rv == net::ERR_IO_PENDING) | 225 if (rv == net::ERR_IO_PENDING) |
| 250 rv = callback.WaitForResult(); | 226 rv = callback.WaitForResult(); |
| 251 EXPECT_EQ(net::OK, rv); | 227 EXPECT_EQ(net::OK, rv); |
| 252 | 228 |
| 253 net::SSLConfig ssl_config = kDefaultSSLConfig; | 229 net::SSLConfig ssl_config = kDefaultSSLConfig; |
| 254 ssl_config.send_client_cert = true; | 230 ssl_config.send_client_cert = true; |
| 255 ssl_config.client_cert = NULL; | 231 ssl_config.client_cert = NULL; |
| 256 | 232 |
| 257 scoped_ptr<net::SSLClientSocket> sock( | 233 scoped_ptr<net::SSLClientSocket> sock( |
| 258 socket_factory_->CreateSSLClientSocket(transport, | 234 socket_factory_->CreateSSLClientSocket( |
| 259 test_server.host_port_pair().host(), ssl_config, | 235 transport, test_server.host_port_pair().host(), ssl_config, |
| 260 NULL /* ssl_host_info */)); | 236 NULL)); |
| 261 | 237 |
| 262 EXPECT_FALSE(sock->IsConnected()); | 238 EXPECT_FALSE(sock->IsConnected()); |
| 263 | 239 |
| 264 // Our test server accepts certificate-less connections. | 240 // Our test server accepts certificate-less connections. |
| 265 // TODO(davidben): Add a test which requires them and verify the error. | 241 // TODO(davidben): Add a test which requires them and verify the error. |
| 266 rv = sock->Connect(&callback); | 242 rv = sock->Connect(&callback); |
| 267 EXPECT_TRUE(net::LogContainsBeginEvent( | 243 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 268 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 244 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 269 if (rv != net::OK) { | 245 if (rv == net::ERR_IO_PENDING) |
| 270 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 246 rv = callback.WaitForResult(); |
| 271 EXPECT_FALSE(sock->IsConnected()); | |
| 272 EXPECT_FALSE(net::LogContainsEndEvent( | |
| 273 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT)); | |
| 274 | 247 |
| 275 rv = callback.WaitForResult(); | 248 EXPECT_EQ(net::OK, rv); |
| 276 EXPECT_EQ(net::OK, rv); | |
| 277 } | |
| 278 | |
| 279 EXPECT_TRUE(sock->IsConnected()); | 249 EXPECT_TRUE(sock->IsConnected()); |
| 280 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); | 250 EXPECT_TRUE(LogContainsSSLConnectEndEvent(log.entries(), -1)); |
| 281 | 251 |
| 282 sock->Disconnect(); | 252 sock->Disconnect(); |
| 283 EXPECT_FALSE(sock->IsConnected()); | 253 EXPECT_FALSE(sock->IsConnected()); |
| 284 } | 254 } |
| 285 | 255 |
| 286 // TODO(wtc): Add unit tests for IsConnectedAndIdle: | 256 // TODO(wtc): Add unit tests for IsConnectedAndIdle: |
| 287 // - Server closes an SSL connection (with a close_notify alert message). | 257 // - Server closes an SSL connection (with a close_notify alert message). |
| 288 // - Server closes the underlying TCP connection directly. | 258 // - Server closes the underlying TCP connection directly. |
| 289 // - Server sends data unexpectedly. | 259 // - Server sends data unexpectedly. |
| 290 | 260 |
| 291 TEST_F(SSLClientSocketTest, Read) { | 261 TEST_F(SSLClientSocketTest, Read) { |
| 292 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 262 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 293 ASSERT_TRUE(test_server.Start()); | 263 ASSERT_TRUE(test_server.Start()); |
| 294 | 264 |
| 295 net::AddressList addr; | 265 net::AddressList addr; |
| 296 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 266 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 297 | 267 |
| 298 TestCompletionCallback callback; | 268 TestCompletionCallback callback; |
| 299 net::ClientSocket* transport = new net::TCPClientSocket( | 269 net::ClientSocket* transport = new net::TCPClientSocket( |
| 300 addr, NULL, net::NetLog::Source()); | 270 addr, NULL, net::NetLog::Source()); |
| 301 int rv = transport->Connect(&callback); | 271 int rv = transport->Connect(&callback); |
| 302 if (rv == net::ERR_IO_PENDING) | 272 if (rv == net::ERR_IO_PENDING) |
| 303 rv = callback.WaitForResult(); | 273 rv = callback.WaitForResult(); |
| 304 EXPECT_EQ(net::OK, rv); | 274 EXPECT_EQ(net::OK, rv); |
| 305 | 275 |
| 306 scoped_ptr<net::SSLClientSocket> sock( | 276 scoped_ptr<net::SSLClientSocket> sock( |
| 307 socket_factory_->CreateSSLClientSocket( | 277 socket_factory_->CreateSSLClientSocket( |
| 308 transport, | 278 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 309 test_server.host_port_pair().host(), | 279 NULL)); |
| 310 kDefaultSSLConfig, | |
| 311 NULL /* ssl_host_info */)); | |
| 312 | 280 |
| 313 rv = sock->Connect(&callback); | 281 rv = sock->Connect(&callback); |
| 314 if (rv != net::OK) { | 282 if (rv == net::ERR_IO_PENDING) |
| 315 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
| 316 | |
| 317 rv = callback.WaitForResult(); | 283 rv = callback.WaitForResult(); |
| 318 EXPECT_EQ(net::OK, rv); | 284 EXPECT_EQ(net::OK, rv); |
| 319 } | |
| 320 EXPECT_TRUE(sock->IsConnected()); | 285 EXPECT_TRUE(sock->IsConnected()); |
| 321 | 286 |
| 322 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 287 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 323 scoped_refptr<net::IOBuffer> request_buffer( | 288 scoped_refptr<net::IOBuffer> request_buffer( |
| 324 new net::IOBuffer(arraysize(request_text) - 1)); | 289 new net::IOBuffer(arraysize(request_text) - 1)); |
| 325 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 290 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 326 | 291 |
| 327 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 292 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); |
| 328 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 293 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 329 | 294 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 359 | 324 |
| 360 net::ClientSocket* transport = new net::TCPClientSocket( | 325 net::ClientSocket* transport = new net::TCPClientSocket( |
| 361 addr, NULL, net::NetLog::Source()); | 326 addr, NULL, net::NetLog::Source()); |
| 362 int rv = transport->Connect(&callback); | 327 int rv = transport->Connect(&callback); |
| 363 if (rv == net::ERR_IO_PENDING) | 328 if (rv == net::ERR_IO_PENDING) |
| 364 rv = callback.WaitForResult(); | 329 rv = callback.WaitForResult(); |
| 365 EXPECT_EQ(net::OK, rv); | 330 EXPECT_EQ(net::OK, rv); |
| 366 | 331 |
| 367 scoped_ptr<net::SSLClientSocket> sock( | 332 scoped_ptr<net::SSLClientSocket> sock( |
| 368 socket_factory_->CreateSSLClientSocket( | 333 socket_factory_->CreateSSLClientSocket( |
| 369 transport, | 334 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 370 test_server.host_port_pair().host(), | 335 NULL)); |
| 371 kDefaultSSLConfig, | |
| 372 NULL /* ssl_host_info */)); | |
| 373 | 336 |
| 374 rv = sock->Connect(&callback); | 337 rv = sock->Connect(&callback); |
| 375 if (rv != net::OK) { | 338 if (rv != net::OK) |
|
wtc
2010/11/10 01:05:50
BUG: this should say
if (rv == net::ERR_IO_PENDI
| |
| 376 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
| 377 | |
| 378 rv = callback.WaitForResult(); | 339 rv = callback.WaitForResult(); |
| 379 EXPECT_EQ(net::OK, rv); | 340 EXPECT_EQ(net::OK, rv); |
| 380 } | |
| 381 EXPECT_TRUE(sock->IsConnected()); | 341 EXPECT_TRUE(sock->IsConnected()); |
| 382 | 342 |
| 383 // Issue a "hanging" Read first. | 343 // Issue a "hanging" Read first. |
| 384 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 344 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
| 385 rv = sock->Read(buf, 4096, &callback); | 345 rv = sock->Read(buf, 4096, &callback); |
| 386 // We haven't written the request, so there should be no response yet. | 346 // We haven't written the request, so there should be no response yet. |
| 387 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 347 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 388 | 348 |
| 389 // Write the request. | 349 // Write the request. |
| 390 // The request is padded with a User-Agent header to a size that causes the | 350 // The request is padded with a User-Agent header to a size that causes the |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 418 | 378 |
| 419 TestCompletionCallback callback; | 379 TestCompletionCallback callback; |
| 420 net::ClientSocket* transport = new net::TCPClientSocket( | 380 net::ClientSocket* transport = new net::TCPClientSocket( |
| 421 addr, NULL, net::NetLog::Source()); | 381 addr, NULL, net::NetLog::Source()); |
| 422 int rv = transport->Connect(&callback); | 382 int rv = transport->Connect(&callback); |
| 423 if (rv == net::ERR_IO_PENDING) | 383 if (rv == net::ERR_IO_PENDING) |
| 424 rv = callback.WaitForResult(); | 384 rv = callback.WaitForResult(); |
| 425 EXPECT_EQ(net::OK, rv); | 385 EXPECT_EQ(net::OK, rv); |
| 426 | 386 |
| 427 scoped_ptr<net::SSLClientSocket> sock( | 387 scoped_ptr<net::SSLClientSocket> sock( |
| 428 socket_factory_->CreateSSLClientSocket(transport, | 388 socket_factory_->CreateSSLClientSocket( |
| 429 test_server.host_port_pair().host(), kDefaultSSLConfig, | 389 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 430 NULL /* ssl_host_info */)); | 390 NULL)); |
| 431 | 391 |
| 432 rv = sock->Connect(&callback); | 392 rv = sock->Connect(&callback); |
| 433 if (rv != net::OK) { | 393 if (rv == net::ERR_IO_PENDING) |
| 434 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
| 435 | |
| 436 rv = callback.WaitForResult(); | 394 rv = callback.WaitForResult(); |
| 437 EXPECT_EQ(net::OK, rv); | 395 EXPECT_EQ(net::OK, rv); |
| 438 } | |
| 439 | 396 |
| 440 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 397 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 441 scoped_refptr<net::IOBuffer> request_buffer( | 398 scoped_refptr<net::IOBuffer> request_buffer( |
| 442 new net::IOBuffer(arraysize(request_text) - 1)); | 399 new net::IOBuffer(arraysize(request_text) - 1)); |
| 443 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 400 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 444 | 401 |
| 445 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 402 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); |
| 446 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 403 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 447 | 404 |
| 448 if (rv == net::ERR_IO_PENDING) | 405 if (rv == net::ERR_IO_PENDING) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 472 | 429 |
| 473 TestCompletionCallback callback; | 430 TestCompletionCallback callback; |
| 474 net::ClientSocket* transport = new net::TCPClientSocket( | 431 net::ClientSocket* transport = new net::TCPClientSocket( |
| 475 addr, NULL, net::NetLog::Source()); | 432 addr, NULL, net::NetLog::Source()); |
| 476 int rv = transport->Connect(&callback); | 433 int rv = transport->Connect(&callback); |
| 477 if (rv == net::ERR_IO_PENDING) | 434 if (rv == net::ERR_IO_PENDING) |
| 478 rv = callback.WaitForResult(); | 435 rv = callback.WaitForResult(); |
| 479 EXPECT_EQ(net::OK, rv); | 436 EXPECT_EQ(net::OK, rv); |
| 480 | 437 |
| 481 scoped_ptr<net::SSLClientSocket> sock( | 438 scoped_ptr<net::SSLClientSocket> sock( |
| 482 socket_factory_->CreateSSLClientSocket(transport, | 439 socket_factory_->CreateSSLClientSocket( |
| 483 test_server.host_port_pair().host(), kDefaultSSLConfig, | 440 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 484 NULL /* ssl_host_info */)); | 441 NULL)); |
| 485 | 442 |
| 486 rv = sock->Connect(&callback); | 443 rv = sock->Connect(&callback); |
| 487 if (rv != net::OK) { | 444 if (rv == net::ERR_IO_PENDING) |
| 488 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
| 489 | |
| 490 rv = callback.WaitForResult(); | 445 rv = callback.WaitForResult(); |
| 491 EXPECT_EQ(net::OK, rv); | 446 EXPECT_EQ(net::OK, rv); |
| 492 } | |
| 493 | 447 |
| 494 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 448 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 495 scoped_refptr<net::IOBuffer> request_buffer( | 449 scoped_refptr<net::IOBuffer> request_buffer( |
| 496 new net::IOBuffer(arraysize(request_text) - 1)); | 450 new net::IOBuffer(arraysize(request_text) - 1)); |
| 497 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 451 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 498 | 452 |
| 499 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 453 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); |
| 500 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 454 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 501 | 455 |
| 502 if (rv == net::ERR_IO_PENDING) | 456 if (rv == net::ERR_IO_PENDING) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 net::ClientSocket* transport = | 502 net::ClientSocket* transport = |
| 549 new net::MockTCPClientSocket(addr, NULL, &data); | 503 new net::MockTCPClientSocket(addr, NULL, &data); |
| 550 int rv = transport->Connect(&callback); | 504 int rv = transport->Connect(&callback); |
| 551 if (rv == net::ERR_IO_PENDING) | 505 if (rv == net::ERR_IO_PENDING) |
| 552 rv = callback.WaitForResult(); | 506 rv = callback.WaitForResult(); |
| 553 EXPECT_EQ(net::OK, rv); | 507 EXPECT_EQ(net::OK, rv); |
| 554 | 508 |
| 555 scoped_ptr<net::SSLClientSocket> sock( | 509 scoped_ptr<net::SSLClientSocket> sock( |
| 556 socket_factory_->CreateSSLClientSocket( | 510 socket_factory_->CreateSSLClientSocket( |
| 557 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, | 511 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 558 NULL /* ssl_host_info */)); | 512 NULL)); |
| 559 | 513 |
| 560 rv = sock->Connect(&callback); | 514 rv = sock->Connect(&callback); |
| 561 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | 515 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 562 } | 516 } |
| OLD | NEW |