OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "net/quic/quic_config.h" |
| 6 |
| 7 #include "net/quic/crypto/crypto_handshake.h" |
| 8 #include "net/quic/crypto/crypto_protocol.h" |
| 9 #include "net/quic/quic_protocol.h" |
| 10 #include "net/quic/quic_time.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 using std::string; |
| 14 |
| 15 namespace net { |
| 16 namespace test { |
| 17 namespace { |
| 18 |
| 19 class QuicConfigTest : public ::testing::Test { |
| 20 protected: |
| 21 QuicConfigTest() { |
| 22 config_.SetDefaults(); |
| 23 } |
| 24 |
| 25 QuicConfig config_; |
| 26 }; |
| 27 |
| 28 TEST_F(QuicConfigTest, ToHandshakeMessage) { |
| 29 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5), |
| 30 QuicTime::Delta::FromSeconds(2)); |
| 31 config_.set_max_streams_per_connection(4, 2); |
| 32 CryptoHandshakeMessage msg; |
| 33 config_.ToHandshakeMessage(&msg); |
| 34 |
| 35 uint32 value; |
| 36 QuicErrorCode error = msg.GetUint32(kICSL, &value); |
| 37 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 38 EXPECT_EQ(5u, value); |
| 39 |
| 40 error = msg.GetUint32(kMSPC, &value); |
| 41 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 42 EXPECT_EQ(4u, value); |
| 43 |
| 44 const QuicTag* out; |
| 45 size_t out_len; |
| 46 error = msg.GetTaglist(kCGST, &out, &out_len); |
| 47 EXPECT_EQ(1u, out_len); |
| 48 EXPECT_EQ(kQBIC, *out); |
| 49 } |
| 50 |
| 51 TEST_F(QuicConfigTest, ProcessClientHello) { |
| 52 QuicConfig client_config; |
| 53 QuicTagVector cgst; |
| 54 cgst.push_back(kINAR); |
| 55 cgst.push_back(kQBIC); |
| 56 client_config.set_congestion_control(cgst, kQBIC); |
| 57 client_config.set_idle_connection_state_lifetime( |
| 58 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), |
| 59 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs)); |
| 60 client_config.set_max_streams_per_connection( |
| 61 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); |
| 62 |
| 63 CryptoHandshakeMessage msg; |
| 64 client_config.ToHandshakeMessage(&msg); |
| 65 string error_details; |
| 66 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 67 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 68 EXPECT_TRUE(config_.negotiated()); |
| 69 EXPECT_EQ(kQBIC, config_.congestion_control()); |
| 70 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs), |
| 71 config_.idle_connection_state_lifetime()); |
| 72 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
| 73 config_.max_streams_per_connection()); |
| 74 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
| 75 } |
| 76 |
| 77 TEST_F(QuicConfigTest, ProcessServerHello) { |
| 78 QuicConfig server_config; |
| 79 QuicTagVector cgst; |
| 80 cgst.push_back(kQBIC); |
| 81 server_config.set_congestion_control(cgst, kQBIC); |
| 82 server_config.set_idle_connection_state_lifetime( |
| 83 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
| 84 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2)); |
| 85 server_config.set_max_streams_per_connection( |
| 86 kDefaultMaxStreamsPerConnection / 2, |
| 87 kDefaultMaxStreamsPerConnection / 2); |
| 88 |
| 89 CryptoHandshakeMessage msg; |
| 90 server_config.ToHandshakeMessage(&msg); |
| 91 string error_details; |
| 92 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 93 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 94 EXPECT_TRUE(config_.negotiated()); |
| 95 EXPECT_EQ(kQBIC, config_.congestion_control()); |
| 96 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
| 97 config_.idle_connection_state_lifetime()); |
| 98 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, |
| 99 config_.max_streams_per_connection()); |
| 100 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
| 101 } |
| 102 |
| 103 TEST_F(QuicConfigTest, MissingValueInCHLO) { |
| 104 CryptoHandshakeMessage msg; |
| 105 msg.SetValue(kICSL, 1); |
| 106 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
| 107 // Missing kMSPC. KATO is optional. |
| 108 string error_details; |
| 109 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 110 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); |
| 111 } |
| 112 |
| 113 TEST_F(QuicConfigTest, MissingValueInSHLO) { |
| 114 CryptoHandshakeMessage msg; |
| 115 msg.SetValue(kICSL, 1); |
| 116 msg.SetValue(kMSPC, 3); |
| 117 // Missing CGST. KATO is optional. |
| 118 string error_details; |
| 119 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 120 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); |
| 121 } |
| 122 |
| 123 TEST_F(QuicConfigTest, OutOfBoundSHLO) { |
| 124 QuicConfig server_config; |
| 125 server_config.set_idle_connection_state_lifetime( |
| 126 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), |
| 127 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs)); |
| 128 |
| 129 CryptoHandshakeMessage msg; |
| 130 server_config.ToHandshakeMessage(&msg); |
| 131 string error_details; |
| 132 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 133 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error); |
| 134 } |
| 135 |
| 136 TEST_F(QuicConfigTest, MultipleNegotiatedValuesInVectorTag) { |
| 137 QuicConfig server_config; |
| 138 QuicTagVector cgst; |
| 139 cgst.push_back(kQBIC); |
| 140 cgst.push_back(kINAR); |
| 141 server_config.set_congestion_control(cgst, kQBIC); |
| 142 |
| 143 CryptoHandshakeMessage msg; |
| 144 server_config.ToHandshakeMessage(&msg); |
| 145 string error_details; |
| 146 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 147 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error); |
| 148 } |
| 149 |
| 150 TEST_F(QuicConfigTest, NoOverLapInCGST) { |
| 151 QuicConfig server_config; |
| 152 server_config.SetDefaults(); |
| 153 QuicTagVector cgst; |
| 154 cgst.push_back(kINAR); |
| 155 server_config.set_congestion_control(cgst, kINAR); |
| 156 |
| 157 CryptoHandshakeMessage msg; |
| 158 string error_details; |
| 159 server_config.ToHandshakeMessage(&msg); |
| 160 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 161 LOG(INFO) << QuicUtils::ErrorToString(error); |
| 162 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); |
| 163 } |
| 164 |
| 165 } // namespace |
| 166 } // namespace test |
| 167 } // namespace net |
OLD | NEW |