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/tools/quic/quic_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 11 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
12 #include "net/quic/core/crypto/quic_random.h" | 12 #include "net/quic/core/crypto/quic_random.h" |
13 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
14 #include "net/quic/core/quic_connection.h" | 14 #include "net/quic/core/quic_connection.h" |
15 #include "net/quic/core/quic_crypto_server_stream.h" | 15 #include "net/quic/core/quic_crypto_server_stream.h" |
16 #include "net/quic/core/quic_utils.h" | 16 #include "net/quic/core/quic_utils.h" |
17 #include "net/quic/platform/api/quic_socket_address.h" | 17 #include "net/quic/platform/api/quic_socket_address.h" |
| 18 #include "net/quic/platform/api/quic_string_piece.h" |
18 #include "net/quic/platform/api/quic_text_utils.h" | 19 #include "net/quic/platform/api/quic_text_utils.h" |
19 #include "net/quic/test_tools/crypto_test_utils.h" | 20 #include "net/quic/test_tools/crypto_test_utils.h" |
20 #include "net/quic/test_tools/quic_config_peer.h" | 21 #include "net/quic/test_tools/quic_config_peer.h" |
21 #include "net/quic/test_tools/quic_connection_peer.h" | 22 #include "net/quic/test_tools/quic_connection_peer.h" |
22 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 23 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
23 #include "net/quic/test_tools/quic_session_peer.h" | 24 #include "net/quic/test_tools/quic_session_peer.h" |
24 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 25 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
25 #include "net/quic/test_tools/quic_spdy_stream_peer.h" | 26 #include "net/quic/test_tools/quic_spdy_stream_peer.h" |
26 #include "net/quic/test_tools/quic_stream_peer.h" | 27 #include "net/quic/test_tools/quic_stream_peer.h" |
27 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" | 28 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 QuicConnectionVisitorInterface* visitor_; | 222 QuicConnectionVisitorInterface* visitor_; |
222 }; | 223 }; |
223 | 224 |
224 INSTANTIATE_TEST_CASE_P(Tests, | 225 INSTANTIATE_TEST_CASE_P(Tests, |
225 QuicSimpleServerSessionTest, | 226 QuicSimpleServerSessionTest, |
226 ::testing::ValuesIn(AllSupportedVersions())); | 227 ::testing::ValuesIn(AllSupportedVersions())); |
227 | 228 |
228 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { | 229 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { |
229 // Open a stream, then reset it. | 230 // Open a stream, then reset it. |
230 // Send two bytes of payload to open it. | 231 // Send two bytes of payload to open it. |
231 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 232 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); |
232 session_->OnStreamFrame(data1); | 233 session_->OnStreamFrame(data1); |
233 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 234 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
234 | 235 |
235 // Receive a reset (and send a RST in response). | 236 // Receive a reset (and send a RST in response). |
236 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 237 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, |
237 0); | 238 0); |
238 EXPECT_CALL(*connection_, | 239 EXPECT_CALL(*connection_, |
239 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 240 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
240 visitor_->OnRstStream(rst1); | 241 visitor_->OnRstStream(rst1); |
241 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 242 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
242 | 243 |
243 // Send the same two bytes of payload in a new packet. | 244 // Send the same two bytes of payload in a new packet. |
244 visitor_->OnStreamFrame(data1); | 245 visitor_->OnStreamFrame(data1); |
245 | 246 |
246 // The stream should not be re-opened. | 247 // The stream should not be re-opened. |
247 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 248 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
248 EXPECT_TRUE(connection_->connected()); | 249 EXPECT_TRUE(connection_->connected()); |
249 } | 250 } |
250 | 251 |
251 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { | 252 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { |
252 // Send a reset (and expect the peer to send a RST in response). | 253 // Send a reset (and expect the peer to send a RST in response). |
253 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 254 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, |
254 0); | 255 0); |
255 EXPECT_CALL(*connection_, | 256 EXPECT_CALL(*connection_, |
256 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 257 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
257 visitor_->OnRstStream(rst1); | 258 visitor_->OnRstStream(rst1); |
258 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 259 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
259 | 260 |
260 // Send two bytes of payload. | 261 // Send two bytes of payload. |
261 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 262 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); |
262 visitor_->OnStreamFrame(data1); | 263 visitor_->OnStreamFrame(data1); |
263 | 264 |
264 // The stream should never be opened, now that the reset is received. | 265 // The stream should never be opened, now that the reset is received. |
265 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 266 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
266 EXPECT_TRUE(connection_->connected()); | 267 EXPECT_TRUE(connection_->connected()); |
267 } | 268 } |
268 | 269 |
269 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { | 270 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { |
270 // Send (empty) compressed headers followed by two bytes of data. | 271 // Send (empty) compressed headers followed by two bytes of data. |
271 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, | 272 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, |
272 StringPiece("\1\0\0\0\0\0\0\0HT")); | 273 QuicStringPiece("\1\0\0\0\0\0\0\0HT")); |
273 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, | 274 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, |
274 StringPiece("\2\0\0\0\0\0\0\0HT")); | 275 QuicStringPiece("\2\0\0\0\0\0\0\0HT")); |
275 visitor_->OnStreamFrame(frame1); | 276 visitor_->OnStreamFrame(frame1); |
276 visitor_->OnStreamFrame(frame2); | 277 visitor_->OnStreamFrame(frame2); |
277 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 278 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
278 | 279 |
279 // Send a reset (and expect the peer to send a RST in response). | 280 // Send a reset (and expect the peer to send a RST in response). |
280 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); | 281 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); |
281 EXPECT_CALL(*connection_, | 282 EXPECT_CALL(*connection_, |
282 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 283 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
283 visitor_->OnRstStream(rst); | 284 visitor_->OnRstStream(rst); |
284 | 285 |
285 // If we were tracking, we'd probably want to reject this because it's data | 286 // If we were tracking, we'd probably want to reject this because it's data |
286 // past the reset point of stream 3. As it's a closed stream we just drop the | 287 // past the reset point of stream 3. As it's a closed stream we just drop the |
287 // data on the floor, but accept the packet because it has data for stream 5. | 288 // data on the floor, but accept the packet because it has data for stream 5. |
288 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, StringPiece("TP")); | 289 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, QuicStringPiece("TP")); |
289 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, StringPiece("TP")); | 290 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, QuicStringPiece("TP")); |
290 visitor_->OnStreamFrame(frame3); | 291 visitor_->OnStreamFrame(frame3); |
291 visitor_->OnStreamFrame(frame4); | 292 visitor_->OnStreamFrame(frame4); |
292 // The stream should never be opened, now that the reset is received. | 293 // The stream should never be opened, now that the reset is received. |
293 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 294 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
294 EXPECT_TRUE(connection_->connected()); | 295 EXPECT_TRUE(connection_->connected()); |
295 } | 296 } |
296 | 297 |
297 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { | 298 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { |
298 // Tests that incoming stream creation fails when connection is not connected. | 299 // Tests that incoming stream creation fails when connection is not connected. |
299 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); | 300 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); | 344 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); |
344 } | 345 } |
345 | 346 |
346 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { | 347 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { |
347 // Tests that outgoing stream creation should not be affected by existing | 348 // Tests that outgoing stream creation should not be affected by existing |
348 // incoming stream and vice-versa. But when reaching the limit of max outgoing | 349 // incoming stream and vice-versa. But when reaching the limit of max outgoing |
349 // stream allowed, creation should fail. | 350 // stream allowed, creation should fail. |
350 | 351 |
351 // Receive some data to initiate a incoming stream which should not effect | 352 // Receive some data to initiate a incoming stream which should not effect |
352 // creating outgoing streams. | 353 // creating outgoing streams. |
353 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 354 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); |
354 session_->OnStreamFrame(data1); | 355 session_->OnStreamFrame(data1); |
355 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 356 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
356 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); | 357 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); |
357 | 358 |
358 // Assume encryption already established. | 359 // Assume encryption already established. |
359 MockQuicCryptoServerStream* crypto_stream = | 360 MockQuicCryptoServerStream* crypto_stream = |
360 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, | 361 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, |
361 session_.get(), &stream_helper_); | 362 session_.get(), &stream_helper_); |
362 crypto_stream->set_encryption_established(true); | 363 crypto_stream->set_encryption_established(true); |
363 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 364 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
364 | 365 |
365 // Create push streams till reaching the upper limit of allowed open streams. | 366 // Create push streams till reaching the upper limit of allowed open streams. |
366 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 367 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
367 QuicSpdyStream* created_stream = | 368 QuicSpdyStream* created_stream = |
368 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 369 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
369 session_.get(), kDefaultPriority); | 370 session_.get(), kDefaultPriority); |
370 EXPECT_EQ(2 * (i + 1), created_stream->id()); | 371 EXPECT_EQ(2 * (i + 1), created_stream->id()); |
371 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); | 372 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); |
372 } | 373 } |
373 | 374 |
374 // Continuing creating push stream would fail. | 375 // Continuing creating push stream would fail. |
375 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 376 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
376 session_.get(), kDefaultPriority)); | 377 session_.get(), kDefaultPriority)); |
377 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 378 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
378 | 379 |
379 // Create peer initiated stream should have no problem. | 380 // Create peer initiated stream should have no problem. |
380 QuicStreamFrame data2(kClientDataStreamId2, false, 0, StringPiece("HT")); | 381 QuicStreamFrame data2(kClientDataStreamId2, false, 0, QuicStringPiece("HT")); |
381 session_->OnStreamFrame(data2); | 382 session_->OnStreamFrame(data2); |
382 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 383 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
383 } | 384 } |
384 | 385 |
385 TEST_P(QuicSimpleServerSessionTest, OnStreamFrameWithEvenStreamId) { | 386 TEST_P(QuicSimpleServerSessionTest, OnStreamFrameWithEvenStreamId) { |
386 QuicStreamFrame frame(2, false, 0, StringPiece()); | 387 QuicStreamFrame frame(2, false, 0, QuicStringPiece()); |
387 EXPECT_CALL(*connection_, | 388 EXPECT_CALL(*connection_, |
388 CloseConnection(QUIC_INVALID_STREAM_ID, | 389 CloseConnection(QUIC_INVALID_STREAM_ID, |
389 "Client sent data on server push stream", _)); | 390 "Client sent data on server push stream", _)); |
390 session_->OnStreamFrame(frame); | 391 session_->OnStreamFrame(frame); |
391 } | 392 } |
392 | 393 |
393 TEST_P(QuicSimpleServerSessionTest, GetEvenIncomingError) { | 394 TEST_P(QuicSimpleServerSessionTest, GetEvenIncomingError) { |
394 // Tests that calling GetOrCreateDynamicStream() on an outgoing stream not | 395 // Tests that calling GetOrCreateDynamicStream() on an outgoing stream not |
395 // promised yet should result close connection. | 396 // promised yet should result close connection. |
396 EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, | 397 EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 614 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
614 | 615 |
615 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 616 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
616 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 617 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
617 visitor_->OnRstStream(rst); | 618 visitor_->OnRstStream(rst); |
618 } | 619 } |
619 | 620 |
620 } // namespace | 621 } // namespace |
621 } // namespace test | 622 } // namespace test |
622 } // namespace net | 623 } // namespace net |
OLD | NEW |