| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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/core/crypto/properties_based_quic_server_info.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "net/base/net_errors.h" | |
| 10 #include "net/http/http_server_properties_impl.h" | |
| 11 #include "net/quic/core/quic_server_id.h" | |
| 12 #include "net/test/gtest_util.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace net { | |
| 17 namespace test { | |
| 18 | |
| 19 namespace { | |
| 20 const char kServerConfigA[] = "server_config_a"; | |
| 21 const char kSourceAddressTokenA[] = "source_address_token_a"; | |
| 22 const char kCertSCTA[] = "cert_sct_a"; | |
| 23 const char kChloHashA[] = "chlo_hash_a"; | |
| 24 const char kServerConfigSigA[] = "server_config_sig_a"; | |
| 25 const char kCertA[] = "cert_a"; | |
| 26 const char kCertB[] = "cert_b"; | |
| 27 } // namespace | |
| 28 | |
| 29 class PropertiesBasedQuicServerInfoTest : public ::testing::Test { | |
| 30 protected: | |
| 31 PropertiesBasedQuicServerInfoTest() | |
| 32 : server_id_("www.google.com", 443, PRIVACY_MODE_DISABLED), | |
| 33 server_info_(server_id_, &http_server_properties_) {} | |
| 34 | |
| 35 // Initialize |server_info_| object and persist it. | |
| 36 void InitializeAndPersist() { | |
| 37 server_info_.Start(); | |
| 38 EXPECT_TRUE(server_info_.IsDataReady()); | |
| 39 QuicServerInfo::State* state = server_info_.mutable_state(); | |
| 40 EXPECT_TRUE(state->certs.empty()); | |
| 41 | |
| 42 state->server_config = kServerConfigA; | |
| 43 state->source_address_token = kSourceAddressTokenA; | |
| 44 state->server_config_sig = kServerConfigSigA; | |
| 45 state->cert_sct = kCertSCTA; | |
| 46 state->chlo_hash = kChloHashA; | |
| 47 state->certs.push_back(kCertA); | |
| 48 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 49 server_info_.Persist(); | |
| 50 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 51 EXPECT_TRUE(server_info_.IsDataReady()); | |
| 52 server_info_.OnExternalCacheHit(); | |
| 53 } | |
| 54 | |
| 55 // Verify the data that is persisted in InitializeAndPersist(). | |
| 56 void VerifyInitialData(const QuicServerInfo::State& state) { | |
| 57 EXPECT_EQ(kServerConfigA, state.server_config); | |
| 58 EXPECT_EQ(kSourceAddressTokenA, state.source_address_token); | |
| 59 EXPECT_EQ(kCertSCTA, state.cert_sct); | |
| 60 EXPECT_EQ(kChloHashA, state.chlo_hash); | |
| 61 EXPECT_EQ(kServerConfigSigA, state.server_config_sig); | |
| 62 EXPECT_EQ(kCertA, state.certs[0]); | |
| 63 } | |
| 64 | |
| 65 HttpServerPropertiesImpl http_server_properties_; | |
| 66 QuicServerId server_id_; | |
| 67 PropertiesBasedQuicServerInfo server_info_; | |
| 68 CompletionCallback callback_; | |
| 69 }; | |
| 70 | |
| 71 // Test persisting, reading and verifying and then updating and verifing. | |
| 72 TEST_F(PropertiesBasedQuicServerInfoTest, Update) { | |
| 73 InitializeAndPersist(); | |
| 74 | |
| 75 // Read the persisted data and verify we have read the data correctly. | |
| 76 PropertiesBasedQuicServerInfo server_info1(server_id_, | |
| 77 &http_server_properties_); | |
| 78 server_info1.Start(); | |
| 79 EXPECT_THAT(server_info1.WaitForDataReady(callback_), | |
| 80 IsOk()); // Read the data. | |
| 81 EXPECT_TRUE(server_info1.IsDataReady()); | |
| 82 | |
| 83 // Verify the data. | |
| 84 const QuicServerInfo::State& state1 = server_info1.state(); | |
| 85 EXPECT_EQ(1U, state1.certs.size()); | |
| 86 VerifyInitialData(state1); | |
| 87 | |
| 88 // Update the data, by adding another cert. | |
| 89 QuicServerInfo::State* state2 = server_info1.mutable_state(); | |
| 90 state2->certs.push_back(kCertB); | |
| 91 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 92 server_info1.Persist(); | |
| 93 | |
| 94 // Read the persisted data and verify we have read the data correctly. | |
| 95 PropertiesBasedQuicServerInfo server_info2(server_id_, | |
| 96 &http_server_properties_); | |
| 97 server_info2.Start(); | |
| 98 EXPECT_THAT(server_info2.WaitForDataReady(callback_), | |
| 99 IsOk()); // Read the data. | |
| 100 EXPECT_TRUE(server_info1.IsDataReady()); | |
| 101 | |
| 102 // Verify updated data. | |
| 103 const QuicServerInfo::State& state3 = server_info2.state(); | |
| 104 VerifyInitialData(state3); | |
| 105 EXPECT_EQ(2U, state3.certs.size()); | |
| 106 EXPECT_EQ(kCertB, state3.certs[1]); | |
| 107 } | |
| 108 | |
| 109 } // namespace test | |
| 110 } // namespace net | |
| OLD | NEW |