Add QuicCryptoClientConfigTest.MultipleCanonicalEntries.
When working on cl/378863627 I originally wrote:
auto it = canonical_server_map_.lower_bound(suffix_server_id);
if (it == canonical_server_map_.end() || it->first < suffix_server_id) {
canonical_server_map_.insert(...);
return false;
}
This is incorrect: lower_bound() never returns an iterator with key less than
its argument. No tests caught this. The statement should have been
if (it == canonical_server_map_.end() || suffix_server_id < it->first) {
or simply
if (it == canonical_server_map_.end() || it->first != suffix_server_id) {
This CL adds a test that would have failed with the incorrect statement.
PiperOrigin-RevId: 378922152
diff --git a/quic/core/crypto/quic_crypto_client_config_test.cc b/quic/core/crypto/quic_crypto_client_config_test.cc
index 6dd0967..5bcf01c 100644
--- a/quic/core/crypto/quic_crypto_client_config_test.cc
+++ b/quic/core/crypto/quic_crypto_client_config_test.cc
@@ -179,6 +179,7 @@
QuicWallTime expiry = QuicWallTime::FromUNIXSeconds(2);
state.SetServerConfig(scfg.GetSerialized().AsStringPiece(), now, expiry,
&details);
+ EXPECT_FALSE(state.IsEmpty());
QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting());
QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params(
@@ -205,6 +206,7 @@
state.SetServerConfig(scfg.GetSerialized().AsStringPiece(),
QuicWallTime::FromUNIXSeconds(1),
QuicWallTime::FromUNIXSeconds(0), &details);
+ EXPECT_FALSE(state.IsEmpty());
QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting());
QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params(
@@ -503,5 +505,46 @@
EXPECT_EQ("server hello missing server nonce", error_details);
}
+// Test that PopulateFromCanonicalConfig() handles the case of multiple entries
+// in |canonical_server_map_|.
+TEST_F(QuicCryptoClientConfigTest, MultipleCanonicalEntries) {
+ QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting());
+ config.AddCanonicalSuffix(".google.com");
+ QuicServerId canonical_server_id1("www.google.com", 443, false);
+ QuicCryptoClientConfig::CachedState* state1 =
+ config.LookupOrCreate(canonical_server_id1);
+
+ CryptoHandshakeMessage scfg;
+ scfg.set_tag(kSCFG);
+ scfg.SetStringPiece(kSCID, "12345678");
+ std::string details;
+ QuicWallTime now = QuicWallTime::FromUNIXSeconds(1);
+ QuicWallTime expiry = QuicWallTime::FromUNIXSeconds(2);
+ state1->SetServerConfig(scfg.GetSerialized().AsStringPiece(), now, expiry,
+ &details);
+ state1->set_source_address_token("TOKEN");
+ state1->SetProofValid();
+ EXPECT_FALSE(state1->IsEmpty());
+
+ // This will have the same |suffix_server_id| as |canonical_server_id1|,
+ // therefore |*state2| will be initialized from |*state1|.
+ QuicServerId canonical_server_id2("mail.google.com", 443, false);
+ QuicCryptoClientConfig::CachedState* state2 =
+ config.LookupOrCreate(canonical_server_id2);
+ EXPECT_FALSE(state2->IsEmpty());
+ const CryptoHandshakeMessage* const scfg2 = state2->GetServerConfig();
+ ASSERT_TRUE(scfg2);
+ EXPECT_EQ(kSCFG, scfg2->tag());
+
+ // With a different |suffix_server_id|, this will return an empty CachedState.
+ config.AddCanonicalSuffix(".example.com");
+ QuicServerId canonical_server_id3("www.example.com", 443, false);
+ QuicCryptoClientConfig::CachedState* state3 =
+ config.LookupOrCreate(canonical_server_id3);
+ EXPECT_TRUE(state3->IsEmpty());
+ const CryptoHandshakeMessage* const scfg3 = state3->GetServerConfig();
+ EXPECT_FALSE(scfg3);
+}
+
} // namespace test
} // namespace quic