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_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "net/quic/crypto/proof_verifier.h" | 7 #include "net/quic/crypto/proof_verifier.h" |
8 #include "net/quic/quic_server_id.h" | 8 #include "net/quic/quic_server_id.h" |
9 #include "net/quic/test_tools/mock_random.h" | 9 #include "net/quic/test_tools/mock_random.h" |
10 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 string error; | 156 string error; |
157 QuicCryptoClientConfig config; | 157 QuicCryptoClientConfig config; |
158 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, | 158 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, |
159 config.ProcessServerHello(msg, 0, supported_versions, | 159 config.ProcessServerHello(msg, 0, supported_versions, |
160 &cached, &out_params, &error)); | 160 &cached, &out_params, &error)); |
161 EXPECT_EQ("Downgrade attack detected", error); | 161 EXPECT_EQ("Downgrade attack detected", error); |
162 } | 162 } |
163 | 163 |
164 TEST(QuicCryptoClientConfigTest, InitializeFrom) { | 164 TEST(QuicCryptoClientConfigTest, InitializeFrom) { |
165 QuicCryptoClientConfig config; | 165 QuicCryptoClientConfig config; |
166 QuicServerId canonical_server_id("www.google.com", 80, false, | 166 QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); |
wtc
2014/04/25 18:17:28
Please undo the changes to this unit test. In this
ramant (doing other things)
2014/04/25 18:55:30
Done.
| |
167 PRIVACY_MODE_DISABLED); | 167 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); |
168 QuicCryptoClientConfig::CachedState* state = | |
169 config.LookupOrCreate(canonical_server_id); | |
170 // TODO(rch): Populate other fields of |state|. | 168 // TODO(rch): Populate other fields of |state|. |
171 state->set_source_address_token("TOKEN"); | 169 state->set_source_address_token("TOKEN"); |
172 state->SetProofValid(); | 170 state->SetProofValid(); |
173 | 171 |
174 QuicServerId other_server_id("mail.google.com", 80, false, | 172 QuicServerId other_server_id("mail.google.com", 80, false, |
175 PRIVACY_MODE_DISABLED); | 173 PRIVACY_MODE_DISABLED); |
176 config.InitializeFrom(other_server_id, canonical_server_id, &config); | 174 config.InitializeFrom(other_server_id, server_id, &config); |
177 QuicCryptoClientConfig::CachedState* other = | 175 QuicCryptoClientConfig::CachedState* other = |
178 config.LookupOrCreate(other_server_id); | 176 config.LookupOrCreate(other_server_id); |
179 | 177 |
180 EXPECT_EQ(state->server_config(), other->server_config()); | 178 EXPECT_EQ(state->server_config(), other->server_config()); |
181 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 179 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
182 EXPECT_EQ(state->certs(), other->certs()); | 180 EXPECT_EQ(state->certs(), other->certs()); |
183 EXPECT_EQ(1u, other->generation_counter()); | 181 EXPECT_EQ(1u, other->generation_counter()); |
184 } | 182 } |
185 | 183 |
186 TEST(QuicCryptoClientConfigTest, Canonical) { | 184 TEST(QuicCryptoClientConfigTest, Canonical) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 // TODO(rch): Populate other fields of |state|. | 220 // TODO(rch): Populate other fields of |state|. |
223 state->set_source_address_token("TOKEN"); | 221 state->set_source_address_token("TOKEN"); |
224 | 222 |
225 // Do not set the proof as valid, and check that it is not used | 223 // Do not set the proof as valid, and check that it is not used |
226 // as a canonical entry. | 224 // as a canonical entry. |
227 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); | 225 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); |
228 } | 226 } |
229 | 227 |
230 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { | 228 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { |
231 QuicCryptoClientConfig config; | 229 QuicCryptoClientConfig config; |
232 QuicServerId canonical_server_id("www.google.com", 80, false, | 230 QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); |
233 PRIVACY_MODE_DISABLED); | 231 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); |
234 QuicCryptoClientConfig::CachedState* state = | |
235 config.LookupOrCreate(canonical_server_id); | |
236 // TODO(rch): Populate other fields of |state|. | 232 // TODO(rch): Populate other fields of |state|. |
237 vector<string> certs(1); | 233 vector<string> certs(1); |
238 certs[0] = "Hello Cert"; | 234 certs[0] = "Hello Cert"; |
239 state->SetProof(certs, "signature"); | 235 state->SetProof(certs, "signature"); |
240 state->set_source_address_token("TOKEN"); | 236 state->set_source_address_token("TOKEN"); |
241 state->SetProofValid(); | 237 state->SetProofValid(); |
242 | 238 |
243 // Verify LookupOrCreate returns the same data. | 239 // Verify LookupOrCreate returns the same data. |
244 QuicServerId other_server_id("www.google.com", 80, false, | 240 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(server_id); |
245 PRIVACY_MODE_DISABLED); | |
246 | 241 |
247 QuicCryptoClientConfig::CachedState* other = | 242 EXPECT_EQ(state, other); |
248 config.LookupOrCreate(other_server_id); | |
249 | |
250 EXPECT_TRUE(other->proof_valid()); | 243 EXPECT_TRUE(other->proof_valid()); |
251 EXPECT_EQ(state->server_config(), other->server_config()); | 244 EXPECT_EQ(state->server_config(), other->server_config()); |
252 EXPECT_EQ(state->signature(), other->signature()); | 245 EXPECT_EQ(state->signature(), other->signature()); |
253 EXPECT_EQ(state->certs(), other->certs()); | 246 EXPECT_EQ(state->certs(), other->certs()); |
254 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 247 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
255 EXPECT_EQ(1u, other->generation_counter()); | 248 EXPECT_EQ(1u, other->generation_counter()); |
wtc
2014/04/25 18:17:28
Once we verify |other| and |state| point to the sa
ramant (doing other things)
2014/04/25 18:55:30
Done.
| |
256 | 249 |
257 // Clear the cached state. | 250 // Clear the cached states. |
258 config.ClearCachedStates(); | 251 config.ClearCachedStates(); |
259 | 252 |
260 // Verify LookupOrCreate doesn't have any data. | 253 // Verify LookupOrCreate doesn't have any data. |
261 QuicCryptoClientConfig::CachedState* cleared_cache = | 254 QuicCryptoClientConfig::CachedState* cleared_cache = |
262 config.LookupOrCreate(other_server_id); | 255 config.LookupOrCreate(server_id); |
263 | 256 |
257 EXPECT_EQ(state, cleared_cache); | |
264 EXPECT_FALSE(cleared_cache->proof_valid()); | 258 EXPECT_FALSE(cleared_cache->proof_valid()); |
265 EXPECT_TRUE(cleared_cache->server_config().empty()); | 259 EXPECT_TRUE(cleared_cache->server_config().empty()); |
266 EXPECT_TRUE(cleared_cache->certs().empty()); | 260 EXPECT_TRUE(cleared_cache->certs().empty()); |
267 EXPECT_TRUE(cleared_cache->signature().empty()); | 261 EXPECT_TRUE(cleared_cache->signature().empty()); |
268 EXPECT_LT(1u, cleared_cache->generation_counter()); | 262 EXPECT_EQ(2u, cleared_cache->generation_counter()); |
269 } | 263 } |
270 | 264 |
271 } // namespace test | 265 } // namespace test |
272 } // namespace net | 266 } // namespace net |
OLD | NEW |