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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service_unittest.cc

Issue 7823004: Convert SHA256_LENGTH from a constant-in-anonymous-enum to a static const. This defines the cons... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 418 }
419 419
420 TEST_F(ClientSideDetectionServiceTest, SetBadSubnets) { 420 TEST_F(ClientSideDetectionServiceTest, SetBadSubnets) {
421 ClientSideModel model; 421 ClientSideModel model;
422 ClientSideDetectionService::BadSubnetMap bad_subnets; 422 ClientSideDetectionService::BadSubnetMap bad_subnets;
423 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets); 423 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets);
424 EXPECT_EQ(0U, bad_subnets.size()); 424 EXPECT_EQ(0U, bad_subnets.size());
425 425
426 // Bad subnets are skipped. 426 // Bad subnets are skipped.
427 ClientSideModel::IPSubnet* subnet = model.add_bad_subnet(); 427 ClientSideModel::IPSubnet* subnet = model.add_bad_subnet();
428 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, '.')); 428 subnet->set_prefix(std::string(crypto::kSHA256Length, '.'));
429 subnet->set_size(130); // Invalid size. 429 subnet->set_size(130); // Invalid size.
430 430
431 subnet = model.add_bad_subnet(); 431 subnet = model.add_bad_subnet();
432 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, '.')); 432 subnet->set_prefix(std::string(crypto::kSHA256Length, '.'));
433 subnet->set_size(-1); // Invalid size. 433 subnet->set_size(-1); // Invalid size.
434 434
435 subnet = model.add_bad_subnet(); 435 subnet = model.add_bad_subnet();
436 subnet->set_prefix(std::string(16, '.')); // Invalid len. 436 subnet->set_prefix(std::string(16, '.')); // Invalid len.
437 subnet->set_size(64); 437 subnet->set_size(64);
438 438
439 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets); 439 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets);
440 EXPECT_EQ(0U, bad_subnets.size()); 440 EXPECT_EQ(0U, bad_subnets.size());
441 441
442 subnet = model.add_bad_subnet(); 442 subnet = model.add_bad_subnet();
443 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, '.')); 443 subnet->set_prefix(std::string(crypto::kSHA256Length, '.'));
444 subnet->set_size(64); 444 subnet->set_size(64);
445 445
446 subnet = model.add_bad_subnet(); 446 subnet = model.add_bad_subnet();
447 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, ',')); 447 subnet->set_prefix(std::string(crypto::kSHA256Length, ','));
448 subnet->set_size(64); 448 subnet->set_size(64);
449 449
450 subnet = model.add_bad_subnet(); 450 subnet = model.add_bad_subnet();
451 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, '.')); 451 subnet->set_prefix(std::string(crypto::kSHA256Length, '.'));
452 subnet->set_size(128); 452 subnet->set_size(128);
453 453
454 subnet = model.add_bad_subnet(); 454 subnet = model.add_bad_subnet();
455 subnet->set_prefix(std::string(crypto::SHA256_LENGTH, '.')); 455 subnet->set_prefix(std::string(crypto::kSHA256Length, '.'));
456 subnet->set_size(100); 456 subnet->set_size(100);
457 457
458 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets); 458 ClientSideDetectionService::SetBadSubnets(model, &bad_subnets);
459 EXPECT_EQ(3U, bad_subnets.size()); 459 EXPECT_EQ(3U, bad_subnets.size());
460 ClientSideDetectionService::BadSubnetMap::const_iterator it; 460 ClientSideDetectionService::BadSubnetMap::const_iterator it;
461 std::string mask = std::string(8, '\xFF') + std::string(8, '\x00'); 461 std::string mask = std::string(8, '\xFF') + std::string(8, '\x00');
462 EXPECT_TRUE(bad_subnets.count(mask)); 462 EXPECT_TRUE(bad_subnets.count(mask));
463 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::SHA256_LENGTH, '.'))); 463 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.')));
464 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::SHA256_LENGTH, ','))); 464 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, ',')));
465 465
466 mask = std::string(16, '\xFF'); 466 mask = std::string(16, '\xFF');
467 EXPECT_TRUE(bad_subnets.count(mask)); 467 EXPECT_TRUE(bad_subnets.count(mask));
468 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::SHA256_LENGTH, '.'))); 468 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.')));
469 469
470 mask = std::string(12, '\xFF') + "\xF0" + std::string(3, '\x00'); 470 mask = std::string(12, '\xFF') + "\xF0" + std::string(3, '\x00');
471 EXPECT_TRUE(bad_subnets.count(mask)); 471 EXPECT_TRUE(bad_subnets.count(mask));
472 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::SHA256_LENGTH, '.'))); 472 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.')));
473 } 473 }
474 474
475 TEST_F(ClientSideDetectionServiceTest, IsBadIpAddress) { 475 TEST_F(ClientSideDetectionServiceTest, IsBadIpAddress) {
476 ClientSideModel model; 476 ClientSideModel model;
477 // IPv6 exact match for: 2620:0:1000:3103:21a:a0ff:fe10:786e. 477 // IPv6 exact match for: 2620:0:1000:3103:21a:a0ff:fe10:786e.
478 ClientSideModel::IPSubnet* subnet = model.add_bad_subnet(); 478 ClientSideModel::IPSubnet* subnet = model.add_bad_subnet();
479 subnet->set_prefix(crypto::SHA256HashString(std::string( 479 subnet->set_prefix(crypto::SHA256HashString(std::string(
480 "\x26\x20\x00\x00\x10\x00\x31\x03\x02\x1a\xa0\xff\xfe\x10\x78\x6e", 16))); 480 "\x26\x20\x00\x00\x10\x00\x31\x03\x02\x1a\xa0\xff\xfe\x10\x78\x6e", 16)));
481 subnet->set_size(128); 481 subnet->set_size(128);
482 482
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 << "Non-model feature " << i; 745 << "Non-model feature " << i;
746 } 746 }
747 747
748 // Also check the serialized forms in case there's a field that we forget 748 // Also check the serialized forms in case there's a field that we forget
749 // to add above. 749 // to add above.
750 EXPECT_EQ(expected.SerializeAsString(), 750 EXPECT_EQ(expected.SerializeAsString(),
751 sanitized_request.SerializeAsString()); 751 sanitized_request.SerializeAsString());
752 } 752 }
753 753
754 } // namespace safe_browsing 754 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698