OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 test_hosts[i].pair = HostPortProxyPair( | 683 test_hosts[i].pair = HostPortProxyPair( |
684 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); | 684 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
685 } | 685 } |
686 | 686 |
687 MockRead reads[] = { | 687 MockRead reads[] = { |
688 MockRead(true, ERR_IO_PENDING), | 688 MockRead(true, ERR_IO_PENDING), |
689 }; | 689 }; |
690 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 690 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
691 socket_factory_.AddSocketDataProvider(&data); | 691 socket_factory_.AddSocketDataProvider(&data); |
692 SSLSocketDataProvider ssl(true, OK); | 692 SSLSocketDataProvider ssl(true, OK); |
693 ssl.cert_ = X509Certificate::CreateFromBytes( | 693 ssl.cert = X509Certificate::CreateFromBytes( |
694 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); | 694 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); |
695 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 695 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
696 ssl.next_proto = "spdy/2"; | 696 ssl.next_proto = "spdy/2"; |
697 socket_factory_.AddSSLSocketDataProvider(&ssl); | 697 socket_factory_.AddSSLSocketDataProvider(&ssl); |
698 | 698 |
699 CreatePool(true /* tcp pool */, false, false); | 699 CreatePool(true /* tcp pool */, false, false); |
700 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 700 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
701 true); | 701 true); |
702 | 702 |
703 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); | 703 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); |
704 TestOldCompletionCallback callback; | 704 TestOldCompletionCallback callback; |
705 int rv = handle->Init( | 705 int rv = handle->Init( |
706 "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); | 706 "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); |
707 EXPECT_EQ(ERR_IO_PENDING, rv); | 707 EXPECT_EQ(ERR_IO_PENDING, rv); |
708 EXPECT_FALSE(handle->is_initialized()); | 708 EXPECT_FALSE(handle->is_initialized()); |
709 EXPECT_FALSE(handle->socket()); | 709 EXPECT_FALSE(handle->socket()); |
710 | 710 |
711 EXPECT_EQ(OK, callback.WaitForResult()); | 711 EXPECT_EQ(OK, callback.WaitForResult()); |
712 EXPECT_TRUE(handle->is_initialized()); | 712 EXPECT_TRUE(handle->is_initialized()); |
713 EXPECT_TRUE(handle->socket()); | 713 EXPECT_TRUE(handle->socket()); |
714 | 714 |
715 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); | 715 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); |
716 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); | 716 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); |
717 std::string proto; | 717 std::string proto; |
718 ssl_socket->GetNextProto(&proto); | 718 ssl_socket->GetNextProto(&proto); |
719 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), | 719 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), |
720 SSLClientSocket::kProtoSPDY2); | 720 SSLClientSocket::kProtoSPDY2); |
721 | 721 |
722 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port | 722 // TODO(rtenneti): MockClientSocket::GetPeerAddress returns 0 as the port |
723 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. | 723 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
724 const addrinfo* address = test_hosts[0].addresses.head(); | 724 const addrinfo* address = test_hosts[0].addresses.head(); |
725 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); | 725 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); |
726 pool_peer.AddAlias(address, test_hosts[0].pair); | 726 pool_peer.AddAlias(address, test_hosts[0].pair); |
727 | 727 |
728 scoped_refptr<SpdySession> spdy_session; | 728 scoped_refptr<SpdySession> spdy_session; |
729 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( | 729 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( |
730 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, | 730 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, |
731 &spdy_session, true); | 731 &spdy_session, true); |
732 EXPECT_EQ(0, rv); | 732 EXPECT_EQ(0, rv); |
733 | 733 |
734 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); | 734 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); |
735 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); | 735 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); |
736 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); | 736 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); |
737 | 737 |
738 session_->spdy_session_pool()->CloseAllSessions(); | 738 session_->spdy_session_pool()->CloseAllSessions(); |
739 } | 739 } |
740 | 740 |
| 741 TEST_F(SSLClientSocketPoolTest, IPPoolingClientCert) { |
| 742 const int kTestPort = 80; |
| 743 struct TestHosts { |
| 744 std::string name; |
| 745 std::string iplist; |
| 746 HostPortProxyPair pair; |
| 747 AddressList addresses; |
| 748 } test_hosts[] = { |
| 749 { "www.webkit.org", "192.0.2.33,192.168.0.1,192.168.0.5" }, |
| 750 { "js.webkit.org", "192.168.0.4,192.168.0.1,192.0.2.33" }, |
| 751 }; |
| 752 |
| 753 TestOldCompletionCallback callback; |
| 754 int rv; |
| 755 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
| 756 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, |
| 757 test_hosts[i].iplist, ""); |
| 758 |
| 759 // This test requires that the HostResolver cache be populated. Normal |
| 760 // code would have done this already, but we do it manually. |
| 761 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
| 762 rv = host_resolver_.Resolve(info, &test_hosts[i].addresses, &callback, |
| 763 NULL, BoundNetLog()); |
| 764 EXPECT_EQ(OK, callback.GetResult(rv)); |
| 765 |
| 766 // Setup a HostPortProxyPair |
| 767 test_hosts[i].pair = HostPortProxyPair( |
| 768 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
| 769 } |
| 770 |
| 771 MockRead reads[] = { |
| 772 MockRead(true, ERR_IO_PENDING), |
| 773 }; |
| 774 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 775 socket_factory_.AddSocketDataProvider(&data); |
| 776 SSLSocketDataProvider ssl(true, OK); |
| 777 ssl.cert = X509Certificate::CreateFromBytes( |
| 778 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); |
| 779 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 780 ssl.next_proto = "spdy/2"; |
| 781 ssl.client_cert_sent = true; |
| 782 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 783 |
| 784 CreatePool(true /* tcp pool */, false, false); |
| 785 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
| 786 true); |
| 787 |
| 788 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); |
| 789 rv = handle->Init( |
| 790 "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); |
| 791 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 792 EXPECT_FALSE(handle->is_initialized()); |
| 793 EXPECT_FALSE(handle->socket()); |
| 794 |
| 795 EXPECT_EQ(OK, callback.WaitForResult()); |
| 796 EXPECT_TRUE(handle->is_initialized()); |
| 797 EXPECT_TRUE(handle->socket()); |
| 798 |
| 799 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); |
| 800 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); |
| 801 std::string proto; |
| 802 ssl_socket->GetNextProto(&proto); |
| 803 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), |
| 804 SSLClientSocket::kProtoSPDY2); |
| 805 |
| 806 // TODO(rtenneti): MockClientSocket::GetPeerAddress returns 0 as the port |
| 807 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
| 808 const addrinfo* address = test_hosts[0].addresses.head(); |
| 809 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); |
| 810 pool_peer.AddAlias(address, test_hosts[0].pair); |
| 811 |
| 812 scoped_refptr<SpdySession> spdy_session; |
| 813 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( |
| 814 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, |
| 815 &spdy_session, true); |
| 816 EXPECT_EQ(0, rv); |
| 817 |
| 818 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); |
| 819 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); |
| 820 |
| 821 session_->spdy_session_pool()->CloseAllSessions(); |
| 822 } |
| 823 |
741 // It would be nice to also test the timeouts in SSLClientSocketPool. | 824 // It would be nice to also test the timeouts in SSLClientSocketPool. |
742 | 825 |
743 } // namespace | 826 } // namespace |
744 | 827 |
745 } // namespace net | 828 } // namespace net |
OLD | NEW |