Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(952)

Side by Side Diff: net/quic/core/quic_server_session_base_test.cc

Issue 2453113002: Fix object-lifetime issues in async GetProof callpaths (Closed)
Patch Set: Updated patchset dependency Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_crypto_stream.cc ('k') | net/quic/test_tools/crypto_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/quic/core/quic_server_session_base.h" 5 #include "net/quic/core/quic_server_session_base.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "net/quic/core/crypto/quic_crypto_server_config.h" 12 #include "net/quic/core/crypto/quic_crypto_server_config.h"
13 #include "net/quic/core/crypto/quic_random.h" 13 #include "net/quic/core/crypto/quic_random.h"
14 #include "net/quic/core/proto/cached_network_parameters.pb.h" 14 #include "net/quic/core/proto/cached_network_parameters.pb.h"
15 #include "net/quic/core/quic_connection.h" 15 #include "net/quic/core/quic_connection.h"
16 #include "net/quic/core/quic_crypto_server_stream.h" 16 #include "net/quic/core/quic_crypto_server_stream.h"
17 #include "net/quic/core/quic_utils.h" 17 #include "net/quic/core/quic_utils.h"
18 #include "net/quic/test_tools/crypto_test_utils.h" 18 #include "net/quic/test_tools/crypto_test_utils.h"
19 #include "net/quic/test_tools/fake_proof_source.h"
19 #include "net/quic/test_tools/quic_config_peer.h" 20 #include "net/quic/test_tools/quic_config_peer.h"
20 #include "net/quic/test_tools/quic_connection_peer.h" 21 #include "net/quic/test_tools/quic_connection_peer.h"
22 #include "net/quic/test_tools/quic_crypto_server_config_peer.h"
21 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 23 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
22 #include "net/quic/test_tools/quic_session_peer.h" 24 #include "net/quic/test_tools/quic_session_peer.h"
23 #include "net/quic/test_tools/quic_spdy_session_peer.h" 25 #include "net/quic/test_tools/quic_spdy_session_peer.h"
24 #include "net/quic/test_tools/quic_spdy_stream_peer.h" 26 #include "net/quic/test_tools/quic_spdy_stream_peer.h"
25 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" 27 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h"
26 #include "net/quic/test_tools/quic_test_utils.h" 28 #include "net/quic/test_tools/quic_test_utils.h"
27 #include "net/test/gtest_util.h" 29 #include "net/test/gtest_util.h"
28 #include "net/tools/quic/quic_simple_server_stream.h" 30 #include "net/tools/quic/quic_simple_server_stream.h"
29 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" 31 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h"
30 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 crypto_config, compressed_certs_cache, 119 crypto_config, compressed_certs_cache,
118 FLAGS_enable_quic_stateless_reject_support, this, stream_helper()); 120 FLAGS_enable_quic_stateless_reject_support, this, stream_helper());
119 } 121 }
120 }; 122 };
121 123
122 const size_t kMaxStreamsForTest = 10; 124 const size_t kMaxStreamsForTest = 10;
123 125
124 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> { 126 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> {
125 protected: 127 protected:
126 QuicServerSessionBaseTest() 128 QuicServerSessionBaseTest()
129 : QuicServerSessionBaseTest(CryptoTestUtils::ProofSourceForTesting()) {}
130
131 explicit QuicServerSessionBaseTest(std::unique_ptr<ProofSource> proof_source)
127 : crypto_config_(QuicCryptoServerConfig::TESTING, 132 : crypto_config_(QuicCryptoServerConfig::TESTING,
128 QuicRandom::GetInstance(), 133 QuicRandom::GetInstance(),
129 CryptoTestUtils::ProofSourceForTesting()), 134 std::move(proof_source)),
130 compressed_certs_cache_( 135 compressed_certs_cache_(
131 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { 136 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) {
132 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); 137 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest);
133 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); 138 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest);
134 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, 139 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_,
135 kMaxStreamsForTest); 140 kMaxStreamsForTest);
136 config_.SetInitialStreamFlowControlWindowToSend( 141 config_.SetInitialStreamFlowControlWindowToSend(
137 kInitialStreamFlowControlWindowForTest); 142 kInitialStreamFlowControlWindowForTest);
138 config_.SetInitialSessionFlowControlWindowToSend( 143 config_.SetInitialSessionFlowControlWindowToSend(
139 kInitialSessionFlowControlWindowForTest); 144 kInitialSessionFlowControlWindowForTest);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 arg->max_bandwidth_timestamp_seconds() == 183 arg->max_bandwidth_timestamp_seconds() ==
179 reference.max_bandwidth_timestamp_seconds() && 184 reference.max_bandwidth_timestamp_seconds() &&
180 arg->min_rtt_ms() == reference.min_rtt_ms() && 185 arg->min_rtt_ms() == reference.min_rtt_ms() &&
181 arg->previous_connection_state() == 186 arg->previous_connection_state() ==
182 reference.previous_connection_state()); 187 reference.previous_connection_state());
183 } 188 }
184 189
185 INSTANTIATE_TEST_CASE_P(Tests, 190 INSTANTIATE_TEST_CASE_P(Tests,
186 QuicServerSessionBaseTest, 191 QuicServerSessionBaseTest,
187 ::testing::ValuesIn(AllSupportedVersions())); 192 ::testing::ValuesIn(AllSupportedVersions()));
188
189 TEST_P(QuicServerSessionBaseTest, ServerPushDisabledByDefault) { 193 TEST_P(QuicServerSessionBaseTest, ServerPushDisabledByDefault) {
190 FLAGS_quic_enable_server_push_by_default = true; 194 FLAGS_quic_enable_server_push_by_default = true;
191 // Without the client explicitly sending kSPSH, server push will be disabled 195 // Without the client explicitly sending kSPSH, server push will be disabled
192 // at the server, until version 35 when it is enabled by default. 196 // at the server, until version 35 when it is enabled by default.
193 EXPECT_FALSE( 197 EXPECT_FALSE(
194 session_->config()->HasReceivedConnectionOptions() && 198 session_->config()->HasReceivedConnectionOptions() &&
195 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH)); 199 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH));
196 session_->OnConfigNegotiated(); 200 session_->OnConfigNegotiated();
197 if (GetParam() <= QUIC_VERSION_34) { 201 if (GetParam() <= QUIC_VERSION_34) {
198 EXPECT_FALSE(session_->server_push_enabled()); 202 EXPECT_FALSE(session_->server_push_enabled());
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 570 }
567 571
568 TEST_P(QuicServerSessionBaseTest, NoBandwidthResumptionByDefault) { 572 TEST_P(QuicServerSessionBaseTest, NoBandwidthResumptionByDefault) {
569 EXPECT_FALSE( 573 EXPECT_FALSE(
570 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); 574 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get()));
571 session_->OnConfigNegotiated(); 575 session_->OnConfigNegotiated();
572 EXPECT_FALSE( 576 EXPECT_FALSE(
573 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); 577 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get()));
574 } 578 }
575 579
580 // Tests which check the lifetime management of data members of
581 // QuicCryptoServerStream objects when async GetProof is in use.
582 class StreamMemberLifetimeTest : public QuicServerSessionBaseTest {
583 public:
584 StreamMemberLifetimeTest()
585 : QuicServerSessionBaseTest(
586 std::unique_ptr<FakeProofSource>(new FakeProofSource())),
587 crypto_config_peer_(&crypto_config_) {
588 GetFakeProofSource()->Activate();
589 }
590
591 FakeProofSource* GetFakeProofSource() const {
592 return static_cast<FakeProofSource*>(crypto_config_peer_.GetProofSource());
593 }
594
595 private:
596 QuicCryptoServerConfigPeer crypto_config_peer_;
597 };
598
599 INSTANTIATE_TEST_CASE_P(StreamMemberLifetimeTests,
600 StreamMemberLifetimeTest,
601 ::testing::ValuesIn(AllSupportedVersions()));
602
603 // Trigger an operation which causes an async invocation of
604 // ProofSource::GetProof. Delay the completion of the operation until after the
605 // stream has been destroyed, and verify that there are no memory bugs.
606 TEST_P(StreamMemberLifetimeTest, Basic) {
607 FLAGS_enable_async_get_proof = true;
608 FLAGS_quic_buffer_packet_till_chlo = true;
609 FLAGS_enable_quic_stateless_reject_support = true;
610 FLAGS_quic_use_cheap_stateless_rejects = true;
611 FLAGS_quic_create_session_after_insertion = true;
612
613 const QuicClock* clock = helper_.GetClock();
614 QuicVersion version = AllSupportedVersions().front();
615 CryptoHandshakeMessage chlo = CryptoTestUtils::GenerateDefaultInchoateCHLO(
616 clock, version, &crypto_config_);
617 chlo.SetVector(kCOPT, QuicTagVector{kSREJ});
618 std::vector<QuicVersion> packet_version_list = {version};
619 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
620 1, true, false, false, kDefaultPathId, 1,
621 chlo.GetSerialized().AsStringPiece().as_string(),
622 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
623 &packet_version_list));
624
625 EXPECT_CALL(stream_helper_, CanAcceptClientHello(_, _, _))
626 .WillOnce(testing::Return(true));
627 EXPECT_CALL(stream_helper_, GenerateConnectionIdForReject(_))
628 .WillOnce(testing::Return(12345));
629
630 // Set the current packet
631 QuicConnectionPeer::SetCurrentPacket(session_->connection(),
632 packet->AsStringPiece());
633
634 // Yes, this is horrible. But it's the easiest way to trigger the behavior we
635 // need to exercise.
636 QuicCryptoServerStreamBase* crypto_stream =
637 const_cast<QuicCryptoServerStreamBase*>(session_->crypto_stream());
638
639 // Feed the CHLO into the crypto stream, which will trigger a call to
640 // ProofSource::GetProof
641 crypto_stream->OnHandshakeMessage(chlo);
642 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1);
643
644 // Destroy the stream
645 session_.reset();
646
647 // Allow the async ProofSource::GetProof call to complete. Verify (under
648 // asan) that this does not result in accesses to any freed memory from the
649 // session or its subobjects.
650 GetFakeProofSource()->InvokePendingCallback(0);
651 }
652
576 } // namespace 653 } // namespace
577 } // namespace test 654 } // namespace test
578 } // namespace net 655 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_crypto_stream.cc ('k') | net/quic/test_tools/crypto_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698