Index: net/quic/crypto/quic_crypto_server_config_test.cc |
diff --git a/net/quic/crypto/quic_crypto_server_config_test.cc b/net/quic/crypto/quic_crypto_server_config_test.cc |
index 8aeef009eeced9cc478514b6dd0eba63d5696031..9cb1e6ac19ddffae1b698bd18c9b769d05a8d565 100644 |
--- a/net/quic/crypto/quic_crypto_server_config_test.cc |
+++ b/net/quic/crypto/quic_crypto_server_config_test.cc |
@@ -45,14 +45,13 @@ class QuicCryptoServerConfigPeer { |
bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) { |
scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id); |
return config->source_address_token_boxer == |
- &(server_config_->default_source_address_token_boxer_); |
+ &(server_config_->default_source_address_token_boxer_); |
} |
- string NewSourceAddressToken( |
- string config_id, |
- IPEndPoint ip, |
- QuicRandom* rand, |
- QuicWallTime now) { |
+ string NewSourceAddressToken(string config_id, |
+ IPEndPoint ip, |
+ QuicRandom* rand, |
+ QuicWallTime now) { |
return server_config_->NewSourceAddressToken( |
*GetConfig(config_id), ip, rand, now); |
} |
@@ -115,12 +114,14 @@ class QuicCryptoServerConfigPeer { |
ASSERT_EQ(expected.size(), server_config_->configs_.size()) |
<< ConfigsDebug(); |
- for (QuicCryptoServerConfig::ConfigMap::const_iterator |
- i = server_config_->configs_.begin(); |
- i != server_config_->configs_.end(); ++i) { |
+ for (QuicCryptoServerConfig::ConfigMap::const_iterator i = |
+ server_config_->configs_.begin(); |
+ i != server_config_->configs_.end(); |
+ ++i) { |
bool found = false; |
for (vector<pair<ServerConfigID, bool> >::iterator j = expected.begin(); |
- j != expected.end(); ++j) { |
+ j != expected.end(); |
+ ++j) { |
if (i->first == j->first && i->second->is_primary == j->second) { |
found = true; |
j->first.clear(); |
@@ -144,9 +145,10 @@ class QuicCryptoServerConfigPeer { |
string s; |
- for (QuicCryptoServerConfig::ConfigMap::const_iterator |
- i = server_config_->configs_.begin(); |
- i != server_config_->configs_.end(); ++i) { |
+ for (QuicCryptoServerConfig::ConfigMap::const_iterator i = |
+ server_config_->configs_.begin(); |
+ i != server_config_->configs_.end(); |
+ ++i) { |
const scoped_refptr<QuicCryptoServerConfig::Config> config = i->second; |
if (config->is_primary) { |
s += "(primary) "; |
@@ -173,9 +175,7 @@ class QuicCryptoServerConfigPeer { |
class TestStrikeRegisterClient : public StrikeRegisterClient { |
public: |
explicit TestStrikeRegisterClient(QuicCryptoServerConfig* config) |
- : config_(config), |
- is_known_orbit_called_(false) { |
- } |
+ : config_(config), is_known_orbit_called_(false) {} |
virtual bool IsKnownOrbit(StringPiece orbit) const OVERRIDE { |
// Ensure that the strike register client lock is not held. |
@@ -190,10 +190,9 @@ class TestStrikeRegisterClient : public StrikeRegisterClient { |
return true; |
} |
- virtual void VerifyNonceIsValidAndUnique( |
- StringPiece nonce, |
- QuicWallTime now, |
- ResultCallback* cb) OVERRIDE { |
+ virtual void VerifyNonceIsValidAndUnique(StringPiece nonce, |
+ QuicWallTime now, |
+ ResultCallback* cb) OVERRIDE { |
LOG(FATAL) << "Not implemented"; |
} |
@@ -209,9 +208,8 @@ TEST(QuicCryptoServerConfigTest, ServerConfig) { |
QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
MockClock clock; |
- scoped_ptr<CryptoHandshakeMessage>( |
- server.AddDefaultConfig(rand, &clock, |
- QuicCryptoServerConfig::ConfigOptions())); |
+ scoped_ptr<CryptoHandshakeMessage>(server.AddDefaultConfig( |
+ rand, &clock, QuicCryptoServerConfig::ConfigOptions())); |
} |
TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { |
@@ -243,9 +241,8 @@ TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { |
QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); |
QuicCryptoServerConfigPeer peer(&server); |
- scoped_ptr<CryptoHandshakeMessage>( |
- server.AddDefaultConfig(rand, &clock, |
- QuicCryptoServerConfig::ConfigOptions())); |
+ scoped_ptr<CryptoHandshakeMessage>(server.AddDefaultConfig( |
+ rand, &clock, QuicCryptoServerConfig::ConfigOptions())); |
// Add a config that overrides the default boxer. |
QuicCryptoServerConfig::ConfigOptions options; |
@@ -255,8 +252,7 @@ TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { |
protobuf->set_source_address_token_secret_override("a secret key"); |
// Lower priority than the default config. |
protobuf->set_priority(1); |
- scoped_ptr<CryptoHandshakeMessage>( |
- server.AddConfig(protobuf.get(), now)); |
+ scoped_ptr<CryptoHandshakeMessage>(server.AddConfig(protobuf.get(), now)); |
EXPECT_TRUE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kPrimary)); |
EXPECT_FALSE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kOverride)); |
@@ -275,25 +271,25 @@ TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { |
EXPECT_TRUE(peer.ValidateSourceAddressToken(kPrimary, token6, ip6, now)); |
// Override config generates configs that validate successfully. |
- const string override_token4 = peer.NewSourceAddressToken( |
- kOverride, ip4, rand, now); |
- const string override_token6 = peer.NewSourceAddressToken( |
- kOverride, ip6, rand, now); |
- EXPECT_TRUE(peer.ValidateSourceAddressToken( |
- kOverride, override_token4, ip4, now)); |
- EXPECT_FALSE(peer.ValidateSourceAddressToken( |
- kOverride, override_token4, ip6, now)); |
- EXPECT_TRUE(peer.ValidateSourceAddressToken( |
- kOverride, override_token6, ip6, now)); |
+ const string override_token4 = |
+ peer.NewSourceAddressToken(kOverride, ip4, rand, now); |
+ const string override_token6 = |
+ peer.NewSourceAddressToken(kOverride, ip6, rand, now); |
+ EXPECT_TRUE( |
+ peer.ValidateSourceAddressToken(kOverride, override_token4, ip4, now)); |
+ EXPECT_FALSE( |
+ peer.ValidateSourceAddressToken(kOverride, override_token4, ip6, now)); |
+ EXPECT_TRUE( |
+ peer.ValidateSourceAddressToken(kOverride, override_token6, ip6, now)); |
// Tokens generated by the primary config do not validate |
// successfully against the override config, and vice versa. |
EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token4, ip4, now)); |
EXPECT_FALSE(peer.ValidateSourceAddressToken(kOverride, token6, ip6, now)); |
- EXPECT_FALSE(peer.ValidateSourceAddressToken( |
- kPrimary, override_token4, ip4, now)); |
- EXPECT_FALSE(peer.ValidateSourceAddressToken( |
- kPrimary, override_token6, ip6, now)); |
+ EXPECT_FALSE( |
+ peer.ValidateSourceAddressToken(kPrimary, override_token4, ip4, now)); |
+ EXPECT_FALSE( |
+ peer.ValidateSourceAddressToken(kPrimary, override_token6, ip6, now)); |
// Validation fails after tokens expire. |
now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); |
@@ -392,221 +388,99 @@ TEST_F(CryptoServerConfigsTest, NoConfigs) { |
TEST_F(CryptoServerConfigsTest, MakePrimaryFirst) { |
// Make sure that "b" is primary even though "a" comes first. |
- SetConfigs("a", 1100, 1, |
- "b", 900, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- NULL); |
+ SetConfigs("a", 1100, 1, "b", 900, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, MakePrimarySecond) { |
// Make sure that a remains primary after b is added. |
- SetConfigs("a", 900, 1, |
- "b", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- NULL); |
+ SetConfigs("a", 900, 1, "b", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, NULL); |
} |
TEST_F(CryptoServerConfigsTest, Delete) { |
// Ensure that configs get deleted when removed. |
- SetConfigs("a", 800, 1, |
- "b", 900, 1, |
- "c", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- "c", false, |
- NULL); |
- SetConfigs("b", 900, 1, |
- "c", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "b", true, |
- "c", false, |
- NULL); |
+ SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
+ SetConfigs("b", 900, 1, "c", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("b", true, "c", false, NULL); |
} |
TEST_F(CryptoServerConfigsTest, DeletePrimary) { |
// Ensure that deleting the primary config works. |
- SetConfigs("a", 800, 1, |
- "b", 900, 1, |
- "c", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- "c", false, |
- NULL); |
- SetConfigs("a", 800, 1, |
- "c", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "c", false, |
- NULL); |
+ SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
+ SetConfigs("a", 800, 1, "c", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("a", true, "c", false, NULL); |
} |
TEST_F(CryptoServerConfigsTest, FailIfDeletingAllConfigs) { |
// Ensure that configs get deleted when removed. |
- SetConfigs("a", 800, 1, |
- "b", 900, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- NULL); |
+ SetConfigs("a", 800, 1, "b", 900, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, NULL); |
SetConfigs(NULL); |
// Config change is rejected, still using old configs. |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, ChangePrimaryTime) { |
// Check that updates to primary time get picked up. |
- SetConfigs("a", 400, 1, |
- "b", 800, 1, |
- "c", 1200, 1, |
- NULL); |
+ SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
test_peer_.SelectNewPrimaryConfig(500); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- "c", false, |
- NULL); |
- SetConfigs("a", 1200, 1, |
- "b", 800, 1, |
- "c", 400, 1, |
- NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
+ SetConfigs("a", 1200, 1, "b", 800, 1, "c", 400, 1, NULL); |
test_peer_.SelectNewPrimaryConfig(500); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", false, |
- "c", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, AllConfigsInThePast) { |
// Check that the most recent config is selected. |
- SetConfigs("a", 400, 1, |
- "b", 800, 1, |
- "c", 1200, 1, |
- NULL); |
+ SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
test_peer_.SelectNewPrimaryConfig(1500); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", false, |
- "c", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, AllConfigsInTheFuture) { |
// Check that the first config is selected. |
- SetConfigs("a", 400, 1, |
- "b", 800, 1, |
- "c", 1200, 1, |
- NULL); |
+ SetConfigs("a", 400, 1, "b", 800, 1, "c", 1200, 1, NULL); |
test_peer_.SelectNewPrimaryConfig(100); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- "c", false, |
- NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
} |
TEST_F(CryptoServerConfigsTest, SortByPriority) { |
// Check that priority is used to decide on a primary config when |
// configs have the same primary time. |
- SetConfigs("a", 900, 1, |
- "b", 900, 2, |
- "c", 900, 3, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- "c", false, |
- NULL); |
+ SetConfigs("a", 900, 1, "b", 900, 2, "c", 900, 3, NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
test_peer_.SelectNewPrimaryConfig(800); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- "c", false, |
- NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
test_peer_.SelectNewPrimaryConfig(1000); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- "c", false, |
- NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, "c", false, NULL); |
// Change priorities and expect sort order to change. |
- SetConfigs("a", 900, 2, |
- "b", 900, 1, |
- "c", 900, 0, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", false, |
- "c", true, |
- NULL); |
+ SetConfigs("a", 900, 2, "b", 900, 1, "c", 900, 0, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
test_peer_.SelectNewPrimaryConfig(800); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", false, |
- "c", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
test_peer_.SelectNewPrimaryConfig(1000); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", false, |
- "c", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", false, "c", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, AdvancePrimary) { |
// Check that a new primary config is enabled at the right time. |
- SetConfigs("a", 900, 1, |
- "b", 1100, 1, |
- NULL); |
+ SetConfigs("a", 900, 1, "b", 1100, 1, NULL); |
test_peer_.SelectNewPrimaryConfig(1000); |
- test_peer_.CheckConfigs( |
- "a", true, |
- "b", false, |
- NULL); |
+ test_peer_.CheckConfigs("a", true, "b", false, NULL); |
test_peer_.SelectNewPrimaryConfig(1101); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, NULL); |
} |
TEST_F(CryptoServerConfigsTest, InvalidConfigs) { |
// Ensure that invalid configs don't change anything. |
- SetConfigs("a", 800, 1, |
- "b", 900, 1, |
- "c", 1100, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- "c", false, |
- NULL); |
- SetConfigs("a", 800, 1, |
- "c", 1100, 1, |
- "INVALID1", 1000, 1, |
- NULL); |
- test_peer_.CheckConfigs( |
- "a", false, |
- "b", true, |
- "c", false, |
- NULL); |
+ SetConfigs("a", 800, 1, "b", 900, 1, "c", 1100, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
+ SetConfigs("a", 800, 1, "c", 1100, 1, "INVALID1", 1000, 1, NULL); |
+ test_peer_.CheckConfigs("a", false, "b", true, "c", false, NULL); |
} |
} // namespace test |