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

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 574283006: Fix dictionary domain check problem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated comments and forbid dictionary domains with "."s. Created 6 years, 2 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
« net/base/sdch_manager.cc ('K') | « net/base/sdch_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <limits.h> 5 #include <limits.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 271
272 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { 272 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) {
273 std::string dictionary_domain("x.y.z.google.com"); 273 std::string dictionary_domain("x.y.z.google.com");
274 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 274 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
275 275
276 // Fail the HD with D being the domain and H having a dot requirement. 276 // Fail the HD with D being the domain and H having a dot requirement.
277 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 277 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
278 GURL("http://w.x.y.z.google.com"))); 278 GURL("http://w.x.y.z.google.com")));
279 } 279 }
280 280
281 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) {
282 std::string dictionary_domain("x.y.z.google.com");
283 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
284
285 // Fail the HD with D being the domain and H having a dot requirement.
286 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
287 GURL("http://w.x.y.z.google.com.")));
288 }
289
281 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { 290 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) {
282 // Make sure that a prefix that matches the domain postfix won't confuse 291 // Make sure that a prefix that matches the domain postfix won't confuse
283 // the validation checks. 292 // the validation checks.
284 std::string dictionary_domain("www.google.com"); 293 std::string dictionary_domain("www.google.com");
285 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 294 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
286 295
287 // Fail the HD with D being the domain and H having a dot requirement. 296 // Fail the HD with D being the domain and H having a dot requirement.
288 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 297 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
289 GURL("http://www.google.com.www.google.com"))); 298 GURL("http://www.google.com.www.google.com")));
290 } 299 }
291 300
292 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { 301 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) {
293 // Make sure that a prefix that matches the domain postfix won't confuse 302 // Make sure that a prefix that matches the domain postfix won't confuse
294 // the validation checks. 303 // the validation checks.
295 std::string dictionary_domain(".google.com"); 304 std::string dictionary_domain(".google.com");
296 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 305 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
297 306
298 // Verify that a leading dot in the domain is acceptable, as long as the host 307 // Verify that a leading dot in the domain is acceptable, as long as the host
299 // name does not contain any dots preceding the matched domain name. 308 // name does not contain any dots preceding the matched domain name.
300 EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))) ; 309 EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))) ;
301 } 310 }
302 311
312 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) {
313 // Make sure that a prefix that matches the domain postfix won't confuse
314 // the validation checks.
315 std::string dictionary_domain(".google.com");
316 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
317
318 // Verify that a leading dot in the domain is acceptable, as long as the host
319 // name does not contain any dots preceding the matched domain name.
320 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
321 GURL("http://www.google.com.")));
322 }
323
324 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) {
325 // Make sure that a prefix that matches the domain postfix won't confuse
326 // the validation checks.
327 std::string dictionary_domain(".google.com");
328 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
329
330 // Verify that a leading dot in the domain does not affect the name containing
331 // dots failure.
332 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
333 GURL("http://www.subdomain.google.com")));
334 }
335
336 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionaryFQDN) {
337 // Make sure that a prefix that matches the domain postfix won't confuse
338 // the validation checks.
339 std::string dictionary_domain(".google.com");
340 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
341
342 // Verify that a FQDN doesn't affect . in hostname checking.
343 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
344 GURL("http://www.subdomain.google.com.")));
345 }
346
347 TEST_F(SdchManagerTest, CannotSetTrailingDotDomainDictionary) {
348 std::string dictionary_domain("google.com.");
349 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
350
351 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
352 GURL("http://www.google.com")));
353 }
354
303 // Make sure the order of the tests is not helping us or confusing things. 355 // Make sure the order of the tests is not helping us or confusing things.
304 // See test CanSetExactMatchDictionary above for first try. 356 // See test CanSetExactMatchDictionary above for first try.
305 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { 357 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) {
306 std::string dictionary_domain("x.y.z.google.com"); 358 std::string dictionary_domain("x.y.z.google.com");
307 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 359 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
308 360
309 // Perfect match should *STILL* work. 361 // Perfect match should *STILL* work.
310 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 362 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
311 GURL("http://" + dictionary_domain))); 363 GURL("http://" + dictionary_domain)));
312 } 364 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 sdch_manager()->GetVcdiffDictionary( 555 sdch_manager()->GetVcdiffDictionary(
504 server_hash, 556 server_hash,
505 GURL("http://" + dictionary_domain + "/random_url"), 557 GURL("http://" + dictionary_domain + "/random_url"),
506 &dictionary); 558 &dictionary);
507 EXPECT_FALSE(dictionary.get()); 559 EXPECT_FALSE(dictionary.get());
508 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 560 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
509 } 561 }
510 562
511 } // namespace net 563 } // namespace net
512 564
OLDNEW
« net/base/sdch_manager.cc ('K') | « net/base/sdch_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698