1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/quic_config.h"
7 #include "net/quic/congestion_control/quic_congestion_manager.h"
8 #include "net/quic/crypto/crypto_handshake.h"
9 #include "net/quic/crypto/crypto_protocol.h"
10 #include "net/quic/quic_protocol.h"
11 #include "net/quic/quic_time.h"
12 #include "net/quic/test_tools/quic_test_utils.h"
13 #include "testing/gtest/include/gtest/gtest.h"
21 class QuicConfigTest
: public ::testing::Test
{
24 config_
.SetDefaults();
25 config_
.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs
, 0);
31 TEST_F(QuicConfigTest
, ToHandshakeMessage
) {
32 config_
.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5),
33 QuicTime::Delta::FromSeconds(2));
34 config_
.set_max_streams_per_connection(4, 2);
35 CryptoHandshakeMessage msg
;
36 config_
.ToHandshakeMessage(&msg
);
39 QuicErrorCode error
= msg
.GetUint32(kICSL
, &value
);
40 EXPECT_EQ(QUIC_NO_ERROR
, error
);
43 error
= msg
.GetUint32(kMSPC
, &value
);
44 EXPECT_EQ(QUIC_NO_ERROR
, error
);
49 error
= msg
.GetTaglist(kCGST
, &out
, &out_len
);
50 EXPECT_EQ(1u, out_len
);
51 EXPECT_EQ(kQBIC
, *out
);
54 TEST_F(QuicConfigTest
, ToHandshakeMessageWithPacing
) {
55 ValueRestore
<bool> old_flag(&FLAGS_enable_quic_pacing
, true);
57 config_
.SetDefaults();
58 CryptoHandshakeMessage msg
;
59 config_
.ToHandshakeMessage(&msg
);
63 EXPECT_EQ(QUIC_NO_ERROR
, msg
.GetTaglist(kCGST
, &out
, &out_len
));
64 EXPECT_EQ(2u, out_len
);
65 EXPECT_EQ(kPACE
, out
[0]);
66 EXPECT_EQ(kQBIC
, out
[1]);
69 TEST_F(QuicConfigTest
, ProcessClientHello
) {
70 QuicConfig client_config
;
72 cgst
.push_back(kINAR
);
73 cgst
.push_back(kQBIC
);
74 client_config
.set_congestion_control(cgst
, kQBIC
);
75 client_config
.set_idle_connection_state_lifetime(
76 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs
),
77 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
));
78 client_config
.set_max_streams_per_connection(
79 2 * kDefaultMaxStreamsPerConnection
, kDefaultMaxStreamsPerConnection
);
80 client_config
.set_initial_round_trip_time_us(
81 10 * base::Time::kMicrosecondsPerMillisecond
,
82 10 * base::Time::kMicrosecondsPerMillisecond
);
84 CryptoHandshakeMessage msg
;
85 client_config
.ToHandshakeMessage(&msg
);
87 const QuicErrorCode error
= config_
.ProcessClientHello(msg
, &error_details
);
88 EXPECT_EQ(QUIC_NO_ERROR
, error
);
89 EXPECT_TRUE(config_
.negotiated());
90 EXPECT_EQ(kQBIC
, config_
.congestion_control());
91 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
),
92 config_
.idle_connection_state_lifetime());
93 EXPECT_EQ(kDefaultMaxStreamsPerConnection
,
94 config_
.max_streams_per_connection());
95 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_
.keepalive_timeout());
96 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond
,
97 config_
.initial_round_trip_time_us());
100 TEST_F(QuicConfigTest
, ProcessServerHello
) {
101 QuicConfig server_config
;
103 cgst
.push_back(kQBIC
);
104 server_config
.set_congestion_control(cgst
, kQBIC
);
105 server_config
.set_idle_connection_state_lifetime(
106 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
/ 2),
107 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
/ 2));
108 server_config
.set_max_streams_per_connection(
109 kDefaultMaxStreamsPerConnection
/ 2,
110 kDefaultMaxStreamsPerConnection
/ 2);
111 server_config
.set_server_initial_congestion_window(kDefaultInitialWindow
/ 2,
112 kDefaultInitialWindow
/ 2);
113 server_config
.set_initial_round_trip_time_us(
114 10 * base::Time::kMicrosecondsPerMillisecond
,
115 10 * base::Time::kMicrosecondsPerMillisecond
);
117 CryptoHandshakeMessage msg
;
118 server_config
.ToHandshakeMessage(&msg
);
119 string error_details
;
120 const QuicErrorCode error
= config_
.ProcessServerHello(msg
, &error_details
);
121 EXPECT_EQ(QUIC_NO_ERROR
, error
);
122 EXPECT_TRUE(config_
.negotiated());
123 EXPECT_EQ(kQBIC
, config_
.congestion_control());
124 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
/ 2),
125 config_
.idle_connection_state_lifetime());
126 EXPECT_EQ(kDefaultMaxStreamsPerConnection
/ 2,
127 config_
.max_streams_per_connection());
128 EXPECT_EQ(kDefaultInitialWindow
/ 2,
129 config_
.server_initial_congestion_window());
130 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_
.keepalive_timeout());
131 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond
,
132 config_
.initial_round_trip_time_us());
135 TEST_F(QuicConfigTest
, MissingValueInCHLO
) {
136 CryptoHandshakeMessage msg
;
137 msg
.SetValue(kICSL
, 1);
138 msg
.SetVector(kCGST
, QuicTagVector(1, kQBIC
));
139 // Missing kMSPC. KATO is optional.
140 string error_details
;
141 const QuicErrorCode error
= config_
.ProcessClientHello(msg
, &error_details
);
142 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND
, error
);
145 TEST_F(QuicConfigTest
, MissingValueInSHLO
) {
146 CryptoHandshakeMessage msg
;
147 msg
.SetValue(kICSL
, 1);
148 msg
.SetValue(kMSPC
, 3);
149 // Missing CGST. KATO is optional.
150 string error_details
;
151 const QuicErrorCode error
= config_
.ProcessServerHello(msg
, &error_details
);
152 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND
, error
);
155 TEST_F(QuicConfigTest
, OutOfBoundSHLO
) {
156 QuicConfig server_config
;
157 server_config
.set_idle_connection_state_lifetime(
158 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs
),
159 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs
));
161 CryptoHandshakeMessage msg
;
162 server_config
.ToHandshakeMessage(&msg
);
163 string error_details
;
164 const QuicErrorCode error
= config_
.ProcessServerHello(msg
, &error_details
);
165 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE
, error
);
168 TEST_F(QuicConfigTest
, MultipleNegotiatedValuesInVectorTag
) {
169 QuicConfig server_config
;
171 cgst
.push_back(kQBIC
);
172 cgst
.push_back(kINAR
);
173 server_config
.set_congestion_control(cgst
, kQBIC
);
175 CryptoHandshakeMessage msg
;
176 server_config
.ToHandshakeMessage(&msg
);
177 string error_details
;
178 const QuicErrorCode error
= config_
.ProcessServerHello(msg
, &error_details
);
179 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE
, error
);
182 TEST_F(QuicConfigTest
, NoOverLapInCGST
) {
183 QuicConfig server_config
;
184 server_config
.SetDefaults();
186 cgst
.push_back(kINAR
);
187 server_config
.set_congestion_control(cgst
, kINAR
);
189 CryptoHandshakeMessage msg
;
190 string error_details
;
191 server_config
.ToHandshakeMessage(&msg
);
192 const QuicErrorCode error
= config_
.ProcessClientHello(msg
, &error_details
);
193 LOG(INFO
) << QuicUtils::ErrorToString(error
);
194 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP
, error
);