| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 18 #include "net/base/proxy_delegate.h" | 18 #include "net/base/proxy_delegate.h" |
| 19 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
| 20 #include "net/base/test_data_stream.h" | 20 #include "net/base/test_data_stream.h" |
| 21 #include "net/base/test_proxy_delegate.h" | 21 #include "net/base/test_proxy_delegate.h" |
| 22 #include "net/cert/ct_policy_status.h" |
| 22 #include "net/log/test_net_log.h" | 23 #include "net/log/test_net_log.h" |
| 23 #include "net/log/test_net_log_entry.h" | 24 #include "net/log/test_net_log_entry.h" |
| 24 #include "net/log/test_net_log_util.h" | 25 #include "net/log/test_net_log_util.h" |
| 25 #include "net/proxy/proxy_server.h" | 26 #include "net/proxy/proxy_server.h" |
| 26 #include "net/socket/client_socket_pool_manager.h" | 27 #include "net/socket/client_socket_pool_manager.h" |
| 27 #include "net/socket/next_proto.h" | 28 #include "net/socket/next_proto.h" |
| 28 #include "net/socket/socket_test_util.h" | 29 #include "net/socket/socket_test_util.h" |
| 29 #include "net/spdy/spdy_http_utils.h" | 30 #include "net/spdy/spdy_http_utils.h" |
| 30 #include "net/spdy/spdy_session_pool.h" | 31 #include "net/spdy/spdy_session_pool.h" |
| 31 #include "net/spdy/spdy_session_test_util.h" | 32 #include "net/spdy/spdy_session_test_util.h" |
| 32 #include "net/spdy/spdy_stream.h" | 33 #include "net/spdy/spdy_stream.h" |
| 33 #include "net/spdy/spdy_stream_test_util.h" | 34 #include "net/spdy/spdy_stream_test_util.h" |
| 34 #include "net/spdy/spdy_test_util_common.h" | 35 #include "net/spdy/spdy_test_util_common.h" |
| 35 #include "net/spdy/spdy_test_utils.h" | 36 #include "net/spdy/spdy_test_utils.h" |
| 36 #include "net/test/cert_test_util.h" | 37 #include "net/test/cert_test_util.h" |
| 37 #include "net/test/test_data_directory.h" | 38 #include "net/test/test_data_directory.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" |
| 38 #include "testing/platform_test.h" | 40 #include "testing/platform_test.h" |
| 39 | 41 |
| 40 namespace net { | 42 namespace net { |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 enum TestCase { | 46 enum TestCase { |
| 45 // Test using the SPDY/3.1 protocol. | 47 // Test using the SPDY/3.1 protocol. |
| 46 kTestCaseSPDY31, | 48 kTestCaseSPDY31, |
| 47 | 49 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 base::TimeTicks SlowReads() { | 73 base::TimeTicks SlowReads() { |
| 72 g_time_delta += | 74 g_time_delta += |
| 73 base::TimeDelta::FromMilliseconds(2 * kYieldAfterDurationMilliseconds); | 75 base::TimeDelta::FromMilliseconds(2 * kYieldAfterDurationMilliseconds); |
| 74 return base::TimeTicks::Now() + g_time_delta; | 76 return base::TimeTicks::Now() + g_time_delta; |
| 75 } | 77 } |
| 76 | 78 |
| 77 base::TimeTicks InstantaneousReads() { | 79 base::TimeTicks InstantaneousReads() { |
| 78 return g_time_now; | 80 return g_time_now; |
| 79 } | 81 } |
| 80 | 82 |
| 83 class MockRequireCTDelegate : public TransportSecurityState::RequireCTDelegate { |
| 84 public: |
| 85 MOCK_METHOD1(IsCTRequiredForHost, |
| 86 CTRequirementLevel(const std::string& host)); |
| 87 }; |
| 88 |
| 81 } // namespace | 89 } // namespace |
| 82 | 90 |
| 83 class SpdySessionTest : public PlatformTest, | 91 class SpdySessionTest : public PlatformTest, |
| 84 public ::testing::WithParamInterface<TestCase> { | 92 public ::testing::WithParamInterface<TestCase> { |
| 85 public: | 93 public: |
| 86 // Functions used with RunResumeAfterUnstallTest(). | 94 // Functions used with RunResumeAfterUnstallTest(). |
| 87 | 95 |
| 88 void StallSessionOnly(SpdyStream* stream) { StallSessionSend(); } | 96 void StallSessionOnly(SpdyStream* stream) { StallSessionSend(); } |
| 89 | 97 |
| 90 void StallStreamOnly(SpdyStream* stream) { StallStreamSend(stream); } | 98 void StallStreamOnly(SpdyStream* stream) { StallStreamSend(stream); } |
| (...skipping 5643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5734 SSLInfo ssl_info; | 5742 SSLInfo ssl_info; |
| 5735 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5743 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5736 "spdy_pooling.pem"); | 5744 "spdy_pooling.pem"); |
| 5737 ssl_info.is_issued_by_known_root = true; | 5745 ssl_info.is_issued_by_known_root = true; |
| 5738 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(bad_pin)); | 5746 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(bad_pin)); |
| 5739 | 5747 |
| 5740 EXPECT_FALSE(SpdySession::CanPool( | 5748 EXPECT_FALSE(SpdySession::CanPool( |
| 5741 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5749 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5742 } | 5750 } |
| 5743 | 5751 |
| 5752 TEST(CanPoolTest, CanNotPoolWithBadCTWhenCTRequired) { |
| 5753 using testing::Return; |
| 5754 using CTRequirementLevel = |
| 5755 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; |
| 5756 |
| 5757 SSLInfo ssl_info; |
| 5758 ssl_info.cert = |
| 5759 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 5760 ssl_info.is_issued_by_known_root = true; |
| 5761 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); |
| 5762 ssl_info.ct_cert_policy_compliance = |
| 5763 ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS; |
| 5764 |
| 5765 MockRequireCTDelegate require_ct_delegate; |
| 5766 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) |
| 5767 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); |
| 5768 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) |
| 5769 .WillRepeatedly(Return(CTRequirementLevel::REQUIRED)); |
| 5770 |
| 5771 TransportSecurityState tss; |
| 5772 tss.SetRequireCTDelegate(&require_ct_delegate); |
| 5773 |
| 5774 EXPECT_FALSE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", |
| 5775 "mail.example.org")); |
| 5776 } |
| 5777 |
| 5778 TEST(CanPoolTest, CanPoolWithBadCTWhenCTNotRequired) { |
| 5779 using testing::Return; |
| 5780 using CTRequirementLevel = |
| 5781 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; |
| 5782 |
| 5783 SSLInfo ssl_info; |
| 5784 ssl_info.cert = |
| 5785 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 5786 ssl_info.is_issued_by_known_root = true; |
| 5787 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); |
| 5788 ssl_info.ct_cert_policy_compliance = |
| 5789 ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS; |
| 5790 |
| 5791 MockRequireCTDelegate require_ct_delegate; |
| 5792 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) |
| 5793 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); |
| 5794 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) |
| 5795 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); |
| 5796 |
| 5797 TransportSecurityState tss; |
| 5798 tss.SetRequireCTDelegate(&require_ct_delegate); |
| 5799 |
| 5800 EXPECT_TRUE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", |
| 5801 "mail.example.org")); |
| 5802 } |
| 5803 |
| 5804 TEST(CanPoolTest, CanPoolWithGoodCTWhenCTRequired) { |
| 5805 using testing::Return; |
| 5806 using CTRequirementLevel = |
| 5807 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; |
| 5808 |
| 5809 SSLInfo ssl_info; |
| 5810 ssl_info.cert = |
| 5811 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 5812 ssl_info.is_issued_by_known_root = true; |
| 5813 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); |
| 5814 ssl_info.ct_cert_policy_compliance = |
| 5815 ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS; |
| 5816 |
| 5817 MockRequireCTDelegate require_ct_delegate; |
| 5818 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) |
| 5819 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); |
| 5820 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) |
| 5821 .WillRepeatedly(Return(CTRequirementLevel::REQUIRED)); |
| 5822 |
| 5823 TransportSecurityState tss; |
| 5824 tss.SetRequireCTDelegate(&require_ct_delegate); |
| 5825 |
| 5826 EXPECT_TRUE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", |
| 5827 "mail.example.org")); |
| 5828 } |
| 5829 |
| 5744 TEST(CanPoolTest, CanPoolWithAcceptablePins) { | 5830 TEST(CanPoolTest, CanPoolWithAcceptablePins) { |
| 5745 uint8_t primary_pin = 1; | 5831 uint8_t primary_pin = 1; |
| 5746 uint8_t backup_pin = 2; | 5832 uint8_t backup_pin = 2; |
| 5747 TransportSecurityState tss; | 5833 TransportSecurityState tss; |
| 5748 test::AddPin(&tss, "mail.example.org", primary_pin, backup_pin); | 5834 test::AddPin(&tss, "mail.example.org", primary_pin, backup_pin); |
| 5749 | 5835 |
| 5750 SSLInfo ssl_info; | 5836 SSLInfo ssl_info; |
| 5751 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5837 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5752 "spdy_pooling.pem"); | 5838 "spdy_pooling.pem"); |
| 5753 ssl_info.is_issued_by_known_root = true; | 5839 ssl_info.is_issued_by_known_root = true; |
| 5754 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5840 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
| 5755 | 5841 |
| 5756 EXPECT_TRUE(SpdySession::CanPool( | 5842 EXPECT_TRUE(SpdySession::CanPool( |
| 5757 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5843 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5758 } | 5844 } |
| 5759 | 5845 |
| 5760 } // namespace net | 5846 } // namespace net |
| OLD | NEW |