Chromium Code Reviews| 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 5638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5729 SSLInfo ssl_info; | 5737 SSLInfo ssl_info; |
| 5730 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5738 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5731 "spdy_pooling.pem"); | 5739 "spdy_pooling.pem"); |
| 5732 ssl_info.is_issued_by_known_root = true; | 5740 ssl_info.is_issued_by_known_root = true; |
| 5733 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(bad_pin)); | 5741 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(bad_pin)); |
| 5734 | 5742 |
| 5735 EXPECT_FALSE(SpdySession::CanPool( | 5743 EXPECT_FALSE(SpdySession::CanPool( |
| 5736 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5744 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5737 } | 5745 } |
| 5738 | 5746 |
| 5747 TEST(CanPoolTest, CanNotPoolWithBadCTWhenCTRequired) { | |
| 5748 using testing::_; | |
| 5749 using testing::Return; | |
| 5750 using CTRequirementLevel = | |
| 5751 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; | |
| 5752 | |
| 5753 SSLInfo ssl_info; | |
| 5754 ssl_info.cert = | |
| 5755 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 5756 ssl_info.is_issued_by_known_root = true; | |
| 5757 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); | |
| 5758 ssl_info.ct_cert_policy_compliance = | |
| 5759 ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS; | |
| 5760 | |
| 5761 MockRequireCTDelegate require_ct_delegate; | |
| 5762 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) | |
| 5763 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); | |
|
davidben
2016/06/23 19:51:43
Only mail.example.org is queried, right?
Ryan Sleevi
2016/06/23 21:38:31
Correct, but nothing in the interface contract of
| |
| 5764 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) | |
| 5765 .WillRepeatedly(Return(CTRequirementLevel::REQUIRED)); | |
| 5766 | |
| 5767 TransportSecurityState tss; | |
| 5768 tss.SetRequireCTDelegate(&require_ct_delegate); | |
| 5769 | |
| 5770 EXPECT_FALSE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", | |
| 5771 "mail.example.org")); | |
| 5772 } | |
| 5773 | |
| 5774 TEST(CanPoolTest, CanPoolWithBadCTWhenCTNotRequired) { | |
| 5775 using testing::_; | |
| 5776 using testing::Return; | |
| 5777 using CTRequirementLevel = | |
| 5778 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; | |
| 5779 | |
| 5780 SSLInfo ssl_info; | |
| 5781 ssl_info.cert = | |
| 5782 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 5783 ssl_info.is_issued_by_known_root = true; | |
| 5784 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); | |
| 5785 ssl_info.ct_cert_policy_compliance = | |
| 5786 ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS; | |
| 5787 | |
| 5788 MockRequireCTDelegate require_ct_delegate; | |
| 5789 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) | |
| 5790 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); | |
|
davidben
2016/06/23 19:51:43
Ditto.
| |
| 5791 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) | |
| 5792 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); | |
| 5793 | |
| 5794 TransportSecurityState tss; | |
| 5795 tss.SetRequireCTDelegate(&require_ct_delegate); | |
| 5796 | |
| 5797 EXPECT_TRUE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", | |
| 5798 "mail.example.org")); | |
| 5799 } | |
| 5800 | |
| 5801 TEST(CanPoolTest, CanPoolWithGoodCTWhenCTRequired) { | |
| 5802 using testing::_; | |
| 5803 using testing::Return; | |
| 5804 using CTRequirementLevel = | |
| 5805 TransportSecurityState::RequireCTDelegate::CTRequirementLevel; | |
| 5806 | |
| 5807 SSLInfo ssl_info; | |
| 5808 ssl_info.cert = | |
| 5809 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 5810 ssl_info.is_issued_by_known_root = true; | |
| 5811 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(1)); | |
| 5812 ssl_info.ct_cert_policy_compliance = | |
| 5813 ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS; | |
| 5814 | |
| 5815 MockRequireCTDelegate require_ct_delegate; | |
| 5816 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("www.example.org")) | |
| 5817 .WillRepeatedly(Return(CTRequirementLevel::NOT_REQUIRED)); | |
|
davidben
2016/06/23 19:51:43
Ditto.
| |
| 5818 EXPECT_CALL(require_ct_delegate, IsCTRequiredForHost("mail.example.org")) | |
| 5819 .WillRepeatedly(Return(CTRequirementLevel::REQUIRED)); | |
| 5820 | |
| 5821 TransportSecurityState tss; | |
| 5822 tss.SetRequireCTDelegate(&require_ct_delegate); | |
| 5823 | |
| 5824 EXPECT_TRUE(SpdySession::CanPool(&tss, ssl_info, "www.example.org", | |
| 5825 "mail.example.org")); | |
| 5826 } | |
| 5827 | |
| 5739 TEST(CanPoolTest, CanPoolWithAcceptablePins) { | 5828 TEST(CanPoolTest, CanPoolWithAcceptablePins) { |
| 5740 uint8_t primary_pin = 1; | 5829 uint8_t primary_pin = 1; |
| 5741 uint8_t backup_pin = 2; | 5830 uint8_t backup_pin = 2; |
| 5742 TransportSecurityState tss; | 5831 TransportSecurityState tss; |
| 5743 test::AddPin(&tss, "mail.example.org", primary_pin, backup_pin); | 5832 test::AddPin(&tss, "mail.example.org", primary_pin, backup_pin); |
| 5744 | 5833 |
| 5745 SSLInfo ssl_info; | 5834 SSLInfo ssl_info; |
| 5746 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5835 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5747 "spdy_pooling.pem"); | 5836 "spdy_pooling.pem"); |
| 5748 ssl_info.is_issued_by_known_root = true; | 5837 ssl_info.is_issued_by_known_root = true; |
| 5749 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5838 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
| 5750 | 5839 |
| 5751 EXPECT_TRUE(SpdySession::CanPool( | 5840 EXPECT_TRUE(SpdySession::CanPool( |
| 5752 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5841 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5753 } | 5842 } |
| 5754 | 5843 |
| 5755 } // namespace net | 5844 } // namespace net |
| OLD | NEW |