OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 namespace { | 71 namespace { |
72 | 72 |
73 // WrappedStreamSocket is a base class that wraps an existing StreamSocket, | 73 // WrappedStreamSocket is a base class that wraps an existing StreamSocket, |
74 // forwarding the Socket and StreamSocket interfaces to the underlying | 74 // forwarding the Socket and StreamSocket interfaces to the underlying |
75 // transport. | 75 // transport. |
76 // This is to provide a common base class for subclasses to override specific | 76 // This is to provide a common base class for subclasses to override specific |
77 // StreamSocket methods for testing, while still communicating with a 'real' | 77 // StreamSocket methods for testing, while still communicating with a 'real' |
78 // StreamSocket. | 78 // StreamSocket. |
79 class WrappedStreamSocket : public StreamSocket { | 79 class WrappedStreamSocket : public StreamSocket { |
80 public: | 80 public: |
81 explicit WrappedStreamSocket(scoped_ptr<StreamSocket> transport) | 81 explicit WrappedStreamSocket(std::unique_ptr<StreamSocket> transport) |
82 : transport_(std::move(transport)) {} | 82 : transport_(std::move(transport)) {} |
83 ~WrappedStreamSocket() override {} | 83 ~WrappedStreamSocket() override {} |
84 | 84 |
85 // StreamSocket implementation: | 85 // StreamSocket implementation: |
86 int Connect(const CompletionCallback& callback) override { | 86 int Connect(const CompletionCallback& callback) override { |
87 return transport_->Connect(callback); | 87 return transport_->Connect(callback); |
88 } | 88 } |
89 void Disconnect() override { transport_->Disconnect(); } | 89 void Disconnect() override { transport_->Disconnect(); } |
90 bool IsConnected() const override { return transport_->IsConnected(); } | 90 bool IsConnected() const override { return transport_->IsConnected(); } |
91 bool IsConnectedAndIdle() const override { | 91 bool IsConnectedAndIdle() const override { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 return transport_->Write(buf, buf_len, callback); | 137 return transport_->Write(buf, buf_len, callback); |
138 } | 138 } |
139 int SetReceiveBufferSize(int32_t size) override { | 139 int SetReceiveBufferSize(int32_t size) override { |
140 return transport_->SetReceiveBufferSize(size); | 140 return transport_->SetReceiveBufferSize(size); |
141 } | 141 } |
142 int SetSendBufferSize(int32_t size) override { | 142 int SetSendBufferSize(int32_t size) override { |
143 return transport_->SetSendBufferSize(size); | 143 return transport_->SetSendBufferSize(size); |
144 } | 144 } |
145 | 145 |
146 protected: | 146 protected: |
147 scoped_ptr<StreamSocket> transport_; | 147 std::unique_ptr<StreamSocket> transport_; |
148 }; | 148 }; |
149 | 149 |
150 // ReadBufferingStreamSocket is a wrapper for an existing StreamSocket that | 150 // ReadBufferingStreamSocket is a wrapper for an existing StreamSocket that |
151 // will ensure a certain amount of data is internally buffered before | 151 // will ensure a certain amount of data is internally buffered before |
152 // satisfying a Read() request. It exists to mimic OS-level internal | 152 // satisfying a Read() request. It exists to mimic OS-level internal |
153 // buffering, but in a way to guarantee that X number of bytes will be | 153 // buffering, but in a way to guarantee that X number of bytes will be |
154 // returned to callers of Read(), regardless of how quickly the OS receives | 154 // returned to callers of Read(), regardless of how quickly the OS receives |
155 // them from the TestServer. | 155 // them from the TestServer. |
156 class ReadBufferingStreamSocket : public WrappedStreamSocket { | 156 class ReadBufferingStreamSocket : public WrappedStreamSocket { |
157 public: | 157 public: |
158 explicit ReadBufferingStreamSocket(scoped_ptr<StreamSocket> transport); | 158 explicit ReadBufferingStreamSocket(std::unique_ptr<StreamSocket> transport); |
159 ~ReadBufferingStreamSocket() override {} | 159 ~ReadBufferingStreamSocket() override {} |
160 | 160 |
161 // Socket implementation: | 161 // Socket implementation: |
162 int Read(IOBuffer* buf, | 162 int Read(IOBuffer* buf, |
163 int buf_len, | 163 int buf_len, |
164 const CompletionCallback& callback) override; | 164 const CompletionCallback& callback) override; |
165 | 165 |
166 // Sets the internal buffer to |size|. This must not be greater than | 166 // Sets the internal buffer to |size|. This must not be greater than |
167 // the largest value supplied to Read() - that is, it does not handle | 167 // the largest value supplied to Read() - that is, it does not handle |
168 // having "leftovers" at the end of Read(). | 168 // having "leftovers" at the end of Read(). |
(...skipping 17 matching lines...) Expand all Loading... |
186 | 186 |
187 State state_; | 187 State state_; |
188 scoped_refptr<GrowableIOBuffer> read_buffer_; | 188 scoped_refptr<GrowableIOBuffer> read_buffer_; |
189 int buffer_size_; | 189 int buffer_size_; |
190 | 190 |
191 scoped_refptr<IOBuffer> user_read_buf_; | 191 scoped_refptr<IOBuffer> user_read_buf_; |
192 CompletionCallback user_read_callback_; | 192 CompletionCallback user_read_callback_; |
193 }; | 193 }; |
194 | 194 |
195 ReadBufferingStreamSocket::ReadBufferingStreamSocket( | 195 ReadBufferingStreamSocket::ReadBufferingStreamSocket( |
196 scoped_ptr<StreamSocket> transport) | 196 std::unique_ptr<StreamSocket> transport) |
197 : WrappedStreamSocket(std::move(transport)), | 197 : WrappedStreamSocket(std::move(transport)), |
198 read_buffer_(new GrowableIOBuffer()), | 198 read_buffer_(new GrowableIOBuffer()), |
199 buffer_size_(0) {} | 199 buffer_size_(0) {} |
200 | 200 |
201 void ReadBufferingStreamSocket::SetBufferSize(int size) { | 201 void ReadBufferingStreamSocket::SetBufferSize(int size) { |
202 DCHECK(!user_read_buf_.get()); | 202 DCHECK(!user_read_buf_.get()); |
203 buffer_size_ = size; | 203 buffer_size_ = size; |
204 read_buffer_->SetCapacity(size); | 204 read_buffer_->SetCapacity(size); |
205 } | 205 } |
206 | 206 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (result == ERR_IO_PENDING) | 278 if (result == ERR_IO_PENDING) |
279 return; | 279 return; |
280 | 280 |
281 user_read_buf_ = NULL; | 281 user_read_buf_ = NULL; |
282 base::ResetAndReturn(&user_read_callback_).Run(result); | 282 base::ResetAndReturn(&user_read_callback_).Run(result); |
283 } | 283 } |
284 | 284 |
285 // Simulates synchronously receiving an error during Read() or Write() | 285 // Simulates synchronously receiving an error during Read() or Write() |
286 class SynchronousErrorStreamSocket : public WrappedStreamSocket { | 286 class SynchronousErrorStreamSocket : public WrappedStreamSocket { |
287 public: | 287 public: |
288 explicit SynchronousErrorStreamSocket(scoped_ptr<StreamSocket> transport); | 288 explicit SynchronousErrorStreamSocket( |
| 289 std::unique_ptr<StreamSocket> transport); |
289 ~SynchronousErrorStreamSocket() override {} | 290 ~SynchronousErrorStreamSocket() override {} |
290 | 291 |
291 // Socket implementation: | 292 // Socket implementation: |
292 int Read(IOBuffer* buf, | 293 int Read(IOBuffer* buf, |
293 int buf_len, | 294 int buf_len, |
294 const CompletionCallback& callback) override; | 295 const CompletionCallback& callback) override; |
295 int Write(IOBuffer* buf, | 296 int Write(IOBuffer* buf, |
296 int buf_len, | 297 int buf_len, |
297 const CompletionCallback& callback) override; | 298 const CompletionCallback& callback) override; |
298 | 299 |
(...skipping 21 matching lines...) Expand all Loading... |
320 bool have_read_error_; | 321 bool have_read_error_; |
321 int pending_read_error_; | 322 int pending_read_error_; |
322 | 323 |
323 bool have_write_error_; | 324 bool have_write_error_; |
324 int pending_write_error_; | 325 int pending_write_error_; |
325 | 326 |
326 DISALLOW_COPY_AND_ASSIGN(SynchronousErrorStreamSocket); | 327 DISALLOW_COPY_AND_ASSIGN(SynchronousErrorStreamSocket); |
327 }; | 328 }; |
328 | 329 |
329 SynchronousErrorStreamSocket::SynchronousErrorStreamSocket( | 330 SynchronousErrorStreamSocket::SynchronousErrorStreamSocket( |
330 scoped_ptr<StreamSocket> transport) | 331 std::unique_ptr<StreamSocket> transport) |
331 : WrappedStreamSocket(std::move(transport)), | 332 : WrappedStreamSocket(std::move(transport)), |
332 have_read_error_(false), | 333 have_read_error_(false), |
333 pending_read_error_(OK), | 334 pending_read_error_(OK), |
334 have_write_error_(false), | 335 have_write_error_(false), |
335 pending_write_error_(OK) {} | 336 pending_write_error_(OK) {} |
336 | 337 |
337 int SynchronousErrorStreamSocket::Read(IOBuffer* buf, | 338 int SynchronousErrorStreamSocket::Read(IOBuffer* buf, |
338 int buf_len, | 339 int buf_len, |
339 const CompletionCallback& callback) { | 340 const CompletionCallback& callback) { |
340 if (have_read_error_) | 341 if (have_read_error_) |
341 return pending_read_error_; | 342 return pending_read_error_; |
342 return transport_->Read(buf, buf_len, callback); | 343 return transport_->Read(buf, buf_len, callback); |
343 } | 344 } |
344 | 345 |
345 int SynchronousErrorStreamSocket::Write(IOBuffer* buf, | 346 int SynchronousErrorStreamSocket::Write(IOBuffer* buf, |
346 int buf_len, | 347 int buf_len, |
347 const CompletionCallback& callback) { | 348 const CompletionCallback& callback) { |
348 if (have_write_error_) | 349 if (have_write_error_) |
349 return pending_write_error_; | 350 return pending_write_error_; |
350 return transport_->Write(buf, buf_len, callback); | 351 return transport_->Write(buf, buf_len, callback); |
351 } | 352 } |
352 | 353 |
353 // FakeBlockingStreamSocket wraps an existing StreamSocket and simulates the | 354 // FakeBlockingStreamSocket wraps an existing StreamSocket and simulates the |
354 // underlying transport needing to complete things asynchronously in a | 355 // underlying transport needing to complete things asynchronously in a |
355 // deterministic manner (e.g.: independent of the TestServer and the OS's | 356 // deterministic manner (e.g.: independent of the TestServer and the OS's |
356 // semantics). | 357 // semantics). |
357 class FakeBlockingStreamSocket : public WrappedStreamSocket { | 358 class FakeBlockingStreamSocket : public WrappedStreamSocket { |
358 public: | 359 public: |
359 explicit FakeBlockingStreamSocket(scoped_ptr<StreamSocket> transport); | 360 explicit FakeBlockingStreamSocket(std::unique_ptr<StreamSocket> transport); |
360 ~FakeBlockingStreamSocket() override {} | 361 ~FakeBlockingStreamSocket() override {} |
361 | 362 |
362 // Socket implementation: | 363 // Socket implementation: |
363 int Read(IOBuffer* buf, | 364 int Read(IOBuffer* buf, |
364 int buf_len, | 365 int buf_len, |
365 const CompletionCallback& callback) override; | 366 const CompletionCallback& callback) override; |
366 int Write(IOBuffer* buf, | 367 int Write(IOBuffer* buf, |
367 int buf_len, | 368 int buf_len, |
368 const CompletionCallback& callback) override; | 369 const CompletionCallback& callback) override; |
369 | 370 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 scoped_refptr<IOBuffer> pending_read_buf_; | 404 scoped_refptr<IOBuffer> pending_read_buf_; |
404 | 405 |
405 // The user callback for the pending read call. | 406 // The user callback for the pending read call. |
406 CompletionCallback pending_read_callback_; | 407 CompletionCallback pending_read_callback_; |
407 | 408 |
408 // The result for the blocked read callback, or ERR_IO_PENDING if not | 409 // The result for the blocked read callback, or ERR_IO_PENDING if not |
409 // completed. | 410 // completed. |
410 int pending_read_result_; | 411 int pending_read_result_; |
411 | 412 |
412 // WaitForReadResult() wait loop. | 413 // WaitForReadResult() wait loop. |
413 scoped_ptr<base::RunLoop> read_loop_; | 414 std::unique_ptr<base::RunLoop> read_loop_; |
414 | 415 |
415 // True if write calls are blocked. | 416 // True if write calls are blocked. |
416 bool should_block_write_; | 417 bool should_block_write_; |
417 | 418 |
418 // The buffer for the pending write, or NULL if not scheduled. | 419 // The buffer for the pending write, or NULL if not scheduled. |
419 scoped_refptr<IOBuffer> pending_write_buf_; | 420 scoped_refptr<IOBuffer> pending_write_buf_; |
420 | 421 |
421 // The callback for the pending write call. | 422 // The callback for the pending write call. |
422 CompletionCallback pending_write_callback_; | 423 CompletionCallback pending_write_callback_; |
423 | 424 |
424 // The length for the pending write, or -1 if not scheduled. | 425 // The length for the pending write, or -1 if not scheduled. |
425 int pending_write_len_; | 426 int pending_write_len_; |
426 | 427 |
427 // WaitForWrite() wait loop. | 428 // WaitForWrite() wait loop. |
428 scoped_ptr<base::RunLoop> write_loop_; | 429 std::unique_ptr<base::RunLoop> write_loop_; |
429 }; | 430 }; |
430 | 431 |
431 FakeBlockingStreamSocket::FakeBlockingStreamSocket( | 432 FakeBlockingStreamSocket::FakeBlockingStreamSocket( |
432 scoped_ptr<StreamSocket> transport) | 433 std::unique_ptr<StreamSocket> transport) |
433 : WrappedStreamSocket(std::move(transport)), | 434 : WrappedStreamSocket(std::move(transport)), |
434 should_block_read_(false), | 435 should_block_read_(false), |
435 pending_read_result_(ERR_IO_PENDING), | 436 pending_read_result_(ERR_IO_PENDING), |
436 should_block_write_(false), | 437 should_block_write_(false), |
437 pending_write_len_(-1) {} | 438 pending_write_len_(-1) {} |
438 | 439 |
439 int FakeBlockingStreamSocket::Read(IOBuffer* buf, | 440 int FakeBlockingStreamSocket::Read(IOBuffer* buf, |
440 int len, | 441 int len, |
441 const CompletionCallback& callback) { | 442 const CompletionCallback& callback) { |
442 DCHECK(!pending_read_buf_); | 443 DCHECK(!pending_read_buf_); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 // before the Read() completed. Either way, return the result to the caller. | 571 // before the Read() completed. Either way, return the result to the caller. |
571 pending_read_buf_ = nullptr; | 572 pending_read_buf_ = nullptr; |
572 base::ResetAndReturn(&pending_read_callback_).Run(result); | 573 base::ResetAndReturn(&pending_read_callback_).Run(result); |
573 } | 574 } |
574 } | 575 } |
575 | 576 |
576 // CountingStreamSocket wraps an existing StreamSocket and maintains a count of | 577 // CountingStreamSocket wraps an existing StreamSocket and maintains a count of |
577 // reads and writes on the socket. | 578 // reads and writes on the socket. |
578 class CountingStreamSocket : public WrappedStreamSocket { | 579 class CountingStreamSocket : public WrappedStreamSocket { |
579 public: | 580 public: |
580 explicit CountingStreamSocket(scoped_ptr<StreamSocket> transport) | 581 explicit CountingStreamSocket(std::unique_ptr<StreamSocket> transport) |
581 : WrappedStreamSocket(std::move(transport)), | 582 : WrappedStreamSocket(std::move(transport)), |
582 read_count_(0), | 583 read_count_(0), |
583 write_count_(0) {} | 584 write_count_(0) {} |
584 ~CountingStreamSocket() override {} | 585 ~CountingStreamSocket() override {} |
585 | 586 |
586 // Socket implementation: | 587 // Socket implementation: |
587 int Read(IOBuffer* buf, | 588 int Read(IOBuffer* buf, |
588 int buf_len, | 589 int buf_len, |
589 const CompletionCallback& callback) override { | 590 const CompletionCallback& callback) override { |
590 read_count_++; | 591 read_count_++; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 StreamSocket* socket_; | 632 StreamSocket* socket_; |
632 CompletionCallback callback_; | 633 CompletionCallback callback_; |
633 | 634 |
634 DISALLOW_COPY_AND_ASSIGN(DeleteSocketCallback); | 635 DISALLOW_COPY_AND_ASSIGN(DeleteSocketCallback); |
635 }; | 636 }; |
636 | 637 |
637 // A ChannelIDStore that always returns an error when asked for a | 638 // A ChannelIDStore that always returns an error when asked for a |
638 // channel id. | 639 // channel id. |
639 class FailingChannelIDStore : public ChannelIDStore { | 640 class FailingChannelIDStore : public ChannelIDStore { |
640 int GetChannelID(const std::string& server_identifier, | 641 int GetChannelID(const std::string& server_identifier, |
641 scoped_ptr<crypto::ECPrivateKey>* key_result, | 642 std::unique_ptr<crypto::ECPrivateKey>* key_result, |
642 const GetChannelIDCallback& callback) override { | 643 const GetChannelIDCallback& callback) override { |
643 return ERR_UNEXPECTED; | 644 return ERR_UNEXPECTED; |
644 } | 645 } |
645 void SetChannelID(scoped_ptr<ChannelID> channel_id) override {} | 646 void SetChannelID(std::unique_ptr<ChannelID> channel_id) override {} |
646 void DeleteChannelID(const std::string& server_identifier, | 647 void DeleteChannelID(const std::string& server_identifier, |
647 const base::Closure& completion_callback) override {} | 648 const base::Closure& completion_callback) override {} |
648 void DeleteAllCreatedBetween( | 649 void DeleteAllCreatedBetween( |
649 base::Time delete_begin, | 650 base::Time delete_begin, |
650 base::Time delete_end, | 651 base::Time delete_end, |
651 const base::Closure& completion_callback) override {} | 652 const base::Closure& completion_callback) override {} |
652 void DeleteAll(const base::Closure& completion_callback) override {} | 653 void DeleteAll(const base::Closure& completion_callback) override {} |
653 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override {} | 654 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override {} |
654 int GetChannelIDCount() override { return 0; } | 655 int GetChannelIDCount() override { return 0; } |
655 void SetForceKeepSessionState() override {} | 656 void SetForceKeepSessionState() override {} |
656 bool IsEphemeral() override { return true; } | 657 bool IsEphemeral() override { return true; } |
657 }; | 658 }; |
658 | 659 |
659 // A ChannelIDStore that asynchronously returns an error when asked for a | 660 // A ChannelIDStore that asynchronously returns an error when asked for a |
660 // channel id. | 661 // channel id. |
661 class AsyncFailingChannelIDStore : public ChannelIDStore { | 662 class AsyncFailingChannelIDStore : public ChannelIDStore { |
662 int GetChannelID(const std::string& server_identifier, | 663 int GetChannelID(const std::string& server_identifier, |
663 scoped_ptr<crypto::ECPrivateKey>* key_result, | 664 std::unique_ptr<crypto::ECPrivateKey>* key_result, |
664 const GetChannelIDCallback& callback) override { | 665 const GetChannelIDCallback& callback) override { |
665 base::ThreadTaskRunnerHandle::Get()->PostTask( | 666 base::ThreadTaskRunnerHandle::Get()->PostTask( |
666 FROM_HERE, | 667 FROM_HERE, |
667 base::Bind(callback, ERR_UNEXPECTED, server_identifier, nullptr)); | 668 base::Bind(callback, ERR_UNEXPECTED, server_identifier, nullptr)); |
668 return ERR_IO_PENDING; | 669 return ERR_IO_PENDING; |
669 } | 670 } |
670 void SetChannelID(scoped_ptr<ChannelID> channel_id) override {} | 671 void SetChannelID(std::unique_ptr<ChannelID> channel_id) override {} |
671 void DeleteChannelID(const std::string& server_identifier, | 672 void DeleteChannelID(const std::string& server_identifier, |
672 const base::Closure& completion_callback) override {} | 673 const base::Closure& completion_callback) override {} |
673 void DeleteAllCreatedBetween( | 674 void DeleteAllCreatedBetween( |
674 base::Time delete_begin, | 675 base::Time delete_begin, |
675 base::Time delete_end, | 676 base::Time delete_end, |
676 const base::Closure& completion_callback) override {} | 677 const base::Closure& completion_callback) override {} |
677 void DeleteAll(const base::Closure& completion_callback) override {} | 678 void DeleteAll(const base::Closure& completion_callback) override {} |
678 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override {} | 679 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override {} |
679 int GetChannelIDCount() override { return 0; } | 680 int GetChannelIDCount() override { return 0; } |
680 void SetForceKeepSessionState() override {} | 681 void SetForceKeepSessionState() override {} |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 return false; | 746 return false; |
746 } | 747 } |
747 | 748 |
748 if (!spawned_test_server_->GetAddressList(&addr_)) { | 749 if (!spawned_test_server_->GetAddressList(&addr_)) { |
749 LOG(ERROR) << "Could not get SpawnedTestServer address list"; | 750 LOG(ERROR) << "Could not get SpawnedTestServer address list"; |
750 return false; | 751 return false; |
751 } | 752 } |
752 return true; | 753 return true; |
753 } | 754 } |
754 | 755 |
755 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 756 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
756 scoped_ptr<StreamSocket> transport_socket, | 757 std::unique_ptr<StreamSocket> transport_socket, |
757 const HostPortPair& host_and_port, | 758 const HostPortPair& host_and_port, |
758 const SSLConfig& ssl_config) { | 759 const SSLConfig& ssl_config) { |
759 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 760 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
760 connection->SetSocket(std::move(transport_socket)); | 761 connection->SetSocket(std::move(transport_socket)); |
761 return socket_factory_->CreateSSLClientSocket( | 762 return socket_factory_->CreateSSLClientSocket( |
762 std::move(connection), host_and_port, ssl_config, context_); | 763 std::move(connection), host_and_port, ssl_config, context_); |
763 } | 764 } |
764 | 765 |
765 // Create an SSLClientSocket object and use it to connect to a test | 766 // Create an SSLClientSocket object and use it to connect to a test |
766 // server, then wait for connection results. This must be called after | 767 // server, then wait for connection results. This must be called after |
767 // a successful StartTestServer() call. | 768 // a successful StartTestServer() call. |
768 // |ssl_config| the SSL configuration to use. | 769 // |ssl_config| the SSL configuration to use. |
769 // |result| will retrieve the ::Connect() result value. | 770 // |result| will retrieve the ::Connect() result value. |
770 // Returns true on success, false otherwise. Success means that the SSL socket | 771 // Returns true on success, false otherwise. Success means that the SSL socket |
771 // could be created and its Connect() was called, not that the connection | 772 // could be created and its Connect() was called, not that the connection |
772 // itself was a success. | 773 // itself was a success. |
773 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, | 774 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, |
774 int* result) { | 775 int* result) { |
775 scoped_ptr<StreamSocket> transport( | 776 std::unique_ptr<StreamSocket> transport( |
776 new TCPClientSocket(addr_, NULL, &log_, NetLog::Source())); | 777 new TCPClientSocket(addr_, NULL, &log_, NetLog::Source())); |
777 int rv = callback_.GetResult(transport->Connect(callback_.callback())); | 778 int rv = callback_.GetResult(transport->Connect(callback_.callback())); |
778 if (rv != OK) { | 779 if (rv != OK) { |
779 LOG(ERROR) << "Could not connect to SpawnedTestServer"; | 780 LOG(ERROR) << "Could not connect to SpawnedTestServer"; |
780 return false; | 781 return false; |
781 } | 782 } |
782 | 783 |
783 sock_ = CreateSSLClientSocket(std::move(transport), | 784 sock_ = CreateSSLClientSocket(std::move(transport), |
784 spawned_test_server_->host_port_pair(), | 785 spawned_test_server_->host_port_pair(), |
785 ssl_config); | 786 ssl_config); |
(...skipping 12 matching lines...) Expand all Loading... |
798 scoped_refptr<X509Certificate> server_cert = | 799 scoped_refptr<X509Certificate> server_cert = |
799 spawned_test_server()->GetCertificate(); | 800 spawned_test_server()->GetCertificate(); |
800 // Get the MockCertVerifier to verify it as an EV cert. | 801 // Get the MockCertVerifier to verify it as an EV cert. |
801 CertVerifyResult verify_result; | 802 CertVerifyResult verify_result; |
802 verify_result.cert_status = status; | 803 verify_result.cert_status = status; |
803 verify_result.verified_cert = server_cert; | 804 verify_result.verified_cert = server_cert; |
804 cert_verifier_->AddResultForCert(server_cert.get(), verify_result, OK); | 805 cert_verifier_->AddResultForCert(server_cert.get(), verify_result, OK); |
805 } | 806 } |
806 | 807 |
807 ClientSocketFactory* socket_factory_; | 808 ClientSocketFactory* socket_factory_; |
808 scoped_ptr<MockCertVerifier> cert_verifier_; | 809 std::unique_ptr<MockCertVerifier> cert_verifier_; |
809 scoped_ptr<TransportSecurityState> transport_security_state_; | 810 std::unique_ptr<TransportSecurityState> transport_security_state_; |
810 SSLClientSocketContext context_; | 811 SSLClientSocketContext context_; |
811 scoped_ptr<SSLClientSocket> sock_; | 812 std::unique_ptr<SSLClientSocket> sock_; |
812 TestNetLog log_; | 813 TestNetLog log_; |
813 | 814 |
814 private: | 815 private: |
815 scoped_ptr<SpawnedTestServer> spawned_test_server_; | 816 std::unique_ptr<SpawnedTestServer> spawned_test_server_; |
816 TestCompletionCallback callback_; | 817 TestCompletionCallback callback_; |
817 AddressList addr_; | 818 AddressList addr_; |
818 }; | 819 }; |
819 | 820 |
820 // Verifies the correctness of GetSSLCertRequestInfo. | 821 // Verifies the correctness of GetSSLCertRequestInfo. |
821 class SSLClientSocketCertRequestInfoTest : public SSLClientSocketTest { | 822 class SSLClientSocketCertRequestInfoTest : public SSLClientSocketTest { |
822 protected: | 823 protected: |
823 // Creates a test server with the given SSLOptions, connects to it and returns | 824 // Creates a test server with the given SSLOptions, connects to it and returns |
824 // the SSLCertRequestInfo reported by the socket. | 825 // the SSLCertRequestInfo reported by the socket. |
825 scoped_refptr<SSLCertRequestInfo> GetCertRequest( | 826 scoped_refptr<SSLCertRequestInfo> GetCertRequest( |
826 SpawnedTestServer::SSLOptions ssl_options) { | 827 SpawnedTestServer::SSLOptions ssl_options) { |
827 SpawnedTestServer spawned_test_server(SpawnedTestServer::TYPE_HTTPS, | 828 SpawnedTestServer spawned_test_server(SpawnedTestServer::TYPE_HTTPS, |
828 ssl_options, base::FilePath()); | 829 ssl_options, base::FilePath()); |
829 if (!spawned_test_server.Start()) | 830 if (!spawned_test_server.Start()) |
830 return NULL; | 831 return NULL; |
831 | 832 |
832 AddressList addr; | 833 AddressList addr; |
833 if (!spawned_test_server.GetAddressList(&addr)) | 834 if (!spawned_test_server.GetAddressList(&addr)) |
834 return NULL; | 835 return NULL; |
835 | 836 |
836 TestCompletionCallback callback; | 837 TestCompletionCallback callback; |
837 TestNetLog log; | 838 TestNetLog log; |
838 scoped_ptr<StreamSocket> transport( | 839 std::unique_ptr<StreamSocket> transport( |
839 new TCPClientSocket(addr, NULL, &log, NetLog::Source())); | 840 new TCPClientSocket(addr, NULL, &log, NetLog::Source())); |
840 int rv = callback.GetResult(transport->Connect(callback.callback())); | 841 int rv = callback.GetResult(transport->Connect(callback.callback())); |
841 EXPECT_EQ(OK, rv); | 842 EXPECT_EQ(OK, rv); |
842 | 843 |
843 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 844 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
844 std::move(transport), spawned_test_server.host_port_pair(), | 845 std::move(transport), spawned_test_server.host_port_pair(), |
845 SSLConfig())); | 846 SSLConfig())); |
846 EXPECT_FALSE(sock->IsConnected()); | 847 EXPECT_FALSE(sock->IsConnected()); |
847 | 848 |
848 rv = callback.GetResult(sock->Connect(callback.callback())); | 849 rv = callback.GetResult(sock->Connect(callback.callback())); |
849 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | 850 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
850 | 851 |
851 scoped_refptr<SSLCertRequestInfo> request_info = new SSLCertRequestInfo(); | 852 scoped_refptr<SSLCertRequestInfo> request_info = new SSLCertRequestInfo(); |
852 sock->GetSSLCertRequestInfo(request_info.get()); | 853 sock->GetSSLCertRequestInfo(request_info.get()); |
853 sock->Disconnect(); | 854 sock->Disconnect(); |
(...skipping 17 matching lines...) Expand all Loading... |
871 // in |*out_raw_transport|. To complete the handshake and successfully read | 872 // in |*out_raw_transport|. To complete the handshake and successfully read |
872 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if | 873 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if |
873 // the client successfully false started, |callback.WaitForResult()| will | 874 // the client successfully false started, |callback.WaitForResult()| will |
874 // return OK without unblocking transport reads. But Read() will still block.) | 875 // return OK without unblocking transport reads. But Read() will still block.) |
875 // | 876 // |
876 // Must be called after StartTestServer is called. | 877 // Must be called after StartTestServer is called. |
877 void CreateAndConnectUntilServerFinishedReceived( | 878 void CreateAndConnectUntilServerFinishedReceived( |
878 const SSLConfig& client_config, | 879 const SSLConfig& client_config, |
879 TestCompletionCallback* callback, | 880 TestCompletionCallback* callback, |
880 FakeBlockingStreamSocket** out_raw_transport, | 881 FakeBlockingStreamSocket** out_raw_transport, |
881 scoped_ptr<SSLClientSocket>* out_sock) { | 882 std::unique_ptr<SSLClientSocket>* out_sock) { |
882 CHECK(spawned_test_server()); | 883 CHECK(spawned_test_server()); |
883 | 884 |
884 scoped_ptr<StreamSocket> real_transport( | 885 std::unique_ptr<StreamSocket> real_transport( |
885 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 886 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
886 scoped_ptr<FakeBlockingStreamSocket> transport( | 887 std::unique_ptr<FakeBlockingStreamSocket> transport( |
887 new FakeBlockingStreamSocket(std::move(real_transport))); | 888 new FakeBlockingStreamSocket(std::move(real_transport))); |
888 int rv = callback->GetResult(transport->Connect(callback->callback())); | 889 int rv = callback->GetResult(transport->Connect(callback->callback())); |
889 EXPECT_EQ(OK, rv); | 890 EXPECT_EQ(OK, rv); |
890 | 891 |
891 FakeBlockingStreamSocket* raw_transport = transport.get(); | 892 FakeBlockingStreamSocket* raw_transport = transport.get(); |
892 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 893 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
893 std::move(transport), spawned_test_server()->host_port_pair(), | 894 std::move(transport), spawned_test_server()->host_port_pair(), |
894 client_config); | 895 client_config); |
895 | 896 |
896 // Connect. Stop before the client processes the first server leg | 897 // Connect. Stop before the client processes the first server leg |
897 // (ServerHello, etc.) | 898 // (ServerHello, etc.) |
898 raw_transport->BlockReadResult(); | 899 raw_transport->BlockReadResult(); |
899 rv = sock->Connect(callback->callback()); | 900 rv = sock->Connect(callback->callback()); |
900 EXPECT_EQ(ERR_IO_PENDING, rv); | 901 EXPECT_EQ(ERR_IO_PENDING, rv); |
901 raw_transport->WaitForReadResult(); | 902 raw_transport->WaitForReadResult(); |
902 | 903 |
(...skipping 14 matching lines...) Expand all Loading... |
917 *out_sock = std::move(sock); | 918 *out_sock = std::move(sock); |
918 } | 919 } |
919 | 920 |
920 void TestFalseStart(const SpawnedTestServer::SSLOptions& server_options, | 921 void TestFalseStart(const SpawnedTestServer::SSLOptions& server_options, |
921 const SSLConfig& client_config, | 922 const SSLConfig& client_config, |
922 bool expect_false_start) { | 923 bool expect_false_start) { |
923 ASSERT_TRUE(StartTestServer(server_options)); | 924 ASSERT_TRUE(StartTestServer(server_options)); |
924 | 925 |
925 TestCompletionCallback callback; | 926 TestCompletionCallback callback; |
926 FakeBlockingStreamSocket* raw_transport = NULL; | 927 FakeBlockingStreamSocket* raw_transport = NULL; |
927 scoped_ptr<SSLClientSocket> sock; | 928 std::unique_ptr<SSLClientSocket> sock; |
928 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 929 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
929 client_config, &callback, &raw_transport, &sock)); | 930 client_config, &callback, &raw_transport, &sock)); |
930 | 931 |
931 if (expect_false_start) { | 932 if (expect_false_start) { |
932 // When False Starting, the handshake should complete before receiving the | 933 // When False Starting, the handshake should complete before receiving the |
933 // Change Cipher Spec and Finished messages. | 934 // Change Cipher Spec and Finished messages. |
934 // | 935 // |
935 // Note: callback.have_result() may not be true without waiting. The NSS | 936 // Note: callback.have_result() may not be true without waiting. The NSS |
936 // state machine sometimes lives on a separate thread, so this thread may | 937 // state machine sometimes lives on a separate thread, so this thread may |
937 // not yet have processed the signal that the handshake has completed. | 938 // not yet have processed the signal that the handshake has completed. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 context_.channel_id_service = channel_id_service_.get(); | 984 context_.channel_id_service = channel_id_service_.get(); |
984 } | 985 } |
985 | 986 |
986 void EnableAsyncFailingChannelID() { | 987 void EnableAsyncFailingChannelID() { |
987 channel_id_service_.reset(new ChannelIDService( | 988 channel_id_service_.reset(new ChannelIDService( |
988 new AsyncFailingChannelIDStore(), base::ThreadTaskRunnerHandle::Get())); | 989 new AsyncFailingChannelIDStore(), base::ThreadTaskRunnerHandle::Get())); |
989 context_.channel_id_service = channel_id_service_.get(); | 990 context_.channel_id_service = channel_id_service_.get(); |
990 } | 991 } |
991 | 992 |
992 private: | 993 private: |
993 scoped_ptr<ChannelIDService> channel_id_service_; | 994 std::unique_ptr<ChannelIDService> channel_id_service_; |
994 }; | 995 }; |
995 | 996 |
996 } // namespace | 997 } // namespace |
997 | 998 |
998 TEST_F(SSLClientSocketTest, Connect) { | 999 TEST_F(SSLClientSocketTest, Connect) { |
999 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1000 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1000 | 1001 |
1001 TestCompletionCallback callback; | 1002 TestCompletionCallback callback; |
1002 TestNetLog log; | 1003 TestNetLog log; |
1003 scoped_ptr<StreamSocket> transport( | 1004 std::unique_ptr<StreamSocket> transport( |
1004 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); | 1005 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); |
1005 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1006 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1006 EXPECT_EQ(OK, rv); | 1007 EXPECT_EQ(OK, rv); |
1007 | 1008 |
1008 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1009 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1009 std::move(transport), spawned_test_server()->host_port_pair(), | 1010 std::move(transport), spawned_test_server()->host_port_pair(), |
1010 SSLConfig())); | 1011 SSLConfig())); |
1011 | 1012 |
1012 EXPECT_FALSE(sock->IsConnected()); | 1013 EXPECT_FALSE(sock->IsConnected()); |
1013 | 1014 |
1014 rv = sock->Connect(callback.callback()); | 1015 rv = sock->Connect(callback.callback()); |
1015 | 1016 |
1016 TestNetLogEntry::List entries; | 1017 TestNetLogEntry::List entries; |
1017 log.GetEntries(&entries); | 1018 log.GetEntries(&entries); |
1018 EXPECT_TRUE(LogContainsBeginEvent(entries, 5, NetLog::TYPE_SSL_CONNECT)); | 1019 EXPECT_TRUE(LogContainsBeginEvent(entries, 5, NetLog::TYPE_SSL_CONNECT)); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 // - Server closes an SSL connection (with a close_notify alert message). | 1140 // - Server closes an SSL connection (with a close_notify alert message). |
1140 // - Server closes the underlying TCP connection directly. | 1141 // - Server closes the underlying TCP connection directly. |
1141 // - Server sends data unexpectedly. | 1142 // - Server sends data unexpectedly. |
1142 | 1143 |
1143 // Tests that the socket can be read from successfully. Also test that a peer's | 1144 // Tests that the socket can be read from successfully. Also test that a peer's |
1144 // close_notify alert is successfully processed without error. | 1145 // close_notify alert is successfully processed without error. |
1145 TEST_F(SSLClientSocketTest, Read) { | 1146 TEST_F(SSLClientSocketTest, Read) { |
1146 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1147 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1147 | 1148 |
1148 TestCompletionCallback callback; | 1149 TestCompletionCallback callback; |
1149 scoped_ptr<StreamSocket> transport( | 1150 std::unique_ptr<StreamSocket> transport( |
1150 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1151 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1151 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); | 1152 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); |
1152 | 1153 |
1153 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1154 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1154 EXPECT_EQ(OK, rv); | 1155 EXPECT_EQ(OK, rv); |
1155 | 1156 |
1156 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1157 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1157 std::move(transport), spawned_test_server()->host_port_pair(), | 1158 std::move(transport), spawned_test_server()->host_port_pair(), |
1158 SSLConfig())); | 1159 SSLConfig())); |
1159 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); | 1160 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); |
1160 | 1161 |
1161 rv = callback.GetResult(sock->Connect(callback.callback())); | 1162 rv = callback.GetResult(sock->Connect(callback.callback())); |
1162 EXPECT_EQ(OK, rv); | 1163 EXPECT_EQ(OK, rv); |
1163 | 1164 |
1164 // Number of network bytes received should increase because of SSL socket | 1165 // Number of network bytes received should increase because of SSL socket |
1165 // establishment. | 1166 // establishment. |
1166 EXPECT_GT(sock->GetTotalReceivedBytes(), 0); | 1167 EXPECT_GT(sock->GetTotalReceivedBytes(), 0); |
(...skipping 29 matching lines...) Expand all Loading... |
1196 EXPECT_EQ(0, rv); | 1197 EXPECT_EQ(0, rv); |
1197 } | 1198 } |
1198 | 1199 |
1199 // Tests that SSLClientSocket properly handles when the underlying transport | 1200 // Tests that SSLClientSocket properly handles when the underlying transport |
1200 // synchronously fails a transport read in during the handshake. The error code | 1201 // synchronously fails a transport read in during the handshake. The error code |
1201 // should be preserved so SSLv3 fallback logic can condition on it. | 1202 // should be preserved so SSLv3 fallback logic can condition on it. |
1202 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { | 1203 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { |
1203 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1204 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1204 | 1205 |
1205 TestCompletionCallback callback; | 1206 TestCompletionCallback callback; |
1206 scoped_ptr<StreamSocket> real_transport( | 1207 std::unique_ptr<StreamSocket> real_transport( |
1207 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1208 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1208 scoped_ptr<SynchronousErrorStreamSocket> transport( | 1209 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
1209 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1210 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1210 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1211 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1211 EXPECT_EQ(OK, rv); | 1212 EXPECT_EQ(OK, rv); |
1212 | 1213 |
1213 // Disable TLS False Start to avoid handshake non-determinism. | 1214 // Disable TLS False Start to avoid handshake non-determinism. |
1214 SSLConfig ssl_config; | 1215 SSLConfig ssl_config; |
1215 ssl_config.false_start_enabled = false; | 1216 ssl_config.false_start_enabled = false; |
1216 | 1217 |
1217 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1218 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
1218 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1219 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1219 std::move(transport), spawned_test_server()->host_port_pair(), | 1220 std::move(transport), spawned_test_server()->host_port_pair(), |
1220 ssl_config)); | 1221 ssl_config)); |
1221 | 1222 |
1222 raw_transport->SetNextWriteError(ERR_CONNECTION_RESET); | 1223 raw_transport->SetNextWriteError(ERR_CONNECTION_RESET); |
1223 | 1224 |
1224 rv = callback.GetResult(sock->Connect(callback.callback())); | 1225 rv = callback.GetResult(sock->Connect(callback.callback())); |
1225 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 1226 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
1226 EXPECT_FALSE(sock->IsConnected()); | 1227 EXPECT_FALSE(sock->IsConnected()); |
1227 } | 1228 } |
1228 | 1229 |
1229 // Tests that the SSLClientSocket properly handles when the underlying transport | 1230 // Tests that the SSLClientSocket properly handles when the underlying transport |
1230 // synchronously returns an error code - such as if an intermediary terminates | 1231 // synchronously returns an error code - such as if an intermediary terminates |
1231 // the socket connection uncleanly. | 1232 // the socket connection uncleanly. |
1232 // This is a regression test for http://crbug.com/238536 | 1233 // This is a regression test for http://crbug.com/238536 |
1233 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { | 1234 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { |
1234 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1235 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1235 | 1236 |
1236 TestCompletionCallback callback; | 1237 TestCompletionCallback callback; |
1237 scoped_ptr<StreamSocket> real_transport( | 1238 std::unique_ptr<StreamSocket> real_transport( |
1238 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1239 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1239 scoped_ptr<SynchronousErrorStreamSocket> transport( | 1240 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
1240 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1241 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1241 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1242 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1242 EXPECT_EQ(OK, rv); | 1243 EXPECT_EQ(OK, rv); |
1243 | 1244 |
1244 // Disable TLS False Start to avoid handshake non-determinism. | 1245 // Disable TLS False Start to avoid handshake non-determinism. |
1245 SSLConfig ssl_config; | 1246 SSLConfig ssl_config; |
1246 ssl_config.false_start_enabled = false; | 1247 ssl_config.false_start_enabled = false; |
1247 | 1248 |
1248 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1249 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
1249 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1250 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1250 std::move(transport), spawned_test_server()->host_port_pair(), | 1251 std::move(transport), spawned_test_server()->host_port_pair(), |
1251 ssl_config)); | 1252 ssl_config)); |
1252 | 1253 |
1253 rv = callback.GetResult(sock->Connect(callback.callback())); | 1254 rv = callback.GetResult(sock->Connect(callback.callback())); |
1254 EXPECT_EQ(OK, rv); | 1255 EXPECT_EQ(OK, rv); |
1255 EXPECT_TRUE(sock->IsConnected()); | 1256 EXPECT_TRUE(sock->IsConnected()); |
1256 | 1257 |
1257 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1258 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1258 static const int kRequestTextSize = | 1259 static const int kRequestTextSize = |
1259 static_cast<int>(arraysize(request_text) - 1); | 1260 static_cast<int>(arraysize(request_text) - 1); |
(...skipping 17 matching lines...) Expand all Loading... |
1277 } | 1278 } |
1278 | 1279 |
1279 // Tests that the SSLClientSocket properly handles when the underlying transport | 1280 // Tests that the SSLClientSocket properly handles when the underlying transport |
1280 // asynchronously returns an error code while writing data - such as if an | 1281 // asynchronously returns an error code while writing data - such as if an |
1281 // intermediary terminates the socket connection uncleanly. | 1282 // intermediary terminates the socket connection uncleanly. |
1282 // This is a regression test for http://crbug.com/249848 | 1283 // This is a regression test for http://crbug.com/249848 |
1283 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { | 1284 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { |
1284 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1285 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1285 | 1286 |
1286 TestCompletionCallback callback; | 1287 TestCompletionCallback callback; |
1287 scoped_ptr<StreamSocket> real_transport( | 1288 std::unique_ptr<StreamSocket> real_transport( |
1288 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1289 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1289 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1290 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
1290 // is retained in order to configure additional errors. | 1291 // is retained in order to configure additional errors. |
1291 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | 1292 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
1292 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1293 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1293 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1294 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
1294 scoped_ptr<FakeBlockingStreamSocket> transport( | 1295 std::unique_ptr<FakeBlockingStreamSocket> transport( |
1295 new FakeBlockingStreamSocket(std::move(error_socket))); | 1296 new FakeBlockingStreamSocket(std::move(error_socket))); |
1296 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1297 FakeBlockingStreamSocket* raw_transport = transport.get(); |
1297 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1298 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1298 EXPECT_EQ(OK, rv); | 1299 EXPECT_EQ(OK, rv); |
1299 | 1300 |
1300 // Disable TLS False Start to avoid handshake non-determinism. | 1301 // Disable TLS False Start to avoid handshake non-determinism. |
1301 SSLConfig ssl_config; | 1302 SSLConfig ssl_config; |
1302 ssl_config.false_start_enabled = false; | 1303 ssl_config.false_start_enabled = false; |
1303 | 1304 |
1304 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1305 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1305 std::move(transport), spawned_test_server()->host_port_pair(), | 1306 std::move(transport), spawned_test_server()->host_port_pair(), |
1306 ssl_config)); | 1307 ssl_config)); |
1307 | 1308 |
1308 rv = callback.GetResult(sock->Connect(callback.callback())); | 1309 rv = callback.GetResult(sock->Connect(callback.callback())); |
1309 EXPECT_EQ(OK, rv); | 1310 EXPECT_EQ(OK, rv); |
1310 EXPECT_TRUE(sock->IsConnected()); | 1311 EXPECT_TRUE(sock->IsConnected()); |
1311 | 1312 |
1312 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1313 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1313 static const int kRequestTextSize = | 1314 static const int kRequestTextSize = |
1314 static_cast<int>(arraysize(request_text) - 1); | 1315 static_cast<int>(arraysize(request_text) - 1); |
(...skipping 29 matching lines...) Expand all Loading... |
1344 } | 1345 } |
1345 | 1346 |
1346 // If there is a Write failure at the transport with no follow-up Read, although | 1347 // If there is a Write failure at the transport with no follow-up Read, although |
1347 // the write error will not be returned to the client until a future Read or | 1348 // the write error will not be returned to the client until a future Read or |
1348 // Write operation, SSLClientSocket should not spin attempting to re-write on | 1349 // Write operation, SSLClientSocket should not spin attempting to re-write on |
1349 // the socket. This is a regression test for part of https://crbug.com/381160. | 1350 // the socket. This is a regression test for part of https://crbug.com/381160. |
1350 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { | 1351 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { |
1351 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1352 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1352 | 1353 |
1353 TestCompletionCallback callback; | 1354 TestCompletionCallback callback; |
1354 scoped_ptr<StreamSocket> real_transport( | 1355 std::unique_ptr<StreamSocket> real_transport( |
1355 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1356 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1356 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer | 1357 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer |
1357 // is retained in order to query them. | 1358 // is retained in order to query them. |
1358 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | 1359 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
1359 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1360 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1360 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1361 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
1361 scoped_ptr<CountingStreamSocket> counting_socket( | 1362 std::unique_ptr<CountingStreamSocket> counting_socket( |
1362 new CountingStreamSocket(std::move(error_socket))); | 1363 new CountingStreamSocket(std::move(error_socket))); |
1363 CountingStreamSocket* raw_counting_socket = counting_socket.get(); | 1364 CountingStreamSocket* raw_counting_socket = counting_socket.get(); |
1364 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); | 1365 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); |
1365 ASSERT_EQ(OK, rv); | 1366 ASSERT_EQ(OK, rv); |
1366 | 1367 |
1367 // Disable TLS False Start to avoid handshake non-determinism. | 1368 // Disable TLS False Start to avoid handshake non-determinism. |
1368 SSLConfig ssl_config; | 1369 SSLConfig ssl_config; |
1369 ssl_config.false_start_enabled = false; | 1370 ssl_config.false_start_enabled = false; |
1370 | 1371 |
1371 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1372 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1372 std::move(counting_socket), spawned_test_server()->host_port_pair(), | 1373 std::move(counting_socket), spawned_test_server()->host_port_pair(), |
1373 ssl_config)); | 1374 ssl_config)); |
1374 | 1375 |
1375 rv = callback.GetResult(sock->Connect(callback.callback())); | 1376 rv = callback.GetResult(sock->Connect(callback.callback())); |
1376 ASSERT_EQ(OK, rv); | 1377 ASSERT_EQ(OK, rv); |
1377 ASSERT_TRUE(sock->IsConnected()); | 1378 ASSERT_TRUE(sock->IsConnected()); |
1378 | 1379 |
1379 // Simulate an unclean/forcible shutdown on the underlying socket. | 1380 // Simulate an unclean/forcible shutdown on the underlying socket. |
1380 raw_error_socket->SetNextWriteError(ERR_CONNECTION_RESET); | 1381 raw_error_socket->SetNextWriteError(ERR_CONNECTION_RESET); |
1381 | 1382 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 // Attempts to Read() and Write() from an SSLClientSocketNSS in full duplex | 1445 // Attempts to Read() and Write() from an SSLClientSocketNSS in full duplex |
1445 // mode when the underlying transport is blocked on sending data. When the | 1446 // mode when the underlying transport is blocked on sending data. When the |
1446 // underlying transport completes due to an error, it should invoke both the | 1447 // underlying transport completes due to an error, it should invoke both the |
1447 // Read() and Write() callbacks. If the socket is deleted by the Read() | 1448 // Read() and Write() callbacks. If the socket is deleted by the Read() |
1448 // callback, the Write() callback should not be invoked. | 1449 // callback, the Write() callback should not be invoked. |
1449 // Regression test for http://crbug.com/232633 | 1450 // Regression test for http://crbug.com/232633 |
1450 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { | 1451 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { |
1451 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1452 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1452 | 1453 |
1453 TestCompletionCallback callback; | 1454 TestCompletionCallback callback; |
1454 scoped_ptr<StreamSocket> real_transport( | 1455 std::unique_ptr<StreamSocket> real_transport( |
1455 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1456 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1456 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1457 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
1457 // is retained in order to configure additional errors. | 1458 // is retained in order to configure additional errors. |
1458 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | 1459 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
1459 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1460 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1460 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1461 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
1461 scoped_ptr<FakeBlockingStreamSocket> transport( | 1462 std::unique_ptr<FakeBlockingStreamSocket> transport( |
1462 new FakeBlockingStreamSocket(std::move(error_socket))); | 1463 new FakeBlockingStreamSocket(std::move(error_socket))); |
1463 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1464 FakeBlockingStreamSocket* raw_transport = transport.get(); |
1464 | 1465 |
1465 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1466 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1466 EXPECT_EQ(OK, rv); | 1467 EXPECT_EQ(OK, rv); |
1467 | 1468 |
1468 // Disable TLS False Start to avoid handshake non-determinism. | 1469 // Disable TLS False Start to avoid handshake non-determinism. |
1469 SSLConfig ssl_config; | 1470 SSLConfig ssl_config; |
1470 ssl_config.false_start_enabled = false; | 1471 ssl_config.false_start_enabled = false; |
1471 | 1472 |
1472 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 1473 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
1473 std::move(transport), spawned_test_server()->host_port_pair(), | 1474 std::move(transport), spawned_test_server()->host_port_pair(), |
1474 ssl_config); | 1475 ssl_config); |
1475 | 1476 |
1476 rv = callback.GetResult(sock->Connect(callback.callback())); | 1477 rv = callback.GetResult(sock->Connect(callback.callback())); |
1477 EXPECT_EQ(OK, rv); | 1478 EXPECT_EQ(OK, rv); |
1478 EXPECT_TRUE(sock->IsConnected()); | 1479 EXPECT_TRUE(sock->IsConnected()); |
1479 | 1480 |
1480 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; | 1481 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; |
1481 request_text.append(20 * 1024, '*'); | 1482 request_text.append(20 * 1024, '*'); |
1482 request_text.append("\r\n\r\n"); | 1483 request_text.append("\r\n\r\n"); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 } | 1554 } |
1554 | 1555 |
1555 // Tests that the SSLClientSocket does not crash if data is received on the | 1556 // Tests that the SSLClientSocket does not crash if data is received on the |
1556 // transport socket after a failing write. This can occur if we have a Write | 1557 // transport socket after a failing write. This can occur if we have a Write |
1557 // error in a SPDY socket. | 1558 // error in a SPDY socket. |
1558 // Regression test for http://crbug.com/335557 | 1559 // Regression test for http://crbug.com/335557 |
1559 TEST_F(SSLClientSocketTest, Read_WithWriteError) { | 1560 TEST_F(SSLClientSocketTest, Read_WithWriteError) { |
1560 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1561 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1561 | 1562 |
1562 TestCompletionCallback callback; | 1563 TestCompletionCallback callback; |
1563 scoped_ptr<StreamSocket> real_transport( | 1564 std::unique_ptr<StreamSocket> real_transport( |
1564 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1565 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1565 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1566 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
1566 // is retained in order to configure additional errors. | 1567 // is retained in order to configure additional errors. |
1567 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | 1568 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
1568 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1569 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1569 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1570 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
1570 scoped_ptr<FakeBlockingStreamSocket> transport( | 1571 std::unique_ptr<FakeBlockingStreamSocket> transport( |
1571 new FakeBlockingStreamSocket(std::move(error_socket))); | 1572 new FakeBlockingStreamSocket(std::move(error_socket))); |
1572 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1573 FakeBlockingStreamSocket* raw_transport = transport.get(); |
1573 | 1574 |
1574 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1575 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1575 EXPECT_EQ(OK, rv); | 1576 EXPECT_EQ(OK, rv); |
1576 | 1577 |
1577 // Disable TLS False Start to avoid handshake non-determinism. | 1578 // Disable TLS False Start to avoid handshake non-determinism. |
1578 SSLConfig ssl_config; | 1579 SSLConfig ssl_config; |
1579 ssl_config.false_start_enabled = false; | 1580 ssl_config.false_start_enabled = false; |
1580 | 1581 |
1581 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1582 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1582 std::move(transport), spawned_test_server()->host_port_pair(), | 1583 std::move(transport), spawned_test_server()->host_port_pair(), |
1583 ssl_config)); | 1584 ssl_config)); |
1584 | 1585 |
1585 rv = callback.GetResult(sock->Connect(callback.callback())); | 1586 rv = callback.GetResult(sock->Connect(callback.callback())); |
1586 EXPECT_EQ(OK, rv); | 1587 EXPECT_EQ(OK, rv); |
1587 EXPECT_TRUE(sock->IsConnected()); | 1588 EXPECT_TRUE(sock->IsConnected()); |
1588 | 1589 |
1589 // Send a request so there is something to read from the socket. | 1590 // Send a request so there is something to read from the socket. |
1590 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1591 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1591 static const int kRequestTextSize = | 1592 static const int kRequestTextSize = |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 1651 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
1651 #endif | 1652 #endif |
1652 } | 1653 } |
1653 | 1654 |
1654 // Tests that SSLClientSocket fails the handshake if the underlying | 1655 // Tests that SSLClientSocket fails the handshake if the underlying |
1655 // transport is cleanly closed. | 1656 // transport is cleanly closed. |
1656 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { | 1657 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { |
1657 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1658 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1658 | 1659 |
1659 TestCompletionCallback callback; | 1660 TestCompletionCallback callback; |
1660 scoped_ptr<StreamSocket> real_transport( | 1661 std::unique_ptr<StreamSocket> real_transport( |
1661 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1662 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1662 scoped_ptr<SynchronousErrorStreamSocket> transport( | 1663 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
1663 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1664 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1664 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1665 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1665 EXPECT_EQ(OK, rv); | 1666 EXPECT_EQ(OK, rv); |
1666 | 1667 |
1667 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1668 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
1668 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1669 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1669 std::move(transport), spawned_test_server()->host_port_pair(), | 1670 std::move(transport), spawned_test_server()->host_port_pair(), |
1670 SSLConfig())); | 1671 SSLConfig())); |
1671 | 1672 |
1672 raw_transport->SetNextReadError(0); | 1673 raw_transport->SetNextReadError(0); |
1673 | 1674 |
1674 rv = callback.GetResult(sock->Connect(callback.callback())); | 1675 rv = callback.GetResult(sock->Connect(callback.callback())); |
1675 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); | 1676 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
1676 EXPECT_FALSE(sock->IsConnected()); | 1677 EXPECT_FALSE(sock->IsConnected()); |
1677 } | 1678 } |
1678 | 1679 |
1679 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket | 1680 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket |
1680 // is cleanly closed, but the peer does not send close_notify. | 1681 // is cleanly closed, but the peer does not send close_notify. |
1681 // This is a regression test for https://crbug.com/422246 | 1682 // This is a regression test for https://crbug.com/422246 |
1682 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { | 1683 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { |
1683 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1684 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1684 | 1685 |
1685 TestCompletionCallback callback; | 1686 TestCompletionCallback callback; |
1686 scoped_ptr<StreamSocket> real_transport( | 1687 std::unique_ptr<StreamSocket> real_transport( |
1687 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1688 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1688 scoped_ptr<SynchronousErrorStreamSocket> transport( | 1689 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
1689 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1690 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1690 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1691 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1691 EXPECT_EQ(OK, rv); | 1692 EXPECT_EQ(OK, rv); |
1692 | 1693 |
1693 // Disable TLS False Start to ensure the handshake has completed. | 1694 // Disable TLS False Start to ensure the handshake has completed. |
1694 SSLConfig ssl_config; | 1695 SSLConfig ssl_config; |
1695 ssl_config.false_start_enabled = false; | 1696 ssl_config.false_start_enabled = false; |
1696 | 1697 |
1697 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1698 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
1698 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1699 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1699 std::move(transport), spawned_test_server()->host_port_pair(), | 1700 std::move(transport), spawned_test_server()->host_port_pair(), |
1700 ssl_config)); | 1701 ssl_config)); |
1701 | 1702 |
1702 rv = callback.GetResult(sock->Connect(callback.callback())); | 1703 rv = callback.GetResult(sock->Connect(callback.callback())); |
1703 EXPECT_EQ(OK, rv); | 1704 EXPECT_EQ(OK, rv); |
1704 EXPECT_TRUE(sock->IsConnected()); | 1705 EXPECT_TRUE(sock->IsConnected()); |
1705 | 1706 |
1706 raw_transport->SetNextReadError(0); | 1707 raw_transport->SetNextReadError(0); |
1707 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 1708 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
1708 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback())); | 1709 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback())); |
1709 EXPECT_EQ(0, rv); | 1710 EXPECT_EQ(0, rv); |
1710 } | 1711 } |
1711 | 1712 |
1712 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the | 1713 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the |
1713 // underlying socket is cleanly closed asynchronously. | 1714 // underlying socket is cleanly closed asynchronously. |
1714 // This is a regression test for https://crbug.com/422246 | 1715 // This is a regression test for https://crbug.com/422246 |
1715 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { | 1716 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { |
1716 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1717 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1717 | 1718 |
1718 TestCompletionCallback callback; | 1719 TestCompletionCallback callback; |
1719 scoped_ptr<StreamSocket> real_transport( | 1720 std::unique_ptr<StreamSocket> real_transport( |
1720 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1721 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1721 scoped_ptr<SynchronousErrorStreamSocket> error_socket( | 1722 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
1722 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1723 new SynchronousErrorStreamSocket(std::move(real_transport))); |
1723 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1724 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
1724 scoped_ptr<FakeBlockingStreamSocket> transport( | 1725 std::unique_ptr<FakeBlockingStreamSocket> transport( |
1725 new FakeBlockingStreamSocket(std::move(error_socket))); | 1726 new FakeBlockingStreamSocket(std::move(error_socket))); |
1726 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1727 FakeBlockingStreamSocket* raw_transport = transport.get(); |
1727 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1728 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1728 EXPECT_EQ(OK, rv); | 1729 EXPECT_EQ(OK, rv); |
1729 | 1730 |
1730 // Disable TLS False Start to ensure the handshake has completed. | 1731 // Disable TLS False Start to ensure the handshake has completed. |
1731 SSLConfig ssl_config; | 1732 SSLConfig ssl_config; |
1732 ssl_config.false_start_enabled = false; | 1733 ssl_config.false_start_enabled = false; |
1733 | 1734 |
1734 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1735 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1735 std::move(transport), spawned_test_server()->host_port_pair(), | 1736 std::move(transport), spawned_test_server()->host_port_pair(), |
1736 ssl_config)); | 1737 ssl_config)); |
1737 | 1738 |
1738 rv = callback.GetResult(sock->Connect(callback.callback())); | 1739 rv = callback.GetResult(sock->Connect(callback.callback())); |
1739 EXPECT_EQ(OK, rv); | 1740 EXPECT_EQ(OK, rv); |
1740 EXPECT_TRUE(sock->IsConnected()); | 1741 EXPECT_TRUE(sock->IsConnected()); |
1741 | 1742 |
1742 raw_error_socket->SetNextReadError(0); | 1743 raw_error_socket->SetNextReadError(0); |
1743 raw_transport->BlockReadResult(); | 1744 raw_transport->BlockReadResult(); |
1744 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 1745 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 rv = callback.GetResult(sock_->Read(buf.get(), 1, callback.callback())); | 1791 rv = callback.GetResult(sock_->Read(buf.get(), 1, callback.callback())); |
1791 EXPECT_GE(rv, 0); | 1792 EXPECT_GE(rv, 0); |
1792 } while (rv > 0); | 1793 } while (rv > 0); |
1793 } | 1794 } |
1794 | 1795 |
1795 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { | 1796 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { |
1796 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1797 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1797 | 1798 |
1798 TestCompletionCallback callback; | 1799 TestCompletionCallback callback; |
1799 | 1800 |
1800 scoped_ptr<StreamSocket> real_transport( | 1801 std::unique_ptr<StreamSocket> real_transport( |
1801 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1802 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1802 scoped_ptr<ReadBufferingStreamSocket> transport( | 1803 std::unique_ptr<ReadBufferingStreamSocket> transport( |
1803 new ReadBufferingStreamSocket(std::move(real_transport))); | 1804 new ReadBufferingStreamSocket(std::move(real_transport))); |
1804 ReadBufferingStreamSocket* raw_transport = transport.get(); | 1805 ReadBufferingStreamSocket* raw_transport = transport.get(); |
1805 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1806 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1806 ASSERT_EQ(OK, rv); | 1807 ASSERT_EQ(OK, rv); |
1807 | 1808 |
1808 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1809 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1809 std::move(transport), spawned_test_server()->host_port_pair(), | 1810 std::move(transport), spawned_test_server()->host_port_pair(), |
1810 SSLConfig())); | 1811 SSLConfig())); |
1811 | 1812 |
1812 rv = callback.GetResult(sock->Connect(callback.callback())); | 1813 rv = callback.GetResult(sock->Connect(callback.callback())); |
1813 ASSERT_EQ(OK, rv); | 1814 ASSERT_EQ(OK, rv); |
1814 ASSERT_TRUE(sock->IsConnected()); | 1815 ASSERT_TRUE(sock->IsConnected()); |
1815 | 1816 |
1816 const char request_text[] = "GET /ssl-many-small-records HTTP/1.0\r\n\r\n"; | 1817 const char request_text[] = "GET /ssl-many-small-records HTTP/1.0\r\n\r\n"; |
1817 scoped_refptr<IOBuffer> request_buffer( | 1818 scoped_refptr<IOBuffer> request_buffer( |
1818 new IOBuffer(arraysize(request_text) - 1)); | 1819 new IOBuffer(arraysize(request_text) - 1)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 rv = callback.GetResult(sock_->Read(buf.get(), 512, callback.callback())); | 1862 rv = callback.GetResult(sock_->Read(buf.get(), 512, callback.callback())); |
1862 EXPECT_GT(rv, 0); | 1863 EXPECT_GT(rv, 0); |
1863 } | 1864 } |
1864 | 1865 |
1865 TEST_F(SSLClientSocketTest, Read_FullLogging) { | 1866 TEST_F(SSLClientSocketTest, Read_FullLogging) { |
1866 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1867 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1867 | 1868 |
1868 TestCompletionCallback callback; | 1869 TestCompletionCallback callback; |
1869 TestNetLog log; | 1870 TestNetLog log; |
1870 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); | 1871 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); |
1871 scoped_ptr<StreamSocket> transport( | 1872 std::unique_ptr<StreamSocket> transport( |
1872 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); | 1873 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); |
1873 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1874 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1874 EXPECT_EQ(OK, rv); | 1875 EXPECT_EQ(OK, rv); |
1875 | 1876 |
1876 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1877 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1877 std::move(transport), spawned_test_server()->host_port_pair(), | 1878 std::move(transport), spawned_test_server()->host_port_pair(), |
1878 SSLConfig())); | 1879 SSLConfig())); |
1879 | 1880 |
1880 rv = callback.GetResult(sock->Connect(callback.callback())); | 1881 rv = callback.GetResult(sock->Connect(callback.callback())); |
1881 EXPECT_EQ(OK, rv); | 1882 EXPECT_EQ(OK, rv); |
1882 EXPECT_TRUE(sock->IsConnected()); | 1883 EXPECT_TRUE(sock->IsConnected()); |
1883 | 1884 |
1884 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 1885 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
1885 scoped_refptr<IOBuffer> request_buffer( | 1886 scoped_refptr<IOBuffer> request_buffer( |
1886 new IOBuffer(arraysize(request_text) - 1)); | 1887 new IOBuffer(arraysize(request_text) - 1)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 // All reads and writes complete synchronously (async=false). | 1931 // All reads and writes complete synchronously (async=false). |
1931 MockRead data_reads[] = { | 1932 MockRead data_reads[] = { |
1932 MockRead(SYNCHRONOUS, | 1933 MockRead(SYNCHRONOUS, |
1933 reinterpret_cast<const char*>(application_data), | 1934 reinterpret_cast<const char*>(application_data), |
1934 arraysize(application_data)), | 1935 arraysize(application_data)), |
1935 MockRead(SYNCHRONOUS, OK), }; | 1936 MockRead(SYNCHRONOUS, OK), }; |
1936 | 1937 |
1937 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | 1938 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
1938 | 1939 |
1939 TestCompletionCallback callback; | 1940 TestCompletionCallback callback; |
1940 scoped_ptr<StreamSocket> transport( | 1941 std::unique_ptr<StreamSocket> transport( |
1941 new MockTCPClientSocket(addr(), NULL, &data)); | 1942 new MockTCPClientSocket(addr(), NULL, &data)); |
1942 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1943 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1943 EXPECT_EQ(OK, rv); | 1944 EXPECT_EQ(OK, rv); |
1944 | 1945 |
1945 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1946 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
1946 std::move(transport), spawned_test_server()->host_port_pair(), | 1947 std::move(transport), spawned_test_server()->host_port_pair(), |
1947 SSLConfig())); | 1948 SSLConfig())); |
1948 | 1949 |
1949 rv = callback.GetResult(sock->Connect(callback.callback())); | 1950 rv = callback.GetResult(sock->Connect(callback.callback())); |
1950 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); | 1951 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
1951 } | 1952 } |
1952 | 1953 |
1953 TEST_F(SSLClientSocketTest, CipherSuiteDisables) { | 1954 TEST_F(SSLClientSocketTest, CipherSuiteDisables) { |
1954 // Rather than exhaustively disabling every AES_128_CBC ciphersuite defined at | 1955 // Rather than exhaustively disabling every AES_128_CBC ciphersuite defined at |
1955 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml, only | 1956 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml, only |
(...skipping 19 matching lines...) Expand all Loading... |
1975 } | 1976 } |
1976 | 1977 |
1977 // When creating an SSLClientSocket, it is allowed to pass in a | 1978 // When creating an SSLClientSocket, it is allowed to pass in a |
1978 // ClientSocketHandle that is not obtained from a client socket pool. | 1979 // ClientSocketHandle that is not obtained from a client socket pool. |
1979 // Here we verify that such a simple ClientSocketHandle, not associated with any | 1980 // Here we verify that such a simple ClientSocketHandle, not associated with any |
1980 // client socket pool, can be destroyed safely. | 1981 // client socket pool, can be destroyed safely. |
1981 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { | 1982 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { |
1982 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1983 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
1983 | 1984 |
1984 TestCompletionCallback callback; | 1985 TestCompletionCallback callback; |
1985 scoped_ptr<StreamSocket> transport( | 1986 std::unique_ptr<StreamSocket> transport( |
1986 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1987 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
1987 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1988 int rv = callback.GetResult(transport->Connect(callback.callback())); |
1988 EXPECT_EQ(OK, rv); | 1989 EXPECT_EQ(OK, rv); |
1989 | 1990 |
1990 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); | 1991 std::unique_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); |
1991 socket_handle->SetSocket(std::move(transport)); | 1992 socket_handle->SetSocket(std::move(transport)); |
1992 | 1993 |
1993 scoped_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( | 1994 std::unique_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( |
1994 std::move(socket_handle), spawned_test_server()->host_port_pair(), | 1995 std::move(socket_handle), spawned_test_server()->host_port_pair(), |
1995 SSLConfig(), context_)); | 1996 SSLConfig(), context_)); |
1996 | 1997 |
1997 EXPECT_FALSE(sock->IsConnected()); | 1998 EXPECT_FALSE(sock->IsConnected()); |
1998 rv = callback.GetResult(sock->Connect(callback.callback())); | 1999 rv = callback.GetResult(sock->Connect(callback.callback())); |
1999 EXPECT_EQ(OK, rv); | 2000 EXPECT_EQ(OK, rv); |
2000 } | 2001 } |
2001 | 2002 |
2002 // Verifies that SSLClientSocket::ExportKeyingMaterial return a success | 2003 // Verifies that SSLClientSocket::ExportKeyingMaterial return a success |
2003 // code and different keying label results in different keying material. | 2004 // code and different keying label results in different keying material. |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 // attempt to read one byte extra. | 2505 // attempt to read one byte extra. |
2505 } | 2506 } |
2506 | 2507 |
2507 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't | 2508 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't |
2508 // been flushed completely out of SSLClientSocket's internal buffers. This is a | 2509 // been flushed completely out of SSLClientSocket's internal buffers. This is a |
2509 // regression test for https://crbug.com/466147. | 2510 // regression test for https://crbug.com/466147. |
2510 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { | 2511 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { |
2511 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 2512 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
2512 | 2513 |
2513 TestCompletionCallback callback; | 2514 TestCompletionCallback callback; |
2514 scoped_ptr<StreamSocket> real_transport( | 2515 std::unique_ptr<StreamSocket> real_transport( |
2515 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 2516 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); |
2516 scoped_ptr<FakeBlockingStreamSocket> transport( | 2517 std::unique_ptr<FakeBlockingStreamSocket> transport( |
2517 new FakeBlockingStreamSocket(std::move(real_transport))); | 2518 new FakeBlockingStreamSocket(std::move(real_transport))); |
2518 FakeBlockingStreamSocket* raw_transport = transport.get(); | 2519 FakeBlockingStreamSocket* raw_transport = transport.get(); |
2519 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | 2520 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); |
2520 | 2521 |
2521 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 2522 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
2522 std::move(transport), spawned_test_server()->host_port_pair(), | 2523 std::move(transport), spawned_test_server()->host_port_pair(), |
2523 SSLConfig())); | 2524 SSLConfig())); |
2524 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | 2525 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); |
2525 | 2526 |
2526 // Block any application data from reaching the network. | 2527 // Block any application data from reaching the network. |
2527 raw_transport->BlockWrite(); | 2528 raw_transport->BlockWrite(); |
2528 | 2529 |
2529 // Write a partial HTTP request. | 2530 // Write a partial HTTP request. |
2530 const char kRequestText[] = "GET / HTTP/1.0"; | 2531 const char kRequestText[] = "GET / HTTP/1.0"; |
2531 const size_t kRequestLen = arraysize(kRequestText) - 1; | 2532 const size_t kRequestLen = arraysize(kRequestText) - 1; |
(...skipping 28 matching lines...) Expand all Loading... |
2560 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | 2561 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); |
2561 | 2562 |
2562 // The next connection should resume. | 2563 // The next connection should resume. |
2563 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2564 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
2564 ASSERT_EQ(OK, rv); | 2565 ASSERT_EQ(OK, rv); |
2565 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); | 2566 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); |
2566 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); | 2567 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); |
2567 sock_.reset(); | 2568 sock_.reset(); |
2568 | 2569 |
2569 // Using a different HostPortPair uses a different session cache key. | 2570 // Using a different HostPortPair uses a different session cache key. |
2570 scoped_ptr<StreamSocket> transport( | 2571 std::unique_ptr<StreamSocket> transport( |
2571 new TCPClientSocket(addr(), NULL, &log_, NetLog::Source())); | 2572 new TCPClientSocket(addr(), NULL, &log_, NetLog::Source())); |
2572 TestCompletionCallback callback; | 2573 TestCompletionCallback callback; |
2573 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); | 2574 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); |
2574 scoped_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 2575 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
2575 std::move(transport), HostPortPair("example.com", 443), ssl_config); | 2576 std::move(transport), HostPortPair("example.com", 443), ssl_config); |
2576 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); | 2577 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); |
2577 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | 2578 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); |
2578 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | 2579 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); |
2579 sock.reset(); | 2580 sock.reset(); |
2580 | 2581 |
2581 SSLClientSocket::ClearSessionCache(); | 2582 SSLClientSocket::ClearSessionCache(); |
2582 | 2583 |
2583 // After clearing the session cache, the next handshake doesn't resume. | 2584 // After clearing the session cache, the next handshake doesn't resume. |
2584 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2585 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2955 | 2956 |
2956 SSLConfig client_config; | 2957 SSLConfig client_config; |
2957 #if !defined(USE_OPENSSL) | 2958 #if !defined(USE_OPENSSL) |
2958 client_config.alpn_protos.push_back(kProtoHTTP11); | 2959 client_config.alpn_protos.push_back(kProtoHTTP11); |
2959 #endif | 2960 #endif |
2960 client_config.npn_protos.push_back(kProtoHTTP11); | 2961 client_config.npn_protos.push_back(kProtoHTTP11); |
2961 | 2962 |
2962 // Start a handshake up to the server Finished message. | 2963 // Start a handshake up to the server Finished message. |
2963 TestCompletionCallback callback; | 2964 TestCompletionCallback callback; |
2964 FakeBlockingStreamSocket* raw_transport1 = NULL; | 2965 FakeBlockingStreamSocket* raw_transport1 = NULL; |
2965 scoped_ptr<SSLClientSocket> sock1; | 2966 std::unique_ptr<SSLClientSocket> sock1; |
2966 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 2967 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
2967 client_config, &callback, &raw_transport1, &sock1)); | 2968 client_config, &callback, &raw_transport1, &sock1)); |
2968 // Although raw_transport1 has the server Finished blocked, the handshake | 2969 // Although raw_transport1 has the server Finished blocked, the handshake |
2969 // still completes. | 2970 // still completes. |
2970 EXPECT_EQ(OK, callback.WaitForResult()); | 2971 EXPECT_EQ(OK, callback.WaitForResult()); |
2971 | 2972 |
2972 // Continue to block the client (|sock1|) from processing the Finished | 2973 // Continue to block the client (|sock1|) from processing the Finished |
2973 // message, but allow it to arrive on the socket. This ensures that, from the | 2974 // message, but allow it to arrive on the socket. This ensures that, from the |
2974 // server's point of view, it has completed the handshake and added the | 2975 // server's point of view, it has completed the handshake and added the |
2975 // session to its session cache. | 2976 // session to its session cache. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3012 | 3013 |
3013 SSLConfig client_config; | 3014 SSLConfig client_config; |
3014 #if !defined(USE_OPENSSL) | 3015 #if !defined(USE_OPENSSL) |
3015 client_config.alpn_protos.push_back(kProtoHTTP11); | 3016 client_config.alpn_protos.push_back(kProtoHTTP11); |
3016 #endif | 3017 #endif |
3017 client_config.npn_protos.push_back(kProtoHTTP11); | 3018 client_config.npn_protos.push_back(kProtoHTTP11); |
3018 | 3019 |
3019 // Start a handshake up to the server Finished message. | 3020 // Start a handshake up to the server Finished message. |
3020 TestCompletionCallback callback; | 3021 TestCompletionCallback callback; |
3021 FakeBlockingStreamSocket* raw_transport1 = NULL; | 3022 FakeBlockingStreamSocket* raw_transport1 = NULL; |
3022 scoped_ptr<SSLClientSocket> sock1; | 3023 std::unique_ptr<SSLClientSocket> sock1; |
3023 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 3024 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
3024 client_config, &callback, &raw_transport1, &sock1)); | 3025 client_config, &callback, &raw_transport1, &sock1)); |
3025 // Although raw_transport1 has the server Finished blocked, the handshake | 3026 // Although raw_transport1 has the server Finished blocked, the handshake |
3026 // still completes. | 3027 // still completes. |
3027 EXPECT_EQ(OK, callback.WaitForResult()); | 3028 EXPECT_EQ(OK, callback.WaitForResult()); |
3028 | 3029 |
3029 // Continue to block the client (|sock1|) from processing the Finished | 3030 // Continue to block the client (|sock1|) from processing the Finished |
3030 // message, but allow it to arrive on the socket. This ensures that, from the | 3031 // message, but allow it to arrive on the socket. This ensures that, from the |
3031 // server's point of view, it has completed the handshake and added the | 3032 // server's point of view, it has completed the handshake and added the |
3032 // session to its session cache. | 3033 // session to its session cache. |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3365 SSLInfo ssl_info; | 3366 SSLInfo ssl_info; |
3366 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); | 3367 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); |
3367 EXPECT_TRUE(ssl_info.client_cert_sent); | 3368 EXPECT_TRUE(ssl_info.client_cert_sent); |
3368 | 3369 |
3369 sock_->Disconnect(); | 3370 sock_->Disconnect(); |
3370 EXPECT_FALSE(sock_->IsConnected()); | 3371 EXPECT_FALSE(sock_->IsConnected()); |
3371 } | 3372 } |
3372 #endif // defined(USE_OPENSSL) | 3373 #endif // defined(USE_OPENSSL) |
3373 | 3374 |
3374 } // namespace net | 3375 } // namespace net |
OLD | NEW |