Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: net/quic/crypto/quic_crypto_client_config_test.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 EXPECT_EQ(state.certs(), other.certs()); 52 EXPECT_EQ(state.certs(), other.certs());
53 EXPECT_EQ(1u, other.generation_counter()); 53 EXPECT_EQ(1u, other.generation_counter());
54 } 54 }
55 55
56 TEST(QuicCryptoClientConfigTest, InchoateChlo) { 56 TEST(QuicCryptoClientConfigTest, InchoateChlo) {
57 QuicCryptoClientConfig::CachedState state; 57 QuicCryptoClientConfig::CachedState state;
58 QuicCryptoClientConfig config; 58 QuicCryptoClientConfig config;
59 QuicCryptoNegotiatedParameters params; 59 QuicCryptoNegotiatedParameters params;
60 CryptoHandshakeMessage msg; 60 CryptoHandshakeMessage msg;
61 QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); 61 QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED);
62 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, 62 config.FillInchoateClientHello(
63 &params, &msg); 63 server_id, QuicVersionMax(), &state, &params, &msg);
64 64
65 QuicTag cver; 65 QuicTag cver;
66 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); 66 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver));
67 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); 67 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver);
68 } 68 }
69 69
70 TEST(QuicCryptoClientConfigTest, PreferAesGcm) { 70 TEST(QuicCryptoClientConfigTest, PreferAesGcm) {
71 QuicCryptoClientConfig config; 71 QuicCryptoClientConfig config;
72 config.SetDefaults(); 72 config.SetDefaults();
73 if (config.aead.size() > 1) 73 if (config.aead.size() > 1)
74 EXPECT_NE(kAESG, config.aead[0]); 74 EXPECT_NE(kAESG, config.aead[0]);
75 config.PreferAesGcm(); 75 config.PreferAesGcm();
76 EXPECT_EQ(kAESG, config.aead[0]); 76 EXPECT_EQ(kAESG, config.aead[0]);
77 } 77 }
78 78
79 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { 79 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) {
80 QuicCryptoClientConfig::CachedState state; 80 QuicCryptoClientConfig::CachedState state;
81 QuicCryptoClientConfig config; 81 QuicCryptoClientConfig config;
82 QuicCryptoNegotiatedParameters params; 82 QuicCryptoNegotiatedParameters params;
83 CryptoHandshakeMessage msg; 83 CryptoHandshakeMessage msg;
84 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 84 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED);
85 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, 85 config.FillInchoateClientHello(
86 &params, &msg); 86 server_id, QuicVersionMax(), &state, &params, &msg);
87 87
88 QuicTag pdmd; 88 QuicTag pdmd;
89 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); 89 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd));
90 EXPECT_EQ(kX509, pdmd); 90 EXPECT_EQ(kX509, pdmd);
91 } 91 }
92 92
93 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { 93 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) {
94 QuicCryptoClientConfig::CachedState state; 94 QuicCryptoClientConfig::CachedState state;
95 QuicCryptoClientConfig config; 95 QuicCryptoClientConfig config;
96 config.DisableEcdsa(); 96 config.DisableEcdsa();
97 QuicCryptoNegotiatedParameters params; 97 QuicCryptoNegotiatedParameters params;
98 CryptoHandshakeMessage msg; 98 CryptoHandshakeMessage msg;
99 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 99 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED);
100 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, 100 config.FillInchoateClientHello(
101 &params, &msg); 101 server_id, QuicVersionMax(), &state, &params, &msg);
102 102
103 QuicTag pdmd; 103 QuicTag pdmd;
104 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); 104 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd));
105 EXPECT_EQ(kX59R, pdmd); 105 EXPECT_EQ(kX59R, pdmd);
106 } 106 }
107 107
108 TEST(QuicCryptoClientConfigTest, FillClientHello) { 108 TEST(QuicCryptoClientConfigTest, FillClientHello) {
109 QuicCryptoClientConfig::CachedState state; 109 QuicCryptoClientConfig::CachedState state;
110 QuicCryptoClientConfig config; 110 QuicCryptoClientConfig config;
111 QuicCryptoNegotiatedParameters params; 111 QuicCryptoNegotiatedParameters params;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 CryptoHandshakeMessage msg; 150 CryptoHandshakeMessage msg;
151 msg.set_tag(kSHLO); 151 msg.set_tag(kSHLO);
152 msg.SetVector(kVER, supported_version_tags); 152 msg.SetVector(kVER, supported_version_tags);
153 153
154 QuicCryptoClientConfig::CachedState cached; 154 QuicCryptoClientConfig::CachedState cached;
155 QuicCryptoNegotiatedParameters out_params; 155 QuicCryptoNegotiatedParameters out_params;
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(
160 &cached, &out_params, &error)); 160 msg, 0, supported_versions, &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 canonical_server_id(
167 PRIVACY_MODE_DISABLED); 167 "www.google.com", 80, false, PRIVACY_MODE_DISABLED);
168 QuicCryptoClientConfig::CachedState* state = 168 QuicCryptoClientConfig::CachedState* state =
169 config.LookupOrCreate(canonical_server_id); 169 config.LookupOrCreate(canonical_server_id);
170 // TODO(rch): Populate other fields of |state|. 170 // TODO(rch): Populate other fields of |state|.
171 state->set_source_address_token("TOKEN"); 171 state->set_source_address_token("TOKEN");
172 state->SetProofValid(); 172 state->SetProofValid();
173 173
174 QuicServerId other_server_id("mail.google.com", 80, false, 174 QuicServerId other_server_id(
175 PRIVACY_MODE_DISABLED); 175 "mail.google.com", 80, false, PRIVACY_MODE_DISABLED);
176 config.InitializeFrom(other_server_id, canonical_server_id, &config); 176 config.InitializeFrom(other_server_id, canonical_server_id, &config);
177 QuicCryptoClientConfig::CachedState* other = 177 QuicCryptoClientConfig::CachedState* other =
178 config.LookupOrCreate(other_server_id); 178 config.LookupOrCreate(other_server_id);
179 179
180 EXPECT_EQ(state->server_config(), other->server_config()); 180 EXPECT_EQ(state->server_config(), other->server_config());
181 EXPECT_EQ(state->source_address_token(), other->source_address_token()); 181 EXPECT_EQ(state->source_address_token(), other->source_address_token());
182 EXPECT_EQ(state->certs(), other->certs()); 182 EXPECT_EQ(state->certs(), other->certs());
183 EXPECT_EQ(1u, other->generation_counter()); 183 EXPECT_EQ(1u, other->generation_counter());
184 } 184 }
185 185
186 TEST(QuicCryptoClientConfigTest, Canonical) { 186 TEST(QuicCryptoClientConfigTest, Canonical) {
187 QuicCryptoClientConfig config; 187 QuicCryptoClientConfig config;
188 config.AddCanonicalSuffix(".google.com"); 188 config.AddCanonicalSuffix(".google.com");
189 QuicServerId canonical_id1("www.google.com", 80, false, 189 QuicServerId canonical_id1(
190 PRIVACY_MODE_DISABLED); 190 "www.google.com", 80, false, PRIVACY_MODE_DISABLED);
191 QuicServerId canonical_id2("mail.google.com", 80, false, 191 QuicServerId canonical_id2(
192 PRIVACY_MODE_DISABLED); 192 "mail.google.com", 80, false, PRIVACY_MODE_DISABLED);
193 QuicCryptoClientConfig::CachedState* state = 193 QuicCryptoClientConfig::CachedState* state =
194 config.LookupOrCreate(canonical_id1); 194 config.LookupOrCreate(canonical_id1);
195 // TODO(rch): Populate other fields of |state|. 195 // TODO(rch): Populate other fields of |state|.
196 state->set_source_address_token("TOKEN"); 196 state->set_source_address_token("TOKEN");
197 state->SetProofValid(); 197 state->SetProofValid();
198 198
199 QuicCryptoClientConfig::CachedState* other = 199 QuicCryptoClientConfig::CachedState* other =
200 config.LookupOrCreate(canonical_id2); 200 config.LookupOrCreate(canonical_id2);
201 201
202 EXPECT_TRUE(state->IsEmpty()); 202 EXPECT_TRUE(state->IsEmpty());
203 EXPECT_EQ(state->server_config(), other->server_config()); 203 EXPECT_EQ(state->server_config(), other->server_config());
204 EXPECT_EQ(state->source_address_token(), other->source_address_token()); 204 EXPECT_EQ(state->source_address_token(), other->source_address_token());
205 EXPECT_EQ(state->certs(), other->certs()); 205 EXPECT_EQ(state->certs(), other->certs());
206 EXPECT_EQ(1u, other->generation_counter()); 206 EXPECT_EQ(1u, other->generation_counter());
207 207
208 QuicServerId different_id("mail.google.org", 80, false, 208 QuicServerId different_id(
209 PRIVACY_MODE_DISABLED); 209 "mail.google.org", 80, false, PRIVACY_MODE_DISABLED);
210 EXPECT_TRUE(config.LookupOrCreate(different_id)->IsEmpty()); 210 EXPECT_TRUE(config.LookupOrCreate(different_id)->IsEmpty());
211 } 211 }
212 212
213 TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) { 213 TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) {
214 QuicCryptoClientConfig config; 214 QuicCryptoClientConfig config;
215 config.AddCanonicalSuffix(".google.com"); 215 config.AddCanonicalSuffix(".google.com");
216 QuicServerId canonical_id1("www.google.com", 80, false, 216 QuicServerId canonical_id1(
217 PRIVACY_MODE_DISABLED); 217 "www.google.com", 80, false, PRIVACY_MODE_DISABLED);
218 QuicServerId canonical_id2("mail.google.com", 80, false, 218 QuicServerId canonical_id2(
219 PRIVACY_MODE_DISABLED); 219 "mail.google.com", 80, false, PRIVACY_MODE_DISABLED);
220 QuicCryptoClientConfig::CachedState* state = 220 QuicCryptoClientConfig::CachedState* state =
221 config.LookupOrCreate(canonical_id1); 221 config.LookupOrCreate(canonical_id1);
222 // TODO(rch): Populate other fields of |state|. 222 // TODO(rch): Populate other fields of |state|.
223 state->set_source_address_token("TOKEN"); 223 state->set_source_address_token("TOKEN");
224 224
225 // Do not set the proof as valid, and check that it is not used 225 // Do not set the proof as valid, and check that it is not used
226 // as a canonical entry. 226 // as a canonical entry.
227 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); 227 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty());
228 } 228 }
229 229
(...skipping 25 matching lines...) Expand all
255 EXPECT_EQ(state, cleared_cache); 255 EXPECT_EQ(state, cleared_cache);
256 EXPECT_FALSE(cleared_cache->proof_valid()); 256 EXPECT_FALSE(cleared_cache->proof_valid());
257 EXPECT_TRUE(cleared_cache->server_config().empty()); 257 EXPECT_TRUE(cleared_cache->server_config().empty());
258 EXPECT_TRUE(cleared_cache->certs().empty()); 258 EXPECT_TRUE(cleared_cache->certs().empty());
259 EXPECT_TRUE(cleared_cache->signature().empty()); 259 EXPECT_TRUE(cleared_cache->signature().empty());
260 EXPECT_EQ(2u, cleared_cache->generation_counter()); 260 EXPECT_EQ(2u, cleared_cache->generation_counter());
261 } 261 }
262 262
263 } // namespace test 263 } // namespace test
264 } // namespace net 264 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698