Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 ClientPhishingResponse response; | 344 ClientPhishingResponse response; |
| 345 response.set_phishy(true); | 345 response.set_phishy(true); |
| 346 SetClientReportPhishingResponse(response.SerializeAsString(), | 346 SetClientReportPhishingResponse(response.SerializeAsString(), |
| 347 true /* success */); | 347 true /* success */); |
| 348 EXPECT_TRUE(SendClientReportPhishingRequest(url, score)); | 348 EXPECT_TRUE(SendClientReportPhishingRequest(url, score)); |
| 349 | 349 |
| 350 // This request will fail | 350 // This request will fail |
| 351 GURL second_url("http://b.com/"); | 351 GURL second_url("http://b.com/"); |
| 352 response.set_phishy(false); | 352 response.set_phishy(false); |
| 353 SetClientReportPhishingResponse(response.SerializeAsString(), | 353 SetClientReportPhishingResponse(response.SerializeAsString(), |
| 354 false /* success*/); | 354 false /* success */); |
| 355 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score)); | 355 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score)); |
| 356 | 356 |
| 357 // This is a false positive. | |
| 358 response.set_phishy(true); | |
| 359 response.add_whitelist_expression("c.com/a.html"); | |
| 360 SetClientReportPhishingResponse(response.SerializeAsString(), | |
| 361 true /* success */); | |
| 362 GURL third_url("http://c.com/"); | |
| 363 EXPECT_FALSE(SendClientReportPhishingRequest(third_url, score)); | |
| 364 | |
| 357 base::Time after = base::Time::Now(); | 365 base::Time after = base::Time::Now(); |
| 358 | 366 |
| 359 // Check that we have recorded all 3 requests within the correct time range. | 367 // Check that we have recorded all 4 requests within the correct time range. |
| 360 std::queue<base::Time>& report_times = GetPhishingReportTimes(); | 368 std::queue<base::Time>& report_times = GetPhishingReportTimes(); |
| 361 EXPECT_EQ(3U, report_times.size()); | 369 EXPECT_EQ(4U, report_times.size()); |
| 362 while (!report_times.empty()) { | 370 while (!report_times.empty()) { |
| 363 base::Time time = report_times.back(); | 371 base::Time time = report_times.back(); |
| 364 report_times.pop(); | 372 report_times.pop(); |
| 365 EXPECT_LE(before, time); | 373 EXPECT_LE(before, time); |
| 366 EXPECT_GE(after, time); | 374 EXPECT_GE(after, time); |
| 367 } | 375 } |
| 368 | 376 |
| 369 // Only the first url should be in the cache. | 377 // Only the first url should be in the cache. |
| 370 bool is_phishing; | 378 bool is_phishing; |
| 371 EXPECT_TRUE(csd_service_->IsInCache(url)); | 379 EXPECT_TRUE(csd_service_->IsInCache(url)); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 sanitized_request.non_model_feature_map(i).value()) | 752 sanitized_request.non_model_feature_map(i).value()) |
| 745 << "Non-model feature " << i; | 753 << "Non-model feature " << i; |
| 746 } | 754 } |
| 747 | 755 |
| 748 // Also check the serialized forms in case there's a field that we forget | 756 // Also check the serialized forms in case there's a field that we forget |
| 749 // to add above. | 757 // to add above. |
| 750 EXPECT_EQ(expected.SerializeAsString(), | 758 EXPECT_EQ(expected.SerializeAsString(), |
| 751 sanitized_request.SerializeAsString()); | 759 sanitized_request.SerializeAsString()); |
| 752 } | 760 } |
| 753 | 761 |
| 762 TEST_F(ClientSideDetectionServiceTest, IsFalsePositiveResponse) { | |
| 763 GURL url("http://www.google.com/"); | |
| 764 ClientPhishingResponse response; | |
| 765 | |
| 766 // If the response is not phishing is should never be a false positive. | |
| 767 response.set_phishy(false); | |
| 768 response.add_whitelist_expression("www.google.com/"); | |
| 769 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 770 url, response)); | |
| 771 | |
| 772 // If there are no entries in the whitelist it should always return false. | |
| 773 response.clear_whitelist_expression(); | |
| 774 response.set_phishy(true); | |
| 775 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 776 url, response)); | |
| 777 | |
| 778 // If the URL doesn't match any whitelist entries it whould return false. | |
| 779 response.add_whitelist_expression("www.yahoo.com/"); | |
| 780 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 781 url, response)); | |
| 782 | |
| 783 // If the URL matches the whitelist it should return true. | |
| 784 response.add_whitelist_expression("google.com/"); | |
| 785 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 786 url, response)); | |
| 787 | |
| 788 // If an entry in the whitelist matches the URL it should return true. | |
| 789 response.clear_whitelist_expression(); | |
| 790 response.add_whitelist_expression("www.google.com/a/b.html"); | |
| 791 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 792 url, response)); | |
|
mattm
2011/08/30 02:23:09
The whitelist matching against the URL seems a bit
noelutz
2011/08/30 16:45:12
This whitelist works in two ways. I.e., if we 'cl
| |
| 793 } | |
| 754 } // namespace safe_browsing | 794 } // namespace safe_browsing |
| OLD | NEW |