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

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

Issue 21170004: Store and return urls instead of hosts for the malware IP matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some nit fix on int type Created 7 years, 4 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
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_host.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 (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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // This needs to happen before we call the parent SetUp() function. We use 220 // This needs to happen before we call the parent SetUp() function. We use
221 // a nice mock because other parts of the code are calling IsOffTheRecord. 221 // a nice mock because other parts of the code are calling IsOffTheRecord.
222 mock_profile_ = new NiceMock<MockTestingProfile>(); 222 mock_profile_ = new NiceMock<MockTestingProfile>();
223 return mock_profile_; 223 return mock_profile_;
224 } 224 }
225 225
226 void OnPhishingDetectionDone(const std::string& verdict_str) { 226 void OnPhishingDetectionDone(const std::string& verdict_str) {
227 csd_host_->OnPhishingDetectionDone(verdict_str); 227 csd_host_->OnPhishingDetectionDone(verdict_str);
228 } 228 }
229 229
230 void UpdateIPHostMap(const std::string& ip, const std::string& host) { 230 void UpdateIPUrlMap(const std::string& ip, const std::string& host) {
231 csd_host_->UpdateIPHostMap(ip, host); 231 csd_host_->UpdateIPUrlMap(ip, host);
232 } 232 }
233 233
234 BrowseInfo* GetBrowseInfo() { 234 BrowseInfo* GetBrowseInfo() {
235 return csd_host_->browse_info_.get(); 235 return csd_host_->browse_info_.get();
236 } 236 }
237 237
238 void ExpectPreClassificationChecks(const GURL& url, 238 void ExpectPreClassificationChecks(const GURL& url,
239 const bool* is_private, 239 const bool* is_private,
240 const bool* is_incognito, 240 const bool* is_incognito,
241 const bool* match_csd_whitelist, 241 const bool* match_csd_whitelist,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) 575 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull()))
576 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); 576 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop()));
577 std::vector<GURL> redirect_chain; 577 std::vector<GURL> redirect_chain;
578 redirect_chain.push_back(url); 578 redirect_chain.push_back(url);
579 SetRedirectChain(redirect_chain); 579 SetRedirectChain(redirect_chain);
580 OnPhishingDetectionDone(verdict.SerializeAsString()); 580 OnPhishingDetectionDone(verdict.SerializeAsString());
581 base::MessageLoop::current()->Run(); 581 base::MessageLoop::current()->Run();
582 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 582 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
583 } 583 }
584 584
585 TEST_F(ClientSideDetectionHostTest, UpdateIPHostMap) { 585 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) {
586 BrowseInfo* browse_info = GetBrowseInfo(); 586 BrowseInfo* browse_info = GetBrowseInfo();
587 587
588 // Empty IP or host are skipped 588 // Empty IP or host are skipped
589 UpdateIPHostMap("250.10.10.10", std::string()); 589 UpdateIPUrlMap("250.10.10.10", std::string());
590 ASSERT_EQ(0U, browse_info->ips.size()); 590 ASSERT_EQ(0U, browse_info->ips.size());
591 UpdateIPHostMap(std::string(), "google.com/"); 591 UpdateIPUrlMap(std::string(), "http://google.com/a");
592 ASSERT_EQ(0U, browse_info->ips.size()); 592 ASSERT_EQ(0U, browse_info->ips.size());
593 UpdateIPHostMap(std::string(), std::string()); 593 UpdateIPUrlMap(std::string(), std::string());
594 ASSERT_EQ(0U, browse_info->ips.size()); 594 ASSERT_EQ(0U, browse_info->ips.size());
595 595
596 std::set<std::string> expected_hosts; 596 std::set<std::string> expected_urls;
597 for (int i = 0; i < 20; i++) { 597 for (int i = 0; i < 20; i++) {
598 std::string host = base::StringPrintf("%d.com/", i); 598 std::string url = base::StringPrintf("http://%d.com/", i);
599 expected_hosts.insert(host); 599 expected_urls.insert(url);
600 UpdateIPHostMap("250.10.10.10", host); 600 UpdateIPUrlMap("250.10.10.10", url);
601 } 601 }
602 ASSERT_EQ(1U, browse_info->ips.size()); 602 ASSERT_EQ(1U, browse_info->ips.size());
603 ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); 603 ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size());
604 EXPECT_EQ(expected_hosts, browse_info->ips["250.10.10.10"]); 604 EXPECT_EQ(expected_urls, browse_info->ips["250.10.10.10"]);
605 605
606 // Add more hosts for this ip, it exceeds max limit and won't be added 606 // Add more urls for this ip, it exceeds max limit and won't be added
607 UpdateIPHostMap("250.10.10.10", "21.com/"); 607 UpdateIPUrlMap("250.10.10.10", "http://21.com/");
608 ASSERT_EQ(1U, browse_info->ips.size()); 608 ASSERT_EQ(1U, browse_info->ips.size());
609 ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); 609 ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size());
610 EXPECT_EQ(expected_hosts, browse_info->ips["250.10.10.10"]); 610 EXPECT_EQ(expected_urls, browse_info->ips["250.10.10.10"]);
611 611
612 // Add 199 more IPs 612 // Add 199 more IPs
613 for (int i = 0; i < 199; i++) { 613 for (int i = 0; i < 199; i++) {
614 std::string ip = base::StringPrintf("%d.%d.%d.256", i, i, i); 614 std::string ip = base::StringPrintf("%d.%d.%d.256", i, i, i);
615 expected_hosts.clear(); 615 expected_urls.clear();
616 expected_hosts.insert("test.com/"); 616 expected_urls.insert("test.com/");
617 UpdateIPHostMap(ip, "test.com/"); 617 UpdateIPUrlMap(ip, "test.com/");
618 ASSERT_EQ(1U, browse_info->ips[ip].size()); 618 ASSERT_EQ(1U, browse_info->ips[ip].size());
619 EXPECT_EQ(expected_hosts, browse_info->ips[ip]); 619 EXPECT_EQ(expected_urls, browse_info->ips[ip]);
620 } 620 }
621 ASSERT_EQ(200U, browse_info->ips.size()); 621 ASSERT_EQ(200U, browse_info->ips.size());
622 622
623 // Exceeding max ip limit 200, these won't be added 623 // Exceeding max ip limit 200, these won't be added
624 UpdateIPHostMap("250.250.250.250", "goo.com/"); 624 UpdateIPUrlMap("250.250.250.250", "goo.com/");
625 UpdateIPHostMap("250.250.250.250", "bar.com/"); 625 UpdateIPUrlMap("250.250.250.250", "bar.com/");
626 UpdateIPHostMap("250.250.0.250", "foo.com/"); 626 UpdateIPUrlMap("250.250.0.250", "foo.com/");
627 ASSERT_EQ(200U, browse_info->ips.size()); 627 ASSERT_EQ(200U, browse_info->ips.size());
628 628
629 // Add host to existing IPs succeed 629 // Add url to existing IPs succeed
630 UpdateIPHostMap("100.100.100.256", "more.com/"); 630 UpdateIPUrlMap("100.100.100.256", "more.com/");
631 ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size()); 631 ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size());
632 expected_hosts.clear(); 632 expected_urls.clear();
633 expected_hosts.insert("test.com/"); 633 expected_urls.insert("test.com/");
634 expected_hosts.insert("more.com/"); 634 expected_urls.insert("more.com/");
635 EXPECT_EQ(expected_hosts, browse_info->ips["100.100.100.256"]); 635 EXPECT_EQ(expected_urls, browse_info->ips["100.100.100.256"]);
636 } 636 }
637 637
638 TEST_F(ClientSideDetectionHostTest, 638 TEST_F(ClientSideDetectionHostTest,
639 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { 639 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) {
640 // Case 7: renderer sends a verdict string that isn't phishing and not matches 640 // Case 7: renderer sends a verdict string that isn't phishing and not matches
641 // malware bad IP list 641 // malware bad IP list
642 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 642 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
643 web_contents(), 643 web_contents(),
644 csd_service_.get()); 644 csd_service_.get());
645 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 645 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 910 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
911 EXPECT_EQ(url, resource.url); 911 EXPECT_EQ(url, resource.url);
912 EXPECT_EQ(url, resource.original_url); 912 EXPECT_EQ(url, resource.original_url);
913 resource.callback.Reset(); 913 resource.callback.Reset();
914 msg = process()->sink().GetFirstMessageMatching( 914 msg = process()->sink().GetFirstMessageMatching(
915 SafeBrowsingMsg_StartPhishingDetection::ID); 915 SafeBrowsingMsg_StartPhishingDetection::ID);
916 ASSERT_FALSE(msg); 916 ASSERT_FALSE(msg);
917 } 917 }
918 918
919 } // namespace safe_browsing 919 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698