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/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
10 #include "net/quic/core/quic_flags.h" | |
11 #include "net/quic/core/spdy_utils.h" | 10 #include "net/quic/core/spdy_utils.h" |
| 11 #include "net/quic/platform/api/quic_flags.h" |
12 #include "net/quic/platform/api/quic_ptr_util.h" | 12 #include "net/quic/platform/api/quic_ptr_util.h" |
13 #include "net/quic/platform/api/quic_socket_address.h" | 13 #include "net/quic/platform/api/quic_socket_address.h" |
14 #include "net/quic/platform/api/quic_str_cat.h" | 14 #include "net/quic/platform/api/quic_str_cat.h" |
15 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
16 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" | 16 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" |
17 #include "net/quic/test_tools/quic_config_peer.h" | 17 #include "net/quic/test_tools/quic_config_peer.h" |
18 #include "net/quic/test_tools/quic_connection_peer.h" | 18 #include "net/quic/test_tools/quic_connection_peer.h" |
19 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 19 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
20 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 20 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
21 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 push_promise_[":scheme"] = "https"; | 95 push_promise_[":scheme"] = "https"; |
96 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); | 96 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
97 } | 97 } |
98 | 98 |
99 void CompleteCryptoHandshake() { | 99 void CompleteCryptoHandshake() { |
100 CompleteCryptoHandshake(kDefaultMaxStreamsPerConnection); | 100 CompleteCryptoHandshake(kDefaultMaxStreamsPerConnection); |
101 } | 101 } |
102 | 102 |
103 void CompleteCryptoHandshake(uint32_t server_max_incoming_streams) { | 103 void CompleteCryptoHandshake(uint32_t server_max_incoming_streams) { |
104 session_->CryptoConnect(); | 104 session_->CryptoConnect(); |
105 QuicCryptoClientStream* stream = | 105 QuicCryptoClientStream* stream = static_cast<QuicCryptoClientStream*>( |
106 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); | 106 session_->GetMutableCryptoStream()); |
107 crypto_test_utils::FakeServerOptions options; | 107 crypto_test_utils::FakeServerOptions options; |
108 QuicConfig config = DefaultQuicConfig(); | 108 QuicConfig config = DefaultQuicConfig(); |
109 config.SetMaxIncomingDynamicStreamsToSend(server_max_incoming_streams); | 109 config.SetMaxIncomingDynamicStreamsToSend(server_max_incoming_streams); |
110 crypto_test_utils::HandshakeWithFakeServer( | 110 crypto_test_utils::HandshakeWithFakeServer( |
111 &config, &helper_, &alarm_factory_, connection_, stream, options); | 111 &config, &helper_, &alarm_factory_, connection_, stream, options); |
112 } | 112 } |
113 | 113 |
114 QuicCryptoClientConfig crypto_config_; | 114 QuicCryptoClientConfig crypto_config_; |
115 MockQuicConnectionHelper helper_; | 115 MockQuicConnectionHelper helper_; |
116 MockAlarmFactory alarm_factory_; | 116 MockAlarmFactory alarm_factory_; |
(...skipping 29 matching lines...) Expand all Loading... |
146 session_->CreateOutgoingDynamicStream(kDefaultPriority); | 146 session_->CreateOutgoingDynamicStream(kDefaultPriority); |
147 ASSERT_TRUE(stream != nullptr); | 147 ASSERT_TRUE(stream != nullptr); |
148 EXPECT_NE(kCryptoStreamId, stream->id()); | 148 EXPECT_NE(kCryptoStreamId, stream->id()); |
149 | 149 |
150 // Process an "inchoate" REJ from the server which will cause | 150 // Process an "inchoate" REJ from the server which will cause |
151 // an inchoate CHLO to be sent and will leave the encryption level | 151 // an inchoate CHLO to be sent and will leave the encryption level |
152 // at NONE. | 152 // at NONE. |
153 CryptoHandshakeMessage rej; | 153 CryptoHandshakeMessage rej; |
154 crypto_test_utils::FillInDummyReject(&rej, /* stateless */ false); | 154 crypto_test_utils::FillInDummyReject(&rej, /* stateless */ false); |
155 EXPECT_TRUE(session_->IsEncryptionEstablished()); | 155 EXPECT_TRUE(session_->IsEncryptionEstablished()); |
156 session_->GetCryptoStream()->OnHandshakeMessage(rej); | 156 session_->GetMutableCryptoStream()->OnHandshakeMessage(rej); |
157 EXPECT_FALSE(session_->IsEncryptionEstablished()); | 157 EXPECT_FALSE(session_->IsEncryptionEstablished()); |
158 EXPECT_EQ(ENCRYPTION_NONE, | 158 EXPECT_EQ(ENCRYPTION_NONE, |
159 QuicPacketCreatorPeer::GetEncryptionLevel( | 159 QuicPacketCreatorPeer::GetEncryptionLevel( |
160 QuicConnectionPeer::GetPacketCreator(connection_))); | 160 QuicConnectionPeer::GetPacketCreator(connection_))); |
161 // Verify that no new streams may be created. | 161 // Verify that no new streams may be created. |
162 EXPECT_TRUE(session_->CreateOutgoingDynamicStream(kDefaultPriority) == | 162 EXPECT_TRUE(session_->CreateOutgoingDynamicStream(kDefaultPriority) == |
163 nullptr); | 163 nullptr); |
164 // Verify that no data may be send on existing streams. | 164 // Verify that no data may be send on existing streams. |
165 char data[] = "hello world"; | 165 char data[] = "hello world"; |
166 struct iovec iov = {data, arraysize(data)}; | 166 struct iovec iov = {data, arraysize(data)}; |
167 QuicIOVector iovector(&iov, 1, iov.iov_len); | 167 QuicIOVector iovector(&iov, 1, iov.iov_len); |
168 QuicConsumedData consumed = | 168 QuicConsumedData consumed = |
169 session_->WritevData(stream, stream->id(), iovector, 0, false, nullptr); | 169 session_->WritevData(stream, stream->id(), iovector, 0, NO_FIN, nullptr); |
170 EXPECT_FALSE(consumed.fin_consumed); | 170 EXPECT_FALSE(consumed.fin_consumed); |
171 EXPECT_EQ(0u, consumed.bytes_consumed); | 171 EXPECT_EQ(0u, consumed.bytes_consumed); |
172 } | 172 } |
173 | 173 |
174 TEST_P(QuicClientSessionTest, MaxNumStreamsWithNoFinOrRst) { | 174 TEST_P(QuicClientSessionTest, MaxNumStreamsWithNoFinOrRst) { |
175 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); | 175 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); |
176 | 176 |
177 if (GetParam() <= QUIC_VERSION_34) { | 177 const uint32_t kServerMaxIncomingStreams = 1; |
178 session_->config()->SetMaxStreamsPerConnection(1, 1); | 178 CompleteCryptoHandshake(kServerMaxIncomingStreams); |
179 | |
180 // Initialize crypto before the client session will create a stream. | |
181 CompleteCryptoHandshake(); | |
182 } else { | |
183 const uint32_t kServerMaxIncomingStreams = 1; | |
184 CompleteCryptoHandshake(kServerMaxIncomingStreams); | |
185 } | |
186 | 179 |
187 QuicSpdyClientStream* stream = | 180 QuicSpdyClientStream* stream = |
188 session_->CreateOutgoingDynamicStream(kDefaultPriority); | 181 session_->CreateOutgoingDynamicStream(kDefaultPriority); |
189 ASSERT_TRUE(stream); | 182 ASSERT_TRUE(stream); |
190 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); | 183 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
191 | 184 |
192 // Close the stream, but without having received a FIN or a RST_STREAM | 185 // Close the stream, but without having received a FIN or a RST_STREAM |
193 // and check that a new one can not be created. | 186 // and check that a new one can not be created. |
194 session_->CloseStream(stream->id()); | 187 session_->CloseStream(stream->id()); |
195 EXPECT_EQ(1u, session_->GetNumOpenOutgoingStreams()); | 188 EXPECT_EQ(1u, session_->GetNumOpenOutgoingStreams()); |
196 | 189 |
197 stream = session_->CreateOutgoingDynamicStream(kDefaultPriority); | 190 stream = session_->CreateOutgoingDynamicStream(kDefaultPriority); |
198 EXPECT_FALSE(stream); | 191 EXPECT_FALSE(stream); |
199 } | 192 } |
200 | 193 |
201 TEST_P(QuicClientSessionTest, MaxNumStreamsWithRst) { | 194 TEST_P(QuicClientSessionTest, MaxNumStreamsWithRst) { |
202 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); | 195 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); |
203 | 196 |
204 if (GetParam() <= QUIC_VERSION_34) { | 197 const uint32_t kServerMaxIncomingStreams = 1; |
205 session_->config()->SetMaxStreamsPerConnection(1, 1); | 198 CompleteCryptoHandshake(kServerMaxIncomingStreams); |
206 | |
207 // Initialize crypto before the client session will create a stream. | |
208 CompleteCryptoHandshake(); | |
209 } else { | |
210 const uint32_t kServerMaxIncomingStreams = 1; | |
211 CompleteCryptoHandshake(kServerMaxIncomingStreams); | |
212 } | |
213 | 199 |
214 QuicSpdyClientStream* stream = | 200 QuicSpdyClientStream* stream = |
215 session_->CreateOutgoingDynamicStream(kDefaultPriority); | 201 session_->CreateOutgoingDynamicStream(kDefaultPriority); |
216 ASSERT_TRUE(stream); | 202 ASSERT_TRUE(stream); |
217 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); | 203 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
218 | 204 |
219 // Close the stream and receive an RST frame to remove the unfinished stream | 205 // Close the stream and receive an RST frame to remove the unfinished stream |
220 session_->CloseStream(stream->id()); | 206 session_->CloseStream(stream->id()); |
221 session_->OnRstStream( | 207 session_->OnRstStream( |
222 QuicRstStreamFrame(stream->id(), QUIC_RST_ACKNOWLEDGEMENT, 0)); | 208 QuicRstStreamFrame(stream->id(), QUIC_RST_ACKNOWLEDGEMENT, 0)); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 QuicClientPromisedInfo* promised = | 484 QuicClientPromisedInfo* promised = |
499 session_->GetPromisedById(promised_stream_id_); | 485 session_->GetPromisedById(promised_stream_id_); |
500 EXPECT_NE(promised, nullptr); | 486 EXPECT_NE(promised, nullptr); |
501 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 487 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
502 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 488 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
503 } | 489 } |
504 | 490 |
505 } // namespace | 491 } // namespace |
506 } // namespace test | 492 } // namespace test |
507 } // namespace net | 493 } // namespace net |
OLD | NEW |