| 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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include "net/base/cert_test_util.h" |
| 7 #include "net/base/host_cache.h" | 8 #include "net/base/host_cache.h" |
| 8 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 9 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
| 10 #include "net/spdy/spdy_io_buffer.h" | 11 #include "net/spdy/spdy_io_buffer.h" |
| 11 #include "net/spdy/spdy_session_pool.h" | 12 #include "net/spdy/spdy_session_pool.h" |
| 12 #include "net/spdy/spdy_stream.h" | 13 #include "net/spdy/spdy_stream.h" |
| 13 #include "net/spdy/spdy_test_util_spdy3.h" | 14 #include "net/spdy/spdy_test_util_spdy3.h" |
| 14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 15 | 16 |
| 16 using namespace net::test_spdy3; | 17 using namespace net::test_spdy3; |
| (...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 // Ensure we don't crash while closing the session. | 1685 // Ensure we don't crash while closing the session. |
| 1685 session->CloseSessionOnError(ERR_ABORTED, true, ""); | 1686 session->CloseSessionOnError(ERR_ABORTED, true, ""); |
| 1686 | 1687 |
| 1687 EXPECT_TRUE(spdy_stream1->closed()); | 1688 EXPECT_TRUE(spdy_stream1->closed()); |
| 1688 EXPECT_TRUE(spdy_stream2->closed()); | 1689 EXPECT_TRUE(spdy_stream2->closed()); |
| 1689 | 1690 |
| 1690 spdy_stream1 = NULL; | 1691 spdy_stream1 = NULL; |
| 1691 spdy_stream2 = NULL; | 1692 spdy_stream2 = NULL; |
| 1692 } | 1693 } |
| 1693 | 1694 |
| 1695 TEST_F(SpdySessionSpdy3Test, VerifyDomainAuthentication) { |
| 1696 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1697 SpdySessionDependencies session_deps; |
| 1698 session_deps.host_resolver->set_synchronous_mode(true); |
| 1699 |
| 1700 // No actual data will be sent. |
| 1701 MockWrite writes[] = { |
| 1702 MockWrite(ASYNC, 0, 1) // EOF |
| 1703 }; |
| 1704 |
| 1705 MockRead reads[] = { |
| 1706 MockRead(ASYNC, 0, 0) // EOF |
| 1707 }; |
| 1708 DeterministicSocketData data(reads, arraysize(reads), |
| 1709 writes, arraysize(writes)); |
| 1710 data.set_connect_data(connect_data); |
| 1711 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 1712 |
| 1713 // Load a cert that is valid for: |
| 1714 // www.example.org |
| 1715 // mail.example.org |
| 1716 // www.example.com |
| 1717 FilePath certs_dir = GetTestCertsDirectory(); |
| 1718 scoped_refptr<X509Certificate> test_cert( |
| 1719 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 1720 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
| 1721 |
| 1722 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 1723 ssl.cert = test_cert; |
| 1724 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1725 |
| 1726 scoped_refptr<HttpNetworkSession> http_session( |
| 1727 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 1728 |
| 1729 const std::string kTestHost("www.example.org"); |
| 1730 const int kTestPort = 80; |
| 1731 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 1732 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 1733 |
| 1734 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 1735 |
| 1736 // Create a session. |
| 1737 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 1738 scoped_refptr<SpdySession> session = |
| 1739 spdy_session_pool->Get(pair, BoundNetLog()); |
| 1740 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 1741 |
| 1742 SSLConfig ssl_config; |
| 1743 scoped_refptr<TransportSocketParams> transport_params( |
| 1744 new TransportSocketParams(test_host_port_pair, |
| 1745 MEDIUM, |
| 1746 false, |
| 1747 false, |
| 1748 OnHostResolutionCallback())); |
| 1749 scoped_refptr<SOCKSSocketParams> socks_params; |
| 1750 scoped_refptr<HttpProxySocketParams> http_proxy_params; |
| 1751 scoped_refptr<SSLSocketParams> ssl_params( |
| 1752 new SSLSocketParams(transport_params, |
| 1753 socks_params, |
| 1754 http_proxy_params, |
| 1755 ProxyServer::SCHEME_DIRECT, |
| 1756 test_host_port_pair, |
| 1757 ssl_config, |
| 1758 0, |
| 1759 false, |
| 1760 false)); |
| 1761 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1762 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 1763 ssl_params, MEDIUM, CompletionCallback(), |
| 1764 http_session->GetSSLSocketPool( |
| 1765 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 1766 BoundNetLog())); |
| 1767 |
| 1768 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1769 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); |
| 1770 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); |
| 1771 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.com")); |
| 1772 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); |
| 1773 } |
| 1774 |
| 1775 TEST_F(SpdySessionSpdy3Test, ConnectionPooledWithTlsChannelId) { |
| 1776 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1777 SpdySessionDependencies session_deps; |
| 1778 session_deps.host_resolver->set_synchronous_mode(true); |
| 1779 |
| 1780 // No actual data will be sent. |
| 1781 MockWrite writes[] = { |
| 1782 MockWrite(ASYNC, 0, 1) // EOF |
| 1783 }; |
| 1784 |
| 1785 MockRead reads[] = { |
| 1786 MockRead(ASYNC, 0, 0) // EOF |
| 1787 }; |
| 1788 DeterministicSocketData data(reads, arraysize(reads), |
| 1789 writes, arraysize(writes)); |
| 1790 data.set_connect_data(connect_data); |
| 1791 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 1792 |
| 1793 // Load a cert that is valid for: |
| 1794 // www.example.org |
| 1795 // mail.example.org |
| 1796 // www.example.com |
| 1797 FilePath certs_dir = GetTestCertsDirectory(); |
| 1798 scoped_refptr<X509Certificate> test_cert( |
| 1799 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 1800 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
| 1801 |
| 1802 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 1803 ssl.channel_id_sent = true; |
| 1804 ssl.cert = test_cert; |
| 1805 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1806 |
| 1807 scoped_refptr<HttpNetworkSession> http_session( |
| 1808 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 1809 |
| 1810 const std::string kTestHost("www.example.org"); |
| 1811 const int kTestPort = 80; |
| 1812 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 1813 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 1814 |
| 1815 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 1816 |
| 1817 // Create a session. |
| 1818 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 1819 scoped_refptr<SpdySession> session = |
| 1820 spdy_session_pool->Get(pair, BoundNetLog()); |
| 1821 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 1822 |
| 1823 SSLConfig ssl_config; |
| 1824 scoped_refptr<TransportSocketParams> transport_params( |
| 1825 new TransportSocketParams(test_host_port_pair, |
| 1826 MEDIUM, |
| 1827 false, |
| 1828 false, |
| 1829 OnHostResolutionCallback())); |
| 1830 scoped_refptr<SOCKSSocketParams> socks_params; |
| 1831 scoped_refptr<HttpProxySocketParams> http_proxy_params; |
| 1832 scoped_refptr<SSLSocketParams> ssl_params( |
| 1833 new SSLSocketParams(transport_params, |
| 1834 socks_params, |
| 1835 http_proxy_params, |
| 1836 ProxyServer::SCHEME_DIRECT, |
| 1837 test_host_port_pair, |
| 1838 ssl_config, |
| 1839 0, |
| 1840 false, |
| 1841 false)); |
| 1842 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1843 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 1844 ssl_params, MEDIUM, CompletionCallback(), |
| 1845 http_session->GetSSLSocketPool( |
| 1846 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 1847 BoundNetLog())); |
| 1848 |
| 1849 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1850 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); |
| 1851 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); |
| 1852 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); |
| 1853 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); |
| 1854 } |
| 1855 |
| 1694 } // namespace net | 1856 } // namespace net |
| OLD | NEW |