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

Side by Side Diff: net/tools/quic/stateless_rejector_test.cc

Issue 2671333004: Convert class-full-of-statics CryptoTestUtils into a namespace (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/tools/quic/stateless_rejector.h" 5 #include "net/tools/quic/stateless_rejector.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "net/quic/core/crypto/crypto_handshake_message.h" 10 #include "net/quic/core/crypto/crypto_handshake_message.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 param.flags = flags; 67 param.flags = flags;
68 params.push_back(param); 68 params.push_back(param);
69 } 69 }
70 } 70 }
71 return params; 71 return params;
72 } 72 }
73 73
74 class StatelessRejectorTest : public ::testing::TestWithParam<TestParams> { 74 class StatelessRejectorTest : public ::testing::TestWithParam<TestParams> {
75 public: 75 public:
76 StatelessRejectorTest() 76 StatelessRejectorTest()
77 : proof_source_(CryptoTestUtils::ProofSourceForTesting()), 77 : proof_source_(crypto_test_utils::ProofSourceForTesting()),
78 config_(QuicCryptoServerConfig::TESTING, 78 config_(QuicCryptoServerConfig::TESTING,
79 QuicRandom::GetInstance(), 79 QuicRandom::GetInstance(),
80 CryptoTestUtils::ProofSourceForTesting()), 80 crypto_test_utils::ProofSourceForTesting()),
81 config_peer_(&config_), 81 config_peer_(&config_),
82 compressed_certs_cache_( 82 compressed_certs_cache_(
83 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), 83 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize),
84 rejector_(QuicMakeUnique<StatelessRejector>( 84 rejector_(QuicMakeUnique<StatelessRejector>(
85 GetParam().version, 85 GetParam().version,
86 AllSupportedVersions(), 86 AllSupportedVersions(),
87 &config_, 87 &config_,
88 &compressed_certs_cache_, 88 &compressed_certs_cache_,
89 &clock_, 89 &clock_,
90 QuicRandom::GetInstance(), 90 QuicRandom::GetInstance(),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 string stk_hex_; 163 string stk_hex_;
164 }; 164 };
165 165
166 INSTANTIATE_TEST_CASE_P(Flags, 166 INSTANTIATE_TEST_CASE_P(Flags,
167 StatelessRejectorTest, 167 StatelessRejectorTest,
168 ::testing::ValuesIn(GetTestParams()), 168 ::testing::ValuesIn(GetTestParams()),
169 TestParamToString); 169 TestParamToString);
170 170
171 TEST_P(StatelessRejectorTest, InvalidChlo) { 171 TEST_P(StatelessRejectorTest, InvalidChlo) {
172 // clang-format off 172 // clang-format off
173 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 173 const CryptoHandshakeMessage client_hello = crypto_test_utils::Message(
174 "CHLO", 174 "CHLO",
175 "PDMD", "X509", 175 "PDMD", "X509",
176 "COPT", "SREJ", 176 "COPT", "SREJ",
177 nullptr); 177 nullptr);
178 // clang-format on 178 // clang-format on
179 rejector_->OnChlo(GetParam().version, kConnectionId, 179 rejector_->OnChlo(GetParam().version, kConnectionId,
180 kServerDesignateConnectionId, client_hello); 180 kServerDesignateConnectionId, client_hello);
181 181
182 if (GetParam().flags != ENABLED) { 182 if (GetParam().flags != ENABLED) {
183 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_->state()); 183 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_->state());
184 return; 184 return;
185 } 185 }
186 186
187 // The StatelessRejector is undecided - proceed with async processing 187 // The StatelessRejector is undecided - proceed with async processing
188 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state()); 188 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state());
189 StatelessRejector::Process(std::move(rejector_), 189 StatelessRejector::Process(std::move(rejector_),
190 QuicMakeUnique<ProcessDoneCallback>(this)); 190 QuicMakeUnique<ProcessDoneCallback>(this));
191 191
192 EXPECT_EQ(StatelessRejector::FAILED, rejector_->state()); 192 EXPECT_EQ(StatelessRejector::FAILED, rejector_->state());
193 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, rejector_->error()); 193 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, rejector_->error());
194 } 194 }
195 195
196 TEST_P(StatelessRejectorTest, ValidChloWithoutSrejSupport) { 196 TEST_P(StatelessRejectorTest, ValidChloWithoutSrejSupport) {
197 // clang-format off 197 // clang-format off
198 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 198 const CryptoHandshakeMessage client_hello = crypto_test_utils::Message(
199 "CHLO", 199 "CHLO",
200 "PDMD", "X509", 200 "PDMD", "X509",
201 "AEAD", "AESG", 201 "AEAD", "AESG",
202 "KEXS", "C255", 202 "KEXS", "C255",
203 "PUBS", pubs_hex_.c_str(), 203 "PUBS", pubs_hex_.c_str(),
204 "NONC", nonc_hex_.c_str(), 204 "NONC", nonc_hex_.c_str(),
205 "VER\0", ver_hex_.c_str(), 205 "VER\0", ver_hex_.c_str(),
206 "$padding", static_cast<int>(kClientHelloMinimumSize), 206 "$padding", static_cast<int>(kClientHelloMinimumSize),
207 nullptr); 207 nullptr);
208 // clang-format on 208 // clang-format on
209 209
210 rejector_->OnChlo(GetParam().version, kConnectionId, 210 rejector_->OnChlo(GetParam().version, kConnectionId,
211 kServerDesignateConnectionId, client_hello); 211 kServerDesignateConnectionId, client_hello);
212 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_->state()); 212 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_->state());
213 } 213 }
214 214
215 TEST_P(StatelessRejectorTest, RejectChlo) { 215 TEST_P(StatelessRejectorTest, RejectChlo) {
216 // clang-format off 216 // clang-format off
217 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 217 const CryptoHandshakeMessage client_hello = crypto_test_utils::Message(
218 "CHLO", 218 "CHLO",
219 "PDMD", "X509", 219 "PDMD", "X509",
220 "AEAD", "AESG", 220 "AEAD", "AESG",
221 "KEXS", "C255", 221 "KEXS", "C255",
222 "COPT", "SREJ", 222 "COPT", "SREJ",
223 "SCID", scid_hex_.c_str(), 223 "SCID", scid_hex_.c_str(),
224 "PUBS", pubs_hex_.c_str(), 224 "PUBS", pubs_hex_.c_str(),
225 "NONC", nonc_hex_.c_str(), 225 "NONC", nonc_hex_.c_str(),
226 "#004b5453", stk_hex_.c_str(), 226 "#004b5453", stk_hex_.c_str(),
227 "VER\0", ver_hex_.c_str(), 227 "VER\0", ver_hex_.c_str(),
(...skipping 19 matching lines...) Expand all
247 const uint32_t* reject_reasons; 247 const uint32_t* reject_reasons;
248 size_t num_reject_reasons; 248 size_t num_reject_reasons;
249 EXPECT_EQ(QUIC_NO_ERROR, 249 EXPECT_EQ(QUIC_NO_ERROR,
250 reply.GetTaglist(kRREJ, &reject_reasons, &num_reject_reasons)); 250 reply.GetTaglist(kRREJ, &reject_reasons, &num_reject_reasons));
251 EXPECT_EQ(1u, num_reject_reasons); 251 EXPECT_EQ(1u, num_reject_reasons);
252 EXPECT_EQ(INVALID_EXPECTED_LEAF_CERTIFICATE, 252 EXPECT_EQ(INVALID_EXPECTED_LEAF_CERTIFICATE,
253 static_cast<HandshakeFailureReason>(reject_reasons[0])); 253 static_cast<HandshakeFailureReason>(reject_reasons[0]));
254 } 254 }
255 255
256 TEST_P(StatelessRejectorTest, AcceptChlo) { 256 TEST_P(StatelessRejectorTest, AcceptChlo) {
257 const uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); 257 const uint64_t xlct = crypto_test_utils::LeafCertHashForTesting();
258 const string xlct_hex = 258 const string xlct_hex =
259 "#" + QuicTextUtils::HexEncode(reinterpret_cast<const char*>(&xlct), 259 "#" + QuicTextUtils::HexEncode(reinterpret_cast<const char*>(&xlct),
260 sizeof(xlct)); 260 sizeof(xlct));
261 // clang-format off 261 // clang-format off
262 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 262 const CryptoHandshakeMessage client_hello = crypto_test_utils::Message(
263 "CHLO", 263 "CHLO",
264 "PDMD", "X509", 264 "PDMD", "X509",
265 "AEAD", "AESG", 265 "AEAD", "AESG",
266 "KEXS", "C255", 266 "KEXS", "C255",
267 "COPT", "SREJ", 267 "COPT", "SREJ",
268 "SCID", scid_hex_.c_str(), 268 "SCID", scid_hex_.c_str(),
269 "PUBS", pubs_hex_.c_str(), 269 "PUBS", pubs_hex_.c_str(),
270 "NONC", nonc_hex_.c_str(), 270 "NONC", nonc_hex_.c_str(),
271 "#004b5453", stk_hex_.c_str(), 271 "#004b5453", stk_hex_.c_str(),
272 "VER\0", ver_hex_.c_str(), 272 "VER\0", ver_hex_.c_str(),
(...skipping 13 matching lines...) Expand all
286 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state()); 286 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state());
287 StatelessRejector::Process(std::move(rejector_), 287 StatelessRejector::Process(std::move(rejector_),
288 QuicMakeUnique<ProcessDoneCallback>(this)); 288 QuicMakeUnique<ProcessDoneCallback>(this));
289 289
290 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_->state()); 290 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_->state());
291 } 291 }
292 292
293 } // namespace 293 } // namespace
294 } // namespace test 294 } // namespace test
295 } // namespace net 295 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_spdy_client_stream_test.cc ('k') | net/url_request/url_request_quic_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698