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 27 matching lines...) Expand all Loading... |
38 return scoped_refptr<QuicCryptoServerConfig::Config>( | 38 return scoped_refptr<QuicCryptoServerConfig::Config>( |
39 server_config_->primary_config_); | 39 server_config_->primary_config_); |
40 } else { | 40 } else { |
41 return server_config_->GetConfigWithScid(config_id); | 41 return server_config_->GetConfigWithScid(config_id); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) { | 45 bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) { |
46 scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id); | 46 scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id); |
47 return config->source_address_token_boxer == | 47 return config->source_address_token_boxer == |
48 &(server_config_->default_source_address_token_boxer_); | 48 &(server_config_->default_source_address_token_boxer_); |
49 } | 49 } |
50 | 50 |
51 string NewSourceAddressToken( | 51 string NewSourceAddressToken(string config_id, |
52 string config_id, | 52 IPEndPoint ip, |
53 IPEndPoint ip, | 53 QuicRandom* rand, |
54 QuicRandom* rand, | 54 QuicWallTime now) { |
55 QuicWallTime now) { | |
56 return server_config_->NewSourceAddressToken( | 55 return server_config_->NewSourceAddressToken( |
57 *GetConfig(config_id), ip, rand, now); | 56 *GetConfig(config_id), ip, rand, now); |
58 } | 57 } |
59 | 58 |
60 bool ValidateSourceAddressToken(string config_id, | 59 bool ValidateSourceAddressToken(string config_id, |
61 StringPiece srct, | 60 StringPiece srct, |
62 IPEndPoint ip, | 61 IPEndPoint ip, |
63 QuicWallTime now) { | 62 QuicWallTime now) { |
64 return server_config_->ValidateSourceAddressToken( | 63 return server_config_->ValidateSourceAddressToken( |
65 *GetConfig(config_id), srct, ip, now); | 64 *GetConfig(config_id), srct, ip, now); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 expected.push_back(make_pair(server_config_id, is_primary)); | 107 expected.push_back(make_pair(server_config_id, is_primary)); |
109 } | 108 } |
110 | 109 |
111 va_end(ap); | 110 va_end(ap); |
112 | 111 |
113 base::AutoLock locked(server_config_->configs_lock_); | 112 base::AutoLock locked(server_config_->configs_lock_); |
114 | 113 |
115 ASSERT_EQ(expected.size(), server_config_->configs_.size()) | 114 ASSERT_EQ(expected.size(), server_config_->configs_.size()) |
116 << ConfigsDebug(); | 115 << ConfigsDebug(); |
117 | 116 |
118 for (QuicCryptoServerConfig::ConfigMap::const_iterator | 117 for (QuicCryptoServerConfig::ConfigMap::const_iterator i = |
119 i = server_config_->configs_.begin(); | 118 server_config_->configs_.begin(); |
120 i != server_config_->configs_.end(); ++i) { | 119 i != server_config_->configs_.end(); |
| 120 ++i) { |
121 bool found = false; | 121 bool found = false; |
122 for (vector<pair<ServerConfigID, bool> >::iterator j = expected.begin(); | 122 for (vector<pair<ServerConfigID, bool> >::iterator j = expected.begin(); |
123 j != expected.end(); ++j) { | 123 j != expected.end(); |
| 124 ++j) { |
124 if (i->first == j->first && i->second->is_primary == j->second) { | 125 if (i->first == j->first && i->second->is_primary == j->second) { |
125 found = true; | 126 found = true; |
126 j->first.clear(); | 127 j->first.clear(); |
127 break; | 128 break; |
128 } | 129 } |
129 } | 130 } |
130 | 131 |
131 ASSERT_TRUE(found) << "Failed to find match for " << i->first | 132 ASSERT_TRUE(found) << "Failed to find match for " << i->first |
132 << " in configs:\n" << ConfigsDebug(); | 133 << " in configs:\n" << ConfigsDebug(); |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 // ConfigsDebug returns a string that contains debugging information about | 137 // ConfigsDebug returns a string that contains debugging information about |
137 // the set of Configs loaded in |server_config_| and their status. | 138 // the set of Configs loaded in |server_config_| and their status. |
138 // ConfigsDebug() should be called after acquiring | 139 // ConfigsDebug() should be called after acquiring |
139 // server_config_->configs_lock_. | 140 // server_config_->configs_lock_. |
140 string ConfigsDebug() { | 141 string ConfigsDebug() { |
141 if (server_config_->configs_.empty()) { | 142 if (server_config_->configs_.empty()) { |
142 return "No Configs in QuicCryptoServerConfig"; | 143 return "No Configs in QuicCryptoServerConfig"; |
143 } | 144 } |
144 | 145 |
145 string s; | 146 string s; |
146 | 147 |
147 for (QuicCryptoServerConfig::ConfigMap::const_iterator | 148 for (QuicCryptoServerConfig::ConfigMap::const_iterator i = |
148 i = server_config_->configs_.begin(); | 149 server_config_->configs_.begin(); |
149 i != server_config_->configs_.end(); ++i) { | 150 i != server_config_->configs_.end(); |
| 151 ++i) { |
150 const scoped_refptr<QuicCryptoServerConfig::Config> config = i->second; | 152 const scoped_refptr<QuicCryptoServerConfig::Config> config = i->second; |
151 if (config->is_primary) { | 153 if (config->is_primary) { |
152 s += "(primary) "; | 154 s += "(primary) "; |
153 } else { | 155 } else { |
154 s += " "; | 156 s += " "; |
155 } | 157 } |
156 s += config->id; | 158 s += config->id; |
157 s += "\n"; | 159 s += "\n"; |
158 } | 160 } |
159 | 161 |
160 return s; | 162 return s; |
161 } | 163 } |
162 | 164 |
163 void SelectNewPrimaryConfig(int seconds) { | 165 void SelectNewPrimaryConfig(int seconds) { |
164 base::AutoLock locked(server_config_->configs_lock_); | 166 base::AutoLock locked(server_config_->configs_lock_); |
165 server_config_->SelectNewPrimaryConfig( | 167 server_config_->SelectNewPrimaryConfig( |
166 QuicWallTime::FromUNIXSeconds(seconds)); | 168 QuicWallTime::FromUNIXSeconds(seconds)); |
167 } | 169 } |
168 | 170 |
169 private: | 171 private: |
170 const QuicCryptoServerConfig* server_config_; | 172 const QuicCryptoServerConfig* server_config_; |
171 }; | 173 }; |
172 | 174 |
173 class TestStrikeRegisterClient : public StrikeRegisterClient { | 175 class TestStrikeRegisterClient : public StrikeRegisterClient { |
174 public: | 176 public: |
175 explicit TestStrikeRegisterClient(QuicCryptoServerConfig* config) | 177 explicit TestStrikeRegisterClient(QuicCryptoServerConfig* config) |
176 : config_(config), | 178 : config_(config), is_known_orbit_called_(false) {} |
177 is_known_orbit_called_(false) { | |
178 } | |
179 | 179 |
180 virtual bool IsKnownOrbit(StringPiece orbit) const OVERRIDE { | 180 virtual bool IsKnownOrbit(StringPiece orbit) const OVERRIDE { |
181 // Ensure that the strike register client lock is not held. | 181 // Ensure that the strike register client lock is not held. |
182 QuicCryptoServerConfigPeer peer(config_); | 182 QuicCryptoServerConfigPeer peer(config_); |
183 base::Lock* m = peer.GetStrikeRegisterClientLock(); | 183 base::Lock* m = peer.GetStrikeRegisterClientLock(); |
184 // In Chromium, we will dead lock if the lock is held by the current thread. | 184 // In Chromium, we will dead lock if the lock is held by the current thread. |
185 // Chromium doesn't have AssertNotHeld API call. | 185 // Chromium doesn't have AssertNotHeld API call. |
186 // m->AssertNotHeld(); | 186 // m->AssertNotHeld(); |
187 base::AutoLock lock(*m); | 187 base::AutoLock lock(*m); |
188 | 188 |
189 is_known_orbit_called_ = true; | 189 is_known_orbit_called_ = true; |
190 return true; | 190 return true; |
191 } | 191 } |
192 | 192 |
193 virtual void VerifyNonceIsValidAndUnique( | 193 virtual void VerifyNonceIsValidAndUnique(StringPiece nonce, |
194 StringPiece nonce, | 194 QuicWallTime now, |
195 QuicWallTime now, | 195 ResultCallback* cb) OVERRIDE { |
196 ResultCallback* cb) OVERRIDE { | |
197 LOG(FATAL) << "Not implemented"; | 196 LOG(FATAL) << "Not implemented"; |
198 } | 197 } |
199 | 198 |
200 bool is_known_orbit_called() { return is_known_orbit_called_; } | 199 bool is_known_orbit_called() { return is_known_orbit_called_; } |
201 | 200 |
202 private: | 201 private: |
203 QuicCryptoServerConfig* config_; | 202 QuicCryptoServerConfig* config_; |
204 mutable bool is_known_orbit_called_; | 203 mutable bool is_known_orbit_called_; |
205 }; | 204 }; |
206 | 205 |
207 TEST(QuicCryptoServerConfigTest, ServerConfig) { | 206 TEST(QuicCryptoServerConfigTest, ServerConfig) { |
208 QuicRandom* rand = QuicRandom::GetInstance(); | 207 QuicRandom* rand = QuicRandom::GetInstance(); |
209 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); | 208 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
210 MockClock clock; | 209 MockClock clock; |
211 | 210 |
212 scoped_ptr<CryptoHandshakeMessage>( | 211 scoped_ptr<CryptoHandshakeMessage>(server.AddDefaultConfig( |
213 server.AddDefaultConfig(rand, &clock, | 212 rand, &clock, QuicCryptoServerConfig::ConfigOptions())); |
214 QuicCryptoServerConfig::ConfigOptions())); | |
215 } | 213 } |
216 | 214 |
217 TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { | 215 TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { |
218 QuicRandom* rand = QuicRandom::GetInstance(); | 216 QuicRandom* rand = QuicRandom::GetInstance(); |
219 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); | 217 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
220 MockClock clock; | 218 MockClock clock; |
221 | 219 |
222 TestStrikeRegisterClient* strike_register = | 220 TestStrikeRegisterClient* strike_register = |
223 new TestStrikeRegisterClient(&server); | 221 new TestStrikeRegisterClient(&server); |
224 server.SetStrikeRegisterClient(strike_register); | 222 server.SetStrikeRegisterClient(strike_register); |
(...skipping 11 matching lines...) Expand all Loading... |
236 MockClock clock; | 234 MockClock clock; |
237 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); | 235 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); |
238 | 236 |
239 QuicWallTime now = clock.WallNow(); | 237 QuicWallTime now = clock.WallNow(); |
240 const QuicWallTime original_time = now; | 238 const QuicWallTime original_time = now; |
241 | 239 |
242 QuicRandom* rand = QuicRandom::GetInstance(); | 240 QuicRandom* rand = QuicRandom::GetInstance(); |
243 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); | 241 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
244 QuicCryptoServerConfigPeer peer(&server); | 242 QuicCryptoServerConfigPeer peer(&server); |
245 | 243 |
246 scoped_ptr<CryptoHandshakeMessage>( | 244 scoped_ptr<CryptoHandshakeMessage>(server.AddDefaultConfig( |
247 server.AddDefaultConfig(rand, &clock, | 245 rand, &clock, QuicCryptoServerConfig::ConfigOptions())); |
248 QuicCryptoServerConfig::ConfigOptions())); | |
249 | 246 |
250 // Add a config that overrides the default boxer. | 247 // Add a config that overrides the default boxer. |
251 QuicCryptoServerConfig::ConfigOptions options; | 248 QuicCryptoServerConfig::ConfigOptions options; |
252 options.id = kOverride; | 249 options.id = kOverride; |
253 scoped_ptr<QuicServerConfigProtobuf> protobuf( | 250 scoped_ptr<QuicServerConfigProtobuf> protobuf( |
254 QuicCryptoServerConfig::GenerateConfig(rand, &clock, options)); | 251 QuicCryptoServerConfig::GenerateConfig(rand, &clock, options)); |
255 protobuf->set_source_address_token_secret_override("a secret key"); | 252 protobuf->set_source_address_token_secret_override("a secret key"); |
256 // Lower priority than the default config. | 253 // Lower priority than the default config. |
257 protobuf->set_priority(1); | 254 protobuf->set_priority(1); |
258 scoped_ptr<CryptoHandshakeMessage>( | 255 scoped_ptr<CryptoHandshakeMessage>(server.AddConfig(protobuf.get(), now)); |
259 server.AddConfig(protobuf.get(), now)); | |
260 | 256 |
261 EXPECT_TRUE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kPrimary)); | 257 EXPECT_TRUE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kPrimary)); |
262 EXPECT_FALSE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kOverride)); | 258 EXPECT_FALSE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kOverride)); |
263 | 259 |
264 IPAddressNumber ip; | 260 IPAddressNumber ip; |
265 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 261 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
266 IPEndPoint ip4 = IPEndPoint(ip, 1); | 262 IPEndPoint ip4 = IPEndPoint(ip, 1); |
267 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip)); | 263 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip)); |
268 IPEndPoint ip6 = IPEndPoint(ip, 2); | 264 IPEndPoint ip6 = IPEndPoint(ip, 2); |
269 | 265 |
270 // Primary config generates configs that validate successfully. | 266 // Primary config generates configs that validate successfully. |
271 const string token4 = peer.NewSourceAddressToken(kPrimary, ip4, rand, now); | 267 const string token4 = peer.NewSourceAddressToken(kPrimary, ip4, rand, now); |
272 const string token6 = peer.NewSourceAddressToken(kPrimary, ip6, rand, now); | 268 const string token6 = peer.NewSourceAddressToken(kPrimary, ip6, rand, now); |
273 EXPECT_TRUE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); | 269 EXPECT_TRUE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); |
274 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip6, now)); | 270 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip6, now)); |
275 EXPECT_TRUE(peer.ValidateSourceAddressToken(kPrimary, token6, ip6, now)); | 271 EXPECT_TRUE(peer.ValidateSourceAddressToken(kPrimary, token6, ip6, now)); |
276 | 272 |
277 // Override config generates configs that validate successfully. | 273 // Override config generates configs that validate successfully. |
278 const string override_token4 = peer.NewSourceAddressToken( | 274 const string override_token4 = |
279 kOverride, ip4, rand, now); | 275 peer.NewSourceAddressToken(kOverride, ip4, rand, now); |
280 const string override_token6 = peer.NewSourceAddressToken( | 276 const string override_token6 = |
281 kOverride, ip6, rand, now); | 277 peer.NewSourceAddressToken(kOverride, ip6, rand, now); |
282 EXPECT_TRUE(peer.ValidateSourceAddressToken( | 278 EXPECT_TRUE( |
283 kOverride, override_token4, ip4, now)); | 279 peer.ValidateSourceAddressToken(kOverride, override_token4, ip4, now)); |
284 EXPECT_FALSE(peer.ValidateSourceAddressToken( | 280 EXPECT_FALSE( |
285 kOverride, override_token4, ip6, now)); | 281 peer.ValidateSourceAddressToken(kOverride, override_token4, ip6, now)); |
286 EXPECT_TRUE(peer.ValidateSourceAddressToken( | 282 EXPECT_TRUE( |
287 kOverride, override_token6, ip6, now)); | 283 peer.ValidateSourceAddressToken(kOverride, override_token6, ip6, now)); |
288 | 284 |
289 // Tokens generated by the primary config do not validate | 285 // Tokens generated by the primary config do not validate |
290 // successfully against the override config, and vice versa. | 286 // successfully against the override config, and vice versa. |
291 EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token4, ip4, now)); | 287 EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token4, ip4, now)); |
292 EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token6, ip6, now)); | 288 EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token6, ip6, now)); |
293 EXPECT_FALSE(peer.ValidateSourceAddressToken( | 289 EXPECT_FALSE( |
294 kPrimary, override_token4, ip4, now)); | 290 peer.ValidateSourceAddressToken(kPrimary, override_token4, ip4, now)); |
295 EXPECT_FALSE(peer.ValidateSourceAddressToken( | 291 EXPECT_FALSE( |
296 kPrimary, override_token6, ip6, now)); | 292 peer.ValidateSourceAddressToken(kPrimary, override_token6, ip6, now)); |
297 | 293 |
298 // Validation fails after tokens expire. | 294 // Validation fails after tokens expire. |
299 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); | 295 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); |
300 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); | 296 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); |
301 | 297 |
302 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); | 298 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); |
303 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); | 299 EXPECT_FALSE(peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); |
304 } | 300 } |
305 | 301 |
306 class CryptoServerConfigsTest : public ::testing::Test { | 302 class CryptoServerConfigsTest : public ::testing::Test { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 QuicCryptoServerConfig config_; | 381 QuicCryptoServerConfig config_; |
386 QuicCryptoServerConfigPeer test_peer_; | 382 QuicCryptoServerConfigPeer test_peer_; |
387 }; | 383 }; |
388 | 384 |
389 TEST_F(CryptoServerConfigsTest, NoConfigs) { | 385 TEST_F(CryptoServerConfigsTest, NoConfigs) { |
390 test_peer_.CheckConfigs(NULL); | 386 test_peer_.CheckConfigs(NULL); |
391 } | 387 } |
392 | 388 |
393 TEST_F(CryptoServerConfigsTest, MakePrimaryFirst) { | 389 TEST_F(CryptoServerConfigsTest, MakePrimaryFirst) { |
394 // Make sure that "b" is primary even though "a" comes first. | 390 // Make sure that "b" is primary even though "a" comes first. |
395 SetConfigs("a", 1100, 1, | 391 SetConfigs("a", 1100, 1, "b", 900, 1, NULL); |
396 "b", 900, 1, | 392 test_peer_.CheckConfigs("a", false, "b", true, NULL); |
397 NULL); | |
398 test_peer_.CheckConfigs( | |
399 "a", false, | |
400 "b", true, | |
401 NULL); | |
402 } | 393 } |
403 | 394 |
404 TEST_F(CryptoServerConfigsTest, MakePrimarySecond) { | 395 TEST_F(CryptoServerConfigsTest, MakePrimarySecond) { |
405 // Make sure that a remains primary after b is added. | 396 // Make sure that a remains primary after b is added. |
406 SetConfigs("a", 900, 1, | 397 SetConfigs("a", 900, 1, "b", 1100, 1, NULL); |
407 "b", 1100, 1, | 398 test_peer_.CheckConfigs("a", true, "b", false, NULL); |
408 NULL); | |
409 test_peer_.CheckConfigs( | |
410 "a", true, | |
411 "b", false, | |
412 NULL); | |
413 } | 399 } |
414 | 400 |
415 TEST_F(CryptoServerConfigsTest, Delete) { | 401 TEST_F(CryptoServerConfigsTest, Delete) { |
416 // Ensure that configs get deleted when removed. | 402 // Ensure that configs get deleted when removed. |
417 SetConfigs("a", 800, 1, | 403 SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
418 "b", 900, 1, | 404 test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
419 "c", 1100, 1, | 405 SetConfigs("b", 900, 1, "c", 1100, 1, NULL); |
420 NULL); | 406 test_peer_.CheckConfigs("b", true, "c", false, NULL); |
421 test_peer_.CheckConfigs( | |
422 "a", false, | |
423 "b", true, | |
424 "c", false, | |
425 NULL); | |
426 SetConfigs("b", 900, 1, | |
427 "c", 1100, 1, | |
428 NULL); | |
429 test_peer_.CheckConfigs( | |
430 "b", true, | |
431 "c", false, | |
432 NULL); | |
433 } | 407 } |
434 | 408 |
435 TEST_F(CryptoServerConfigsTest, DeletePrimary) { | 409 TEST_F(CryptoServerConfigsTest, DeletePrimary) { |
436 // Ensure that deleting the primary config works. | 410 // Ensure that deleting the primary config works. |
437 SetConfigs("a", 800, 1, | 411 SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
438 "b", 900, 1, | 412 test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
439 "c", 1100, 1, | 413 SetConfigs("a", 800, 1, "c", 1100, 1, NULL); |
440 NULL); | 414 test_peer_.CheckConfigs("a", true, "c", false, NULL); |
441 test_peer_.CheckConfigs( | |
442 "a", false, | |
443 "b", true, | |
444 "c", false, | |
445 NULL); | |
446 SetConfigs("a", 800, 1, | |
447 "c", 1100, 1, | |
448 NULL); | |
449 test_peer_.CheckConfigs( | |
450 "a", true, | |
451 "c", false, | |
452 NULL); | |
453 } | 415 } |
454 | 416 |
455 TEST_F(CryptoServerConfigsTest, FailIfDeletingAllConfigs) { | 417 TEST_F(CryptoServerConfigsTest, FailIfDeletingAllConfigs) { |
456 // Ensure that configs get deleted when removed. | 418 // Ensure that configs get deleted when removed. |
457 SetConfigs("a", 800, 1, | 419 SetConfigs("a", 800, 1, "b", 900, 1, NULL); |
458 "b", 900, 1, | 420 test_peer_.CheckConfigs("a", false, "b", true, NULL); |
459 NULL); | |
460 test_peer_.CheckConfigs( | |
461 "a", false, | |
462 "b", true, | |
463 NULL); | |
464 SetConfigs(NULL); | 421 SetConfigs(NULL); |
465 // Config change is rejected, still using old configs. | 422 // Config change is rejected, still using old configs. |
466 test_peer_.CheckConfigs( | 423 test_peer_.CheckConfigs("a", false, "b", true, NULL); |
467 "a", false, | |
468 "b", true, | |
469 NULL); | |
470 } | 424 } |
471 | 425 |
472 TEST_F(CryptoServerConfigsTest, ChangePrimaryTime) { | 426 TEST_F(CryptoServerConfigsTest, ChangePrimaryTime) { |
473 // Check that updates to primary time get picked up. | 427 // Check that updates to primary time get picked up. |
474 SetConfigs("a", 400, 1, | 428 SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
475 "b", 800, 1, | |
476 "c", 1200, 1, | |
477 NULL); | |
478 test_peer_.SelectNewPrimaryConfig(500); | 429 test_peer_.SelectNewPrimaryConfig(500); |
479 test_peer_.CheckConfigs( | 430 test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
480 "a", true, | 431 SetConfigs("a", 1200, 1, "b", 800, 1, "c", 400, 1, NULL); |
481 "b", false, | |
482 "c", false, | |
483 NULL); | |
484 SetConfigs("a", 1200, 1, | |
485 "b", 800, 1, | |
486 "c", 400, 1, | |
487 NULL); | |
488 test_peer_.SelectNewPrimaryConfig(500); | 432 test_peer_.SelectNewPrimaryConfig(500); |
489 test_peer_.CheckConfigs( | 433 test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
490 "a", false, | |
491 "b", false, | |
492 "c", true, | |
493 NULL); | |
494 } | 434 } |
495 | 435 |
496 TEST_F(CryptoServerConfigsTest, AllConfigsInThePast) { | 436 TEST_F(CryptoServerConfigsTest, AllConfigsInThePast) { |
497 // Check that the most recent config is selected. | 437 // Check that the most recent config is selected. |
498 SetConfigs("a", 400, 1, | 438 SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
499 "b", 800, 1, | |
500 "c", 1200, 1, | |
501 NULL); | |
502 test_peer_.SelectNewPrimaryConfig(1500); | 439 test_peer_.SelectNewPrimaryConfig(1500); |
503 test_peer_.CheckConfigs( | 440 test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
504 "a", false, | |
505 "b", false, | |
506 "c", true, | |
507 NULL); | |
508 } | 441 } |
509 | 442 |
510 TEST_F(CryptoServerConfigsTest, AllConfigsInTheFuture) { | 443 TEST_F(CryptoServerConfigsTest, AllConfigsInTheFuture) { |
511 // Check that the first config is selected. | 444 // Check that the first config is selected. |
512 SetConfigs("a", 400, 1, | 445 SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
513 "b", 800, 1, | |
514 "c", 1200, 1, | |
515 NULL); | |
516 test_peer_.SelectNewPrimaryConfig(100); | 446 test_peer_.SelectNewPrimaryConfig(100); |
517 test_peer_.CheckConfigs( | 447 test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
518 "a", true, | |
519 "b", false, | |
520 "c", false, | |
521 NULL); | |
522 } | 448 } |
523 | 449 |
524 TEST_F(CryptoServerConfigsTest, SortByPriority) { | 450 TEST_F(CryptoServerConfigsTest, SortByPriority) { |
525 // Check that priority is used to decide on a primary config when | 451 // Check that priority is used to decide on a primary config when |
526 // configs have the same primary time. | 452 // configs have the same primary time. |
527 SetConfigs("a", 900, 1, | 453 SetConfigs("a", 900, 1, "b", 900, 2, "c", 900, 3, NULL); |
528 "b", 900, 2, | 454 test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
529 "c", 900, 3, | |
530 NULL); | |
531 test_peer_.CheckConfigs( | |
532 "a", true, | |
533 "b", false, | |
534 "c", false, | |
535 NULL); | |
536 test_peer_.SelectNewPrimaryConfig(800); | 455 test_peer_.SelectNewPrimaryConfig(800); |
537 test_peer_.CheckConfigs( | 456 test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
538 "a", true, | |
539 "b", false, | |
540 "c", false, | |
541 NULL); | |
542 test_peer_.SelectNewPrimaryConfig(1000); | 457 test_peer_.SelectNewPrimaryConfig(1000); |
543 test_peer_.CheckConfigs( | 458 test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
544 "a", true, | |
545 "b", false, | |
546 "c", false, | |
547 NULL); | |
548 | 459 |
549 // Change priorities and expect sort order to change. | 460 // Change priorities and expect sort order to change. |
550 SetConfigs("a", 900, 2, | 461 SetConfigs("a", 900, 2, "b", 900, 1, "c", 900, 0, NULL); |
551 "b", 900, 1, | 462 test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
552 "c", 900, 0, | |
553 NULL); | |
554 test_peer_.CheckConfigs( | |
555 "a", false, | |
556 "b", false, | |
557 "c", true, | |
558 NULL); | |
559 test_peer_.SelectNewPrimaryConfig(800); | 463 test_peer_.SelectNewPrimaryConfig(800); |
560 test_peer_.CheckConfigs( | 464 test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
561 "a", false, | |
562 "b", false, | |
563 "c", true, | |
564 NULL); | |
565 test_peer_.SelectNewPrimaryConfig(1000); | 465 test_peer_.SelectNewPrimaryConfig(1000); |
566 test_peer_.CheckConfigs( | 466 test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
567 "a", false, | |
568 "b", false, | |
569 "c", true, | |
570 NULL); | |
571 } | 467 } |
572 | 468 |
573 TEST_F(CryptoServerConfigsTest, AdvancePrimary) { | 469 TEST_F(CryptoServerConfigsTest, AdvancePrimary) { |
574 // Check that a new primary config is enabled at the right time. | 470 // Check that a new primary config is enabled at the right time. |
575 SetConfigs("a", 900, 1, | 471 SetConfigs("a", 900, 1, "b", 1100, 1, NULL); |
576 "b", 1100, 1, | |
577 NULL); | |
578 test_peer_.SelectNewPrimaryConfig(1000); | 472 test_peer_.SelectNewPrimaryConfig(1000); |
579 test_peer_.CheckConfigs( | 473 test_peer_.CheckConfigs("a", true, "b", false, NULL); |
580 "a", true, | |
581 "b", false, | |
582 NULL); | |
583 test_peer_.SelectNewPrimaryConfig(1101); | 474 test_peer_.SelectNewPrimaryConfig(1101); |
584 test_peer_.CheckConfigs( | 475 test_peer_.CheckConfigs("a", false, "b", true, NULL); |
585 "a", false, | |
586 "b", true, | |
587 NULL); | |
588 } | 476 } |
589 | 477 |
590 TEST_F(CryptoServerConfigsTest, InvalidConfigs) { | 478 TEST_F(CryptoServerConfigsTest, InvalidConfigs) { |
591 // Ensure that invalid configs don't change anything. | 479 // Ensure that invalid configs don't change anything. |
592 SetConfigs("a", 800, 1, | 480 SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
593 "b", 900, 1, | 481 test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
594 "c", 1100, 1, | 482 SetConfigs("a", 800, 1, "c", 1100, 1, "INVALID1", 1000, 1, NULL); |
595 NULL); | 483 test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
596 test_peer_.CheckConfigs( | |
597 "a", false, | |
598 "b", true, | |
599 "c", false, | |
600 NULL); | |
601 SetConfigs("a", 800, 1, | |
602 "c", 1100, 1, | |
603 "INVALID1", 1000, 1, | |
604 NULL); | |
605 test_peer_.CheckConfigs( | |
606 "a", false, | |
607 "b", true, | |
608 "c", false, | |
609 NULL); | |
610 } | 484 } |
611 | 485 |
612 } // namespace test | 486 } // namespace test |
613 } // namespace net | 487 } // namespace net |
OLD | NEW |