| OLD | NEW |
| 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" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 connection, | 73 connection, |
| 74 visitor, | 74 visitor, |
| 75 helper, | 75 helper, |
| 76 crypto_config, | 76 crypto_config, |
| 77 compressed_certs_cache), | 77 compressed_certs_cache), |
| 78 response_cache_(response_cache) {} | 78 response_cache_(response_cache) {} |
| 79 | 79 |
| 80 ~TestServerSession() override { delete connection(); }; | 80 ~TestServerSession() override { delete connection(); }; |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 // TODO(ckrasic) - for two below, remove when |
| 84 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. |
| 83 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override { | 85 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override { |
| 84 if (!ShouldCreateIncomingDynamicStream(id)) { | 86 if (!ShouldCreateIncomingDynamicStream(id)) { |
| 85 return nullptr; | 87 return nullptr; |
| 86 } | 88 } |
| 87 QuicSpdyStream* stream = | 89 QuicSpdyStream* stream = |
| 88 new QuicSimpleServerStream(id, this, response_cache_); | 90 new QuicSimpleServerStream(id, this, response_cache_); |
| 89 ActivateStream(QuicWrapUnique(stream)); | 91 ActivateStream(QuicWrapUnique(stream)); |
| 90 return stream; | 92 return stream; |
| 91 } | 93 } |
| 92 | 94 |
| 93 QuicSpdyStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { | 95 QuicSpdyStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { |
| 94 if (!ShouldCreateOutgoingDynamicStream()) { | 96 if (!ShouldCreateOutgoingDynamicStream()) { |
| 95 return nullptr; | 97 return nullptr; |
| 96 } | 98 } |
| 97 | 99 |
| 98 QuicSpdyStream* stream = new QuicSimpleServerStream( | 100 QuicSpdyStream* stream = new QuicSimpleServerStream( |
| 99 GetNextOutgoingStreamId(), this, response_cache_); | 101 GetNextOutgoingStreamId(), this, response_cache_); |
| 100 stream->SetPriority(priority); | 102 stream->SetPriority(priority); |
| 101 ActivateStream(QuicWrapUnique(stream)); | 103 ActivateStream(QuicWrapUnique(stream)); |
| 102 return stream; | 104 return stream; |
| 103 } | 105 } |
| 104 | 106 |
| 107 std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) override { |
| 108 return QuicMakeUnique<QuicSimpleServerStream>(id, this, response_cache_); |
| 109 } |
| 110 |
| 105 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 111 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
| 106 const QuicCryptoServerConfig* crypto_config, | 112 const QuicCryptoServerConfig* crypto_config, |
| 107 QuicCompressedCertsCache* compressed_certs_cache) override { | 113 QuicCompressedCertsCache* compressed_certs_cache) override { |
| 108 return new QuicCryptoServerStream( | 114 return new QuicCryptoServerStream( |
| 109 crypto_config, compressed_certs_cache, | 115 crypto_config, compressed_certs_cache, |
| 110 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support, this, | 116 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support, this, |
| 111 stream_helper()); | 117 stream_helper()); |
| 112 } | 118 } |
| 113 | 119 |
| 114 private: | 120 private: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 144 config_, connection_, &owner_, &stream_helper_, &crypto_config_, | 150 config_, connection_, &owner_, &stream_helper_, &crypto_config_, |
| 145 &compressed_certs_cache_, &response_cache_)); | 151 &compressed_certs_cache_, &response_cache_)); |
| 146 MockClock clock; | 152 MockClock clock; |
| 147 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 153 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 148 QuicRandom::GetInstance(), &clock, | 154 QuicRandom::GetInstance(), &clock, |
| 149 QuicCryptoServerConfig::ConfigOptions())); | 155 QuicCryptoServerConfig::ConfigOptions())); |
| 150 session_->Initialize(); | 156 session_->Initialize(); |
| 151 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 157 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 152 } | 158 } |
| 153 | 159 |
| 160 QuicStreamId GetNthClientInitiatedId(int n) { |
| 161 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(*session_, n); |
| 162 } |
| 163 |
| 164 QuicStreamId GetNthServerInitiatedId(int n) { |
| 165 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(*session_, n); |
| 166 } |
| 167 |
| 154 StrictMock<MockQuicSessionVisitor> owner_; | 168 StrictMock<MockQuicSessionVisitor> owner_; |
| 155 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; | 169 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
| 156 MockQuicConnectionHelper helper_; | 170 MockQuicConnectionHelper helper_; |
| 157 MockAlarmFactory alarm_factory_; | 171 MockAlarmFactory alarm_factory_; |
| 158 StrictMock<MockQuicConnection>* connection_; | 172 StrictMock<MockQuicConnection>* connection_; |
| 159 QuicConfig config_; | 173 QuicConfig config_; |
| 160 QuicCryptoServerConfig crypto_config_; | 174 QuicCryptoServerConfig crypto_config_; |
| 161 QuicCompressedCertsCache compressed_certs_cache_; | 175 QuicCompressedCertsCache compressed_certs_cache_; |
| 162 QuicHttpResponseCache response_cache_; | 176 QuicHttpResponseCache response_cache_; |
| 163 std::unique_ptr<TestServerSession> session_; | 177 std::unique_ptr<TestServerSession> session_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 191 EXPECT_FALSE( | 205 EXPECT_FALSE( |
| 192 session_->config()->HasReceivedConnectionOptions() && | 206 session_->config()->HasReceivedConnectionOptions() && |
| 193 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH)); | 207 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH)); |
| 194 session_->OnConfigNegotiated(); | 208 session_->OnConfigNegotiated(); |
| 195 EXPECT_TRUE(session_->server_push_enabled()); | 209 EXPECT_TRUE(session_->server_push_enabled()); |
| 196 } | 210 } |
| 197 | 211 |
| 198 TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) { | 212 TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) { |
| 199 // Open a stream, then reset it. | 213 // Open a stream, then reset it. |
| 200 // Send two bytes of payload to open it. | 214 // Send two bytes of payload to open it. |
| 201 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 215 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0, |
| 216 QuicStringPiece("HT")); |
| 202 session_->OnStreamFrame(data1); | 217 session_->OnStreamFrame(data1); |
| 203 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 218 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 204 | 219 |
| 205 // Send a reset (and expect the peer to send a RST in response). | 220 // Send a reset (and expect the peer to send a RST in response). |
| 206 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 221 QuicRstStreamFrame rst1(GetNthClientInitiatedId(0), |
| 207 0); | 222 QUIC_ERROR_PROCESSING_STREAM, 0); |
| 208 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 223 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
| 209 EXPECT_CALL(*connection_, | 224 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
| 210 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 225 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
| 211 visitor_->OnRstStream(rst1); | 226 visitor_->OnRstStream(rst1); |
| 212 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 227 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 213 | 228 |
| 214 // Send the same two bytes of payload in a new packet. | 229 // Send the same two bytes of payload in a new packet. |
| 215 visitor_->OnStreamFrame(data1); | 230 visitor_->OnStreamFrame(data1); |
| 216 | 231 |
| 217 // The stream should not be re-opened. | 232 // The stream should not be re-opened. |
| 218 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 233 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 219 EXPECT_TRUE(connection_->connected()); | 234 EXPECT_TRUE(connection_->connected()); |
| 220 } | 235 } |
| 221 | 236 |
| 222 TEST_P(QuicServerSessionBaseTest, NeverOpenStreamDueToReset) { | 237 TEST_P(QuicServerSessionBaseTest, NeverOpenStreamDueToReset) { |
| 223 // Send a reset (and expect the peer to send a RST in response). | 238 // Send a reset (and expect the peer to send a RST in response). |
| 224 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 239 QuicRstStreamFrame rst1(GetNthClientInitiatedId(0), |
| 225 0); | 240 QUIC_ERROR_PROCESSING_STREAM, 0); |
| 226 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 241 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
| 227 EXPECT_CALL(*connection_, | 242 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
| 228 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 243 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
| 229 visitor_->OnRstStream(rst1); | 244 visitor_->OnRstStream(rst1); |
| 230 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 245 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 231 | 246 |
| 232 // Send two bytes of payload. | 247 // Send two bytes of payload. |
| 233 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 248 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0, |
| 249 QuicStringPiece("HT")); |
| 234 visitor_->OnStreamFrame(data1); | 250 visitor_->OnStreamFrame(data1); |
| 235 | 251 |
| 236 // The stream should never be opened, now that the reset is received. | 252 // The stream should never be opened, now that the reset is received. |
| 237 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 253 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 238 EXPECT_TRUE(connection_->connected()); | 254 EXPECT_TRUE(connection_->connected()); |
| 239 } | 255 } |
| 240 | 256 |
| 241 TEST_P(QuicServerSessionBaseTest, AcceptClosedStream) { | 257 TEST_P(QuicServerSessionBaseTest, AcceptClosedStream) { |
| 242 // Send (empty) compressed headers followed by two bytes of data. | 258 // Send (empty) compressed headers followed by two bytes of data. |
| 243 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, | 259 QuicStreamFrame frame1(GetNthClientInitiatedId(0), false, 0, |
| 244 QuicStringPiece("\1\0\0\0\0\0\0\0HT")); | 260 QuicStringPiece("\1\0\0\0\0\0\0\0HT")); |
| 245 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, | 261 QuicStreamFrame frame2(GetNthClientInitiatedId(1), false, 0, |
| 246 QuicStringPiece("\2\0\0\0\0\0\0\0HT")); | 262 QuicStringPiece("\2\0\0\0\0\0\0\0HT")); |
| 247 visitor_->OnStreamFrame(frame1); | 263 visitor_->OnStreamFrame(frame1); |
| 248 visitor_->OnStreamFrame(frame2); | 264 visitor_->OnStreamFrame(frame2); |
| 249 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 265 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
| 250 | 266 |
| 251 // Send a reset (and expect the peer to send a RST in response). | 267 // Send a reset (and expect the peer to send a RST in response). |
| 252 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); | 268 QuicRstStreamFrame rst(GetNthClientInitiatedId(0), |
| 269 QUIC_ERROR_PROCESSING_STREAM, 0); |
| 253 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 270 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
| 254 EXPECT_CALL(*connection_, | 271 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
| 255 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 272 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
| 256 visitor_->OnRstStream(rst); | 273 visitor_->OnRstStream(rst); |
| 257 | 274 |
| 258 // If we were tracking, we'd probably want to reject this because it's data | 275 // If we were tracking, we'd probably want to reject this because it's data |
| 259 // past the reset point of stream 3. As it's a closed stream we just drop the | 276 // past the reset point of stream 3. As it's a closed stream we just drop the |
| 260 // data on the floor, but accept the packet because it has data for stream 5. | 277 // data on the floor, but accept the packet because it has data for stream 5. |
| 261 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, QuicStringPiece("TP")); | 278 QuicStreamFrame frame3(GetNthClientInitiatedId(0), false, 2, |
| 262 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, QuicStringPiece("TP")); | 279 QuicStringPiece("TP")); |
| 280 QuicStreamFrame frame4(GetNthClientInitiatedId(1), false, 2, |
| 281 QuicStringPiece("TP")); |
| 263 visitor_->OnStreamFrame(frame3); | 282 visitor_->OnStreamFrame(frame3); |
| 264 visitor_->OnStreamFrame(frame4); | 283 visitor_->OnStreamFrame(frame4); |
| 265 // The stream should never be opened, now that the reset is received. | 284 // The stream should never be opened, now that the reset is received. |
| 266 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 285 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 267 EXPECT_TRUE(connection_->connected()); | 286 EXPECT_TRUE(connection_->connected()); |
| 268 } | 287 } |
| 269 | 288 |
| 270 TEST_P(QuicServerSessionBaseTest, MaxOpenStreams) { | 289 TEST_P(QuicServerSessionBaseTest, MaxOpenStreams) { |
| 271 // Test that the server refuses if a client attempts to open too many data | 290 // Test that the server refuses if a client attempts to open too many data |
| 272 // streams. The server accepts slightly more than the negotiated stream limit | 291 // streams. The server accepts slightly more than the negotiated stream limit |
| 273 // to deal with rare cases where a client FIN/RST is lost. | 292 // to deal with rare cases where a client FIN/RST is lost. |
| 274 | 293 |
| 275 // The slightly increased stream limit is set during config negotiation. It | 294 // The slightly increased stream limit is set during config negotiation. It |
| 276 // is either an increase of 10 over negotiated limit, or a fixed percentage | 295 // is either an increase of 10 over negotiated limit, or a fixed percentage |
| 277 // scaling, whichever is larger. Test both before continuing. | 296 // scaling, whichever is larger. Test both before continuing. |
| 278 session_->OnConfigNegotiated(); | 297 session_->OnConfigNegotiated(); |
| 279 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, | 298 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, |
| 280 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); | 299 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); |
| 281 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, | 300 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, |
| 282 session_->max_open_incoming_streams()); | 301 session_->max_open_incoming_streams()); |
| 283 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 302 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 284 QuicStreamId stream_id = kClientDataStreamId1; | 303 QuicStreamId stream_id = GetNthClientInitiatedId(0); |
| 285 // Open the max configured number of streams, should be no problem. | 304 // Open the max configured number of streams, should be no problem. |
| 286 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 305 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
| 287 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 306 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 288 session_.get(), stream_id)); | 307 session_.get(), stream_id)); |
| 289 stream_id += 2; | 308 stream_id += QuicSpdySessionPeer::NextStreamId(*session_); |
| 290 } | 309 } |
| 291 | 310 |
| 292 // Open more streams: server should accept slightly more than the limit. | 311 // Open more streams: server should accept slightly more than the limit. |
| 293 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { | 312 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { |
| 294 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 313 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 295 session_.get(), stream_id)); | 314 session_.get(), stream_id)); |
| 296 stream_id += 2; | 315 stream_id += QuicSpdySessionPeer::NextStreamId(*session_); |
| 297 } | 316 } |
| 298 | 317 |
| 299 // Now violate the server's internal stream limit. | 318 // Now violate the server's internal stream limit. |
| 300 stream_id += 2; | 319 stream_id += QuicSpdySessionPeer::NextStreamId(*session_); |
| 301 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 320 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 302 EXPECT_CALL(*connection_, SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0)); | 321 EXPECT_CALL(*connection_, SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0)); |
| 303 // Even if the connection remains open, the stream creation should fail. | 322 // Even if the connection remains open, the stream creation should fail. |
| 304 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 323 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 305 session_.get(), stream_id)); | 324 session_.get(), stream_id)); |
| 306 } | 325 } |
| 307 | 326 |
| 308 TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) { | 327 TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) { |
| 309 // Test that the server closes the connection if a client makes too many data | 328 // Test that the server closes the connection if a client makes too many data |
| 310 // streams available. The server accepts slightly more than the negotiated | 329 // streams available. The server accepts slightly more than the negotiated |
| 311 // stream limit to deal with rare cases where a client FIN/RST is lost. | 330 // stream limit to deal with rare cases where a client FIN/RST is lost. |
| 312 | 331 |
| 313 session_->OnConfigNegotiated(); | 332 session_->OnConfigNegotiated(); |
| 314 const size_t kAvailableStreamLimit = session_->MaxAvailableStreams(); | 333 const size_t kAvailableStreamLimit = session_->MaxAvailableStreams(); |
| 315 EXPECT_EQ( | 334 EXPECT_EQ( |
| 316 session_->max_open_incoming_streams() * kMaxAvailableStreamsMultiplier, | 335 session_->max_open_incoming_streams() * kMaxAvailableStreamsMultiplier, |
| 317 session_->MaxAvailableStreams()); | 336 session_->MaxAvailableStreams()); |
| 318 // The protocol specification requires that there can be at least 10 times | 337 // The protocol specification requires that there can be at least 10 times |
| 319 // as many available streams as the connection's maximum open streams. | 338 // as many available streams as the connection's maximum open streams. |
| 320 EXPECT_LE(10 * kMaxStreamsForTest, kAvailableStreamLimit); | 339 EXPECT_LE(10 * kMaxStreamsForTest, kAvailableStreamLimit); |
| 321 | 340 |
| 322 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 341 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 323 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 342 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 324 session_.get(), kClientDataStreamId1)); | 343 session_.get(), GetNthClientInitiatedId(0))); |
| 325 | 344 |
| 326 // Establish available streams up to the server's limit. | 345 // Establish available streams up to the server's limit. |
| 346 QuicStreamId next_id = QuicSpdySessionPeer::NextStreamId(*session_); |
| 327 const int kLimitingStreamId = | 347 const int kLimitingStreamId = |
| 328 kClientDataStreamId1 + (kAvailableStreamLimit)*2 + 2; | 348 GetNthClientInitiatedId(kAvailableStreamLimit + 1); |
| 329 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 349 EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 330 session_.get(), kLimitingStreamId)); | 350 session_.get(), kLimitingStreamId)); |
| 331 | 351 |
| 332 // A further available stream will result in connection close. | 352 // A further available stream will result in connection close. |
| 333 EXPECT_CALL(*connection_, | 353 EXPECT_CALL(*connection_, |
| 334 CloseConnection(QUIC_TOO_MANY_AVAILABLE_STREAMS, _, _)); | 354 CloseConnection(QUIC_TOO_MANY_AVAILABLE_STREAMS, _, _)); |
| 335 // This forces stream kLimitingStreamId + 2 to become available, which | 355 // This forces stream kLimitingStreamId + 2 to become available, which |
| 336 // violates the quota. | 356 // violates the quota. |
| 337 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 357 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 338 session_.get(), kLimitingStreamId + 4)); | 358 session_.get(), kLimitingStreamId + 2 * next_id)); |
| 339 } | 359 } |
| 340 | 360 |
| 341 // TODO(ckrasic): remove this when | 361 // TODO(ckrasic): remove this when |
| 342 // FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default is | 362 // FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default is |
| 343 // deprecated. | 363 // deprecated. |
| 344 TEST_P(QuicServerSessionBaseTest, EnableServerPushThroughConnectionOption) { | 364 TEST_P(QuicServerSessionBaseTest, EnableServerPushThroughConnectionOption) { |
| 345 FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default = false; | 365 FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default = false; |
| 346 // Assume server received server push connection option. | 366 // Assume server received server push connection option. |
| 347 QuicTagVector copt; | 367 QuicTagVector copt; |
| 348 copt.push_back(kSPSH); | 368 copt.push_back(kSPSH); |
| 349 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); | 369 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); |
| 350 session_->OnConfigNegotiated(); | 370 session_->OnConfigNegotiated(); |
| 351 EXPECT_TRUE(session_->server_push_enabled()); | 371 EXPECT_TRUE(session_->server_push_enabled()); |
| 352 } | 372 } |
| 353 | 373 |
| 354 TEST_P(QuicServerSessionBaseTest, GetEvenIncomingError) { | 374 TEST_P(QuicServerSessionBaseTest, GetEvenIncomingError) { |
| 355 // Incoming streams on the server session must be odd. | 375 // Incoming streams on the server session must be odd. |
| 356 EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _)); | 376 EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _)); |
| 357 EXPECT_EQ(nullptr, QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 377 EXPECT_EQ(nullptr, QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 358 session_.get(), 4)); | 378 session_.get(), GetNthServerInitiatedId(0))); |
| 359 } | 379 } |
| 360 | 380 |
| 361 TEST_P(QuicServerSessionBaseTest, GetStreamDisconnected) { | 381 TEST_P(QuicServerSessionBaseTest, GetStreamDisconnected) { |
| 362 // Don't create new streams if the connection is disconnected. | 382 // Don't create new streams if the connection is disconnected. |
| 363 QuicConnectionPeer::TearDownLocalConnectionState(connection_); | 383 QuicConnectionPeer::TearDownLocalConnectionState(connection_); |
| 364 EXPECT_QUIC_BUG( | 384 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 365 QuicServerSessionBasePeer::GetOrCreateDynamicStream(session_.get(), 5), | 385 EXPECT_EQ(nullptr, QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 366 "ShouldCreateIncomingDynamicStream called when disconnected"); | 386 session_.get(), GetNthClientInitiatedId(0))); |
| 387 } else { |
| 388 EXPECT_QUIC_BUG( |
| 389 QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 390 session_.get(), GetNthClientInitiatedId(0)), |
| 391 "ShouldCreateIncomingDynamicStream called when disconnected"); |
| 392 } |
| 367 } | 393 } |
| 368 | 394 |
| 369 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 395 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
| 370 public: | 396 public: |
| 371 explicit MockQuicCryptoServerStream( | 397 explicit MockQuicCryptoServerStream( |
| 372 const QuicCryptoServerConfig* crypto_config, | 398 const QuicCryptoServerConfig* crypto_config, |
| 373 QuicCompressedCertsCache* compressed_certs_cache, | 399 QuicCompressedCertsCache* compressed_certs_cache, |
| 374 QuicServerSessionBase* session, | 400 QuicServerSessionBase* session, |
| 375 QuicCryptoServerStream::Helper* helper) | 401 QuicCryptoServerStream::Helper* helper) |
| 376 : QuicCryptoServerStream( | 402 : QuicCryptoServerStream( |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 658 |
| 633 // Allow the async ProofSource::GetProof call to complete. Verify (under | 659 // Allow the async ProofSource::GetProof call to complete. Verify (under |
| 634 // asan) that this does not result in accesses to any freed memory from the | 660 // asan) that this does not result in accesses to any freed memory from the |
| 635 // session or its subobjects. | 661 // session or its subobjects. |
| 636 GetFakeProofSource()->InvokePendingCallback(0); | 662 GetFakeProofSource()->InvokePendingCallback(0); |
| 637 } | 663 } |
| 638 | 664 |
| 639 } // namespace | 665 } // namespace |
| 640 } // namespace test | 666 } // namespace test |
| 641 } // namespace net | 667 } // namespace net |
| OLD | NEW |