| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/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_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 scoped_refptr<net::HostResolver> resolver_; | 52 scoped_refptr<net::HostResolver> resolver_; |
| 53 net::ClientSocketFactory* socket_factory_; | 53 net::ClientSocketFactory* socket_factory_; |
| 54 net::TestServerLauncher server_; | 54 net::TestServerLauncher server_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 //----------------------------------------------------------------------------- | 57 //----------------------------------------------------------------------------- |
| 58 | 58 |
| 59 #if defined(OS_MACOSX) | 59 TEST_F(SSLClientSocketTest, Connect) { |
| 60 // Status 6/19/09: | |
| 61 // | |
| 62 // If these tests are enabled on OSX, we choke at the point | |
| 63 // SSLHandshake() (Security framework call) is called from | |
| 64 // SSLClientSocketMac::DoHandshake(). Return value is -9812 (cert | |
| 65 // valid but root not trusted), but if you don't have the cert in your | |
| 66 // keychain as documented on | |
| 67 // http://dev.chromium.org/developers/testing, the -9812 becomes a | |
| 68 // -9813 (no root cert). | |
| 69 // | |
| 70 // See related handshake failures exhibited by disabled tests in | |
| 71 // net/url_request/url_request_unittest.cc. | |
| 72 #define MAYBE_Connect DISABLED_Connect | |
| 73 #define MAYBE_ConnectExpired DISABLED_ConnectExpired | |
| 74 #define MAYBE_ConnectMismatched DISABLED_ConnectMismatched | |
| 75 #define MAYBE_Read DISABLED_Read | |
| 76 #define MAYBE_Read_SmallChunks DISABLED_Read_SmallChunks | |
| 77 #define MAYBE_Read_Interrupted DISABLED_Read_Interrupted | |
| 78 #else | |
| 79 #define MAYBE_Connect Connect | |
| 80 #define MAYBE_ConnectExpired ConnectExpired | |
| 81 #define MAYBE_ConnectMismatched ConnectMismatched | |
| 82 #define MAYBE_Read Read | |
| 83 #define MAYBE_Read_SmallChunks Read_SmallChunks | |
| 84 #define MAYBE_Read_Interrupted Read_Interrupted | |
| 85 #endif | |
| 86 | |
| 87 TEST_F(SSLClientSocketTest, MAYBE_Connect) { | |
| 88 StartOKServer(); | 60 StartOKServer(); |
| 89 | 61 |
| 90 net::AddressList addr; | 62 net::AddressList addr; |
| 91 TestCompletionCallback callback; | 63 TestCompletionCallback callback; |
| 92 | 64 |
| 93 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); | 65 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); |
| 94 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); | 66 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); |
| 95 EXPECT_EQ(net::OK, rv); | 67 EXPECT_EQ(net::OK, rv); |
| 96 | 68 |
| 97 net::ClientSocket *transport = new net::TCPClientSocket(addr); | 69 net::ClientSocket *transport = new net::TCPClientSocket(addr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 114 rv = callback.WaitForResult(); | 86 rv = callback.WaitForResult(); |
| 115 EXPECT_EQ(net::OK, rv); | 87 EXPECT_EQ(net::OK, rv); |
| 116 } | 88 } |
| 117 | 89 |
| 118 EXPECT_TRUE(sock->IsConnected()); | 90 EXPECT_TRUE(sock->IsConnected()); |
| 119 | 91 |
| 120 sock->Disconnect(); | 92 sock->Disconnect(); |
| 121 EXPECT_FALSE(sock->IsConnected()); | 93 EXPECT_FALSE(sock->IsConnected()); |
| 122 } | 94 } |
| 123 | 95 |
| 124 TEST_F(SSLClientSocketTest, MAYBE_ConnectExpired) { | 96 TEST_F(SSLClientSocketTest, ConnectExpired) { |
| 125 StartExpiredServer(); | 97 StartExpiredServer(); |
| 126 | 98 |
| 127 net::AddressList addr; | 99 net::AddressList addr; |
| 128 TestCompletionCallback callback; | 100 TestCompletionCallback callback; |
| 129 | 101 |
| 130 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); | 102 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); |
| 131 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); | 103 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); |
| 132 EXPECT_EQ(net::OK, rv); | 104 EXPECT_EQ(net::OK, rv); |
| 133 | 105 |
| 134 net::ClientSocket *transport = new net::TCPClientSocket(addr); | 106 net::ClientSocket *transport = new net::TCPClientSocket(addr); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 150 | 122 |
| 151 rv = callback.WaitForResult(); | 123 rv = callback.WaitForResult(); |
| 152 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); | 124 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); |
| 153 } | 125 } |
| 154 | 126 |
| 155 // We cannot test sock->IsConnected(), as the NSS implementation disconnects | 127 // We cannot test sock->IsConnected(), as the NSS implementation disconnects |
| 156 // the socket when it encounters an error, whereas other implementations | 128 // the socket when it encounters an error, whereas other implementations |
| 157 // leave it connected. | 129 // leave it connected. |
| 158 } | 130 } |
| 159 | 131 |
| 160 TEST_F(SSLClientSocketTest, MAYBE_ConnectMismatched) { | 132 TEST_F(SSLClientSocketTest, ConnectMismatched) { |
| 161 StartMismatchedServer(); | 133 StartMismatchedServer(); |
| 162 | 134 |
| 163 net::AddressList addr; | 135 net::AddressList addr; |
| 164 TestCompletionCallback callback; | 136 TestCompletionCallback callback; |
| 165 | 137 |
| 166 net::HostResolver::RequestInfo info(server_.kMismatchedHostName, | 138 net::HostResolver::RequestInfo info(server_.kMismatchedHostName, |
| 167 server_.kOKHTTPSPort); | 139 server_.kOKHTTPSPort); |
| 168 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); | 140 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); |
| 169 EXPECT_EQ(net::OK, rv); | 141 EXPECT_EQ(net::OK, rv); |
| 170 | 142 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 192 // We cannot test sock->IsConnected(), as the NSS implementation disconnects | 164 // We cannot test sock->IsConnected(), as the NSS implementation disconnects |
| 193 // the socket when it encounters an error, whereas other implementations | 165 // the socket when it encounters an error, whereas other implementations |
| 194 // leave it connected. | 166 // leave it connected. |
| 195 } | 167 } |
| 196 | 168 |
| 197 // TODO(wtc): Add unit tests for IsConnectedAndIdle: | 169 // TODO(wtc): Add unit tests for IsConnectedAndIdle: |
| 198 // - Server closes an SSL connection (with a close_notify alert message). | 170 // - Server closes an SSL connection (with a close_notify alert message). |
| 199 // - Server closes the underlying TCP connection directly. | 171 // - Server closes the underlying TCP connection directly. |
| 200 // - Server sends data unexpectedly. | 172 // - Server sends data unexpectedly. |
| 201 | 173 |
| 202 TEST_F(SSLClientSocketTest, MAYBE_Read) { | 174 TEST_F(SSLClientSocketTest, Read) { |
| 203 StartOKServer(); | 175 StartOKServer(); |
| 204 | 176 |
| 205 net::AddressList addr; | 177 net::AddressList addr; |
| 206 TestCompletionCallback callback; | 178 TestCompletionCallback callback; |
| 207 | 179 |
| 208 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); | 180 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); |
| 209 int rv = resolver_->Resolve(info, &addr, &callback, NULL, NULL); | 181 int rv = resolver_->Resolve(info, &addr, &callback, NULL, NULL); |
| 210 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 182 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 211 | 183 |
| 212 rv = callback.WaitForResult(); | 184 rv = callback.WaitForResult(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 224 |
| 253 if (rv == net::ERR_IO_PENDING) | 225 if (rv == net::ERR_IO_PENDING) |
| 254 rv = callback.WaitForResult(); | 226 rv = callback.WaitForResult(); |
| 255 | 227 |
| 256 EXPECT_GE(rv, 0); | 228 EXPECT_GE(rv, 0); |
| 257 if (rv <= 0) | 229 if (rv <= 0) |
| 258 break; | 230 break; |
| 259 } | 231 } |
| 260 } | 232 } |
| 261 | 233 |
| 262 TEST_F(SSLClientSocketTest, MAYBE_Read_SmallChunks) { | 234 TEST_F(SSLClientSocketTest, Read_SmallChunks) { |
| 263 StartOKServer(); | 235 StartOKServer(); |
| 264 | 236 |
| 265 net::AddressList addr; | 237 net::AddressList addr; |
| 266 TestCompletionCallback callback; | 238 TestCompletionCallback callback; |
| 267 | 239 |
| 268 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); | 240 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); |
| 269 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); | 241 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); |
| 270 EXPECT_EQ(net::OK, rv); | 242 EXPECT_EQ(net::OK, rv); |
| 271 | 243 |
| 272 net::ClientSocket *transport = new net::TCPClientSocket(addr); | 244 net::ClientSocket *transport = new net::TCPClientSocket(addr); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 279 |
| 308 if (rv == net::ERR_IO_PENDING) | 280 if (rv == net::ERR_IO_PENDING) |
| 309 rv = callback.WaitForResult(); | 281 rv = callback.WaitForResult(); |
| 310 | 282 |
| 311 EXPECT_GE(rv, 0); | 283 EXPECT_GE(rv, 0); |
| 312 if (rv <= 0) | 284 if (rv <= 0) |
| 313 break; | 285 break; |
| 314 } | 286 } |
| 315 } | 287 } |
| 316 | 288 |
| 317 TEST_F(SSLClientSocketTest, MAYBE_Read_Interrupted) { | 289 TEST_F(SSLClientSocketTest, Read_Interrupted) { |
| 318 StartOKServer(); | 290 StartOKServer(); |
| 319 | 291 |
| 320 net::AddressList addr; | 292 net::AddressList addr; |
| 321 TestCompletionCallback callback; | 293 TestCompletionCallback callback; |
| 322 | 294 |
| 323 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); | 295 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); |
| 324 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); | 296 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); |
| 325 EXPECT_EQ(net::OK, rv); | 297 EXPECT_EQ(net::OK, rv); |
| 326 | 298 |
| 327 net::ClientSocket *transport = new net::TCPClientSocket(addr); | 299 net::ClientSocket *transport = new net::TCPClientSocket(addr); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 358 // Do a partial read and then exit. This test should not crash! | 330 // Do a partial read and then exit. This test should not crash! |
| 359 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512); | 331 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512); |
| 360 rv = sock->Read(buf, 512, &callback); | 332 rv = sock->Read(buf, 512, &callback); |
| 361 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 333 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 362 | 334 |
| 363 if (rv == net::ERR_IO_PENDING) | 335 if (rv == net::ERR_IO_PENDING) |
| 364 rv = callback.WaitForResult(); | 336 rv = callback.WaitForResult(); |
| 365 | 337 |
| 366 EXPECT_NE(rv, 0); | 338 EXPECT_NE(rv, 0); |
| 367 } | 339 } |
| OLD | NEW |