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/crypto/quic_crypto_server_config.h" | 5 #include "net/quic/crypto/quic_crypto_server_config.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // // status. | 96 // // status. |
97 // CheckConfigs( | 97 // CheckConfigs( |
98 // "id1", false, | 98 // "id1", false, |
99 // "id2", true, | 99 // "id2", true, |
100 // "id3", false, | 100 // "id3", false, |
101 // nullptr); | 101 // nullptr); |
102 void CheckConfigs(const char* server_config_id1, ...) { | 102 void CheckConfigs(const char* server_config_id1, ...) { |
103 va_list ap; | 103 va_list ap; |
104 va_start(ap, server_config_id1); | 104 va_start(ap, server_config_id1); |
105 | 105 |
106 vector<pair<ServerConfigID, bool> > expected; | 106 vector<pair<ServerConfigID, bool>> expected; |
107 bool first = true; | 107 bool first = true; |
108 for (;;) { | 108 for (;;) { |
109 const char* server_config_id; | 109 const char* server_config_id; |
110 if (first) { | 110 if (first) { |
111 server_config_id = server_config_id1; | 111 server_config_id = server_config_id1; |
112 first = false; | 112 first = false; |
113 } else { | 113 } else { |
114 server_config_id = va_arg(ap, const char*); | 114 server_config_id = va_arg(ap, const char*); |
115 } | 115 } |
116 | 116 |
117 if (!server_config_id) { | 117 if (!server_config_id) { |
118 break; | 118 break; |
119 } | 119 } |
120 | 120 |
121 // varargs will promote the value to an int so we have to read that from | 121 // varargs will promote the value to an int so we have to read that from |
122 // the stack and cast down. | 122 // the stack and cast down. |
123 const bool is_primary = static_cast<bool>(va_arg(ap, int)); | 123 const bool is_primary = static_cast<bool>(va_arg(ap, int)); |
124 expected.push_back(std::make_pair(server_config_id, is_primary)); | 124 expected.push_back(std::make_pair(server_config_id, is_primary)); |
125 } | 125 } |
126 | 126 |
127 va_end(ap); | 127 va_end(ap); |
128 | 128 |
129 base::AutoLock locked(server_config_->configs_lock_); | 129 base::AutoLock locked(server_config_->configs_lock_); |
130 | 130 |
131 ASSERT_EQ(expected.size(), server_config_->configs_.size()) | 131 ASSERT_EQ(expected.size(), server_config_->configs_.size()) |
132 << ConfigsDebug(); | 132 << ConfigsDebug(); |
133 | 133 |
134 for (QuicCryptoServerConfig::ConfigMap::const_iterator | 134 for (const pair<const ServerConfigID, |
135 i = server_config_->configs_.begin(); | 135 scoped_refptr<QuicCryptoServerConfig::Config>>& i : |
136 i != server_config_->configs_.end(); ++i) { | 136 server_config_->configs_) { |
137 bool found = false; | 137 bool found = false; |
138 for (vector<pair<ServerConfigID, bool> >::iterator j = expected.begin(); | 138 for (pair<ServerConfigID, bool>& j : expected) { |
139 j != expected.end(); ++j) { | 139 if (i.first == j.first && i.second->is_primary == j.second) { |
140 if (i->first == j->first && i->second->is_primary == j->second) { | |
141 found = true; | 140 found = true; |
142 j->first.clear(); | 141 j.first.clear(); |
143 break; | 142 break; |
144 } | 143 } |
145 } | 144 } |
146 | 145 |
147 ASSERT_TRUE(found) << "Failed to find match for " << i->first | 146 ASSERT_TRUE(found) << "Failed to find match for " << i.first |
148 << " in configs:\n" << ConfigsDebug(); | 147 << " in configs:\n" << ConfigsDebug(); |
149 } | 148 } |
150 } | 149 } |
151 | 150 |
152 // ConfigsDebug returns a string that contains debugging information about | 151 // ConfigsDebug returns a string that contains debugging information about |
153 // the set of Configs loaded in |server_config_| and their status. | 152 // the set of Configs loaded in |server_config_| and their status. |
154 // ConfigsDebug() should be called after acquiring | 153 // ConfigsDebug() should be called after acquiring |
155 // server_config_->configs_lock_. | 154 // server_config_->configs_lock_. |
156 string ConfigsDebug() { | 155 string ConfigsDebug() { |
157 if (server_config_->configs_.empty()) { | 156 if (server_config_->configs_.empty()) { |
158 return "No Configs in QuicCryptoServerConfig"; | 157 return "No Configs in QuicCryptoServerConfig"; |
159 } | 158 } |
160 | 159 |
161 string s; | 160 string s; |
162 | 161 |
163 for (QuicCryptoServerConfig::ConfigMap::const_iterator | 162 for (const auto& i : server_config_->configs_) { |
164 i = server_config_->configs_.begin(); | 163 const scoped_refptr<QuicCryptoServerConfig::Config> config = i.second; |
165 i != server_config_->configs_.end(); ++i) { | |
166 const scoped_refptr<QuicCryptoServerConfig::Config> config = i->second; | |
167 if (config->is_primary) { | 164 if (config->is_primary) { |
168 s += "(primary) "; | 165 s += "(primary) "; |
169 } else { | 166 } else { |
170 s += " "; | 167 s += " "; |
171 } | 168 } |
172 s += config->id; | 169 s += config->id; |
173 s += "\n"; | 170 s += "\n"; |
174 } | 171 } |
175 | 172 |
176 return s; | 173 return s; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { | 229 TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { |
233 QuicRandom* rand = QuicRandom::GetInstance(); | 230 QuicRandom* rand = QuicRandom::GetInstance(); |
234 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); | 231 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
235 MockClock clock; | 232 MockClock clock; |
236 | 233 |
237 TestStrikeRegisterClient* strike_register = | 234 TestStrikeRegisterClient* strike_register = |
238 new TestStrikeRegisterClient(&server); | 235 new TestStrikeRegisterClient(&server); |
239 server.SetStrikeRegisterClient(strike_register); | 236 server.SetStrikeRegisterClient(strike_register); |
240 | 237 |
241 QuicCryptoServerConfig::ConfigOptions options; | 238 QuicCryptoServerConfig::ConfigOptions options; |
242 scoped_ptr<CryptoHandshakeMessage>( | 239 scoped_ptr<CryptoHandshakeMessage> message( |
243 server.AddDefaultConfig(rand, &clock, options)); | 240 server.AddDefaultConfig(rand, &clock, options)); |
244 EXPECT_TRUE(strike_register->is_known_orbit_called()); | 241 EXPECT_TRUE(strike_register->is_known_orbit_called()); |
245 } | 242 } |
246 | 243 |
247 class SourceAddressTokenTest : public ::testing::Test { | 244 class SourceAddressTokenTest : public ::testing::Test { |
248 public: | 245 public: |
249 SourceAddressTokenTest() | 246 SourceAddressTokenTest() |
250 : ip4_(Loopback4()), | 247 : ip4_(Loopback4()), |
251 ip4_dual_(ConvertIPv4NumberToIPv6Number(ip4_)), | 248 ip4_dual_(ConvertIPv4NumberToIPv6Number(ip4_)), |
252 ip6_(Loopback6()), | 249 ip6_(Loopback6()), |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 nullptr); | 749 nullptr); |
753 test_peer_.CheckConfigs( | 750 test_peer_.CheckConfigs( |
754 "a", false, | 751 "a", false, |
755 "b", true, | 752 "b", true, |
756 "c", false, | 753 "c", false, |
757 nullptr); | 754 nullptr); |
758 } | 755 } |
759 | 756 |
760 } // namespace test | 757 } // namespace test |
761 } // namespace net | 758 } // namespace net |
OLD | NEW |