OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 | 565 |
566 mask = std::string(16, '\xFF'); | 566 mask = std::string(16, '\xFF'); |
567 EXPECT_TRUE(bad_subnets.count(mask)); | 567 EXPECT_TRUE(bad_subnets.count(mask)); |
568 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.'))); | 568 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.'))); |
569 | 569 |
570 mask = std::string(12, '\xFF') + "\xF0" + std::string(3, '\x00'); | 570 mask = std::string(12, '\xFF') + "\xF0" + std::string(3, '\x00'); |
571 EXPECT_TRUE(bad_subnets.count(mask)); | 571 EXPECT_TRUE(bad_subnets.count(mask)); |
572 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.'))); | 572 EXPECT_TRUE(bad_subnets[mask].count(std::string(crypto::kSHA256Length, '.'))); |
573 } | 573 } |
574 | 574 |
575 TEST_F(ClientSideDetectionServiceTest, IsBadIpAddress) { | |
576 ClientSideModel model; | |
577 // IPv6 exact match for: 2620:0:1000:3103:21a:a0ff:fe10:786e. | |
578 ClientSideModel::IPSubnet* subnet = model.add_bad_subnet(); | |
579 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
580 "\x26\x20\x00\x00\x10\x00\x31\x03\x02\x1a\xa0\xff\xfe\x10\x78\x6e", 16))); | |
581 subnet->set_size(128); | |
582 | |
583 // IPv6 prefix match for: fe80::21a:a0ff:fe10:786e/64. | |
584 subnet = model.add_bad_subnet(); | |
585 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
586 "\xfe\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16))); | |
587 subnet->set_size(64); | |
588 | |
589 // IPv4 exact match for ::ffff:192.0.2.128. | |
590 subnet = model.add_bad_subnet(); | |
591 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
592 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\x00\x02\x80", 16))); | |
593 subnet->set_size(128); | |
594 | |
595 // IPv4 prefix match (/8) for ::ffff:192.1.1.0. | |
596 subnet = model.add_bad_subnet(); | |
597 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
598 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\x01\x01\x00", 16))); | |
599 subnet->set_size(120); | |
600 | |
601 // IPv4 prefix match (/9) for ::ffff:192.1.122.0. | |
602 subnet = model.add_bad_subnet(); | |
603 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
604 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\x01\x7a\x00", 16))); | |
605 subnet->set_size(119); | |
606 | |
607 // IPv4 prefix match (/15) for ::ffff:192.1.128.0. | |
608 subnet = model.add_bad_subnet(); | |
609 subnet->set_prefix(crypto::SHA256HashString(std::string( | |
610 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\x01\x80\x00", 16))); | |
611 subnet->set_size(113); | |
612 | |
613 csd_service_.reset(ClientSideDetectionService::Create(NULL)); | |
614 ClientSideDetectionService::SetBadSubnets( | |
615 model, &(csd_service_->bad_subnets_)); | |
616 EXPECT_FALSE(csd_service_->IsBadIpAddress("blabla")); | |
617 EXPECT_FALSE(csd_service_->IsBadIpAddress(std::string())); | |
618 | |
619 EXPECT_TRUE(csd_service_->IsBadIpAddress( | |
620 "2620:0:1000:3103:21a:a0ff:fe10:786e")); | |
621 EXPECT_FALSE(csd_service_->IsBadIpAddress( | |
622 "2620:0:1000:3103:21a:a0ff:fe10:786f")); | |
623 | |
624 EXPECT_TRUE(csd_service_->IsBadIpAddress("fe80::21a:a0ff:fe10:786e")); | |
625 EXPECT_TRUE(csd_service_->IsBadIpAddress("fe80::31a:a0ff:fe10:786e")); | |
626 EXPECT_TRUE(csd_service_->IsBadIpAddress("fe80::21a:a0ff:fe10:786f")); | |
627 EXPECT_FALSE(csd_service_->IsBadIpAddress("fe81::21a:a0ff:fe10:786e")); | |
628 | |
629 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.0.2.128")); | |
630 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.0.2.128")); | |
631 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.0.2.129")); | |
632 | |
633 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.1.0")); | |
634 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.1.255")); | |
635 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.1.10")); | |
636 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.1.2")); | |
637 | |
638 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.121.255")); | |
639 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.122.0")); | |
640 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.122.1")); | |
641 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.122.255")); | |
642 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.123.0")); | |
643 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.123.255")); | |
644 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.124.0")); | |
645 | |
646 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.127.255")); | |
647 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.0")); | |
648 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.128.1")); | |
649 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.255")); | |
650 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.0")); | |
651 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.255")); | |
652 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.2.0.0")); | |
mattm
2013/10/25 06:28:12
did all of this get put somewhere in the new impl?
noé
2013/10/28 23:39:26
I did and made them even better :-).
| |
653 } | |
654 | |
655 TEST_F(ClientSideDetectionServiceTest, ModelHasValidHashIds) { | 575 TEST_F(ClientSideDetectionServiceTest, ModelHasValidHashIds) { |
656 ClientSideModel model; | 576 ClientSideModel model; |
657 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); | 577 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); |
658 model.add_hashes("bla"); | 578 model.add_hashes("bla"); |
659 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); | 579 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); |
660 model.add_page_term(0); | 580 model.add_page_term(0); |
661 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); | 581 EXPECT_TRUE(ClientSideDetectionService::ModelHasValidHashIds(model)); |
662 | 582 |
663 model.add_page_term(-1); | 583 model.add_page_term(-1); |
664 EXPECT_FALSE(ClientSideDetectionService::ModelHasValidHashIds(model)); | 584 EXPECT_FALSE(ClientSideDetectionService::ModelHasValidHashIds(model)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 EXPECT_CALL(*service, ScheduleFetchModel(_)) | 669 EXPECT_CALL(*service, ScheduleFetchModel(_)) |
750 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); | 670 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); |
751 EXPECT_CALL(*service, EndFetchModel( | 671 EXPECT_CALL(*service, EndFetchModel( |
752 ClientSideDetectionService::MODEL_NOT_CHANGED)) | 672 ClientSideDetectionService::MODEL_NOT_CHANGED)) |
753 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); | 673 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); |
754 csd_service_->SetEnabledAndRefreshState(true); | 674 csd_service_->SetEnabledAndRefreshState(true); |
755 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); | 675 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); |
756 Mock::VerifyAndClearExpectations(service); | 676 Mock::VerifyAndClearExpectations(service); |
757 } | 677 } |
758 } // namespace safe_browsing | 678 } // namespace safe_browsing |
OLD | NEW |