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 "chrome/browser/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
16 #include "chrome/browser/history/history_backend.h" | 16 #include "chrome/browser/history/history_backend.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/browser_features.h" | |
19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
20 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
21 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
22 #include "content/browser/renderer_host/test_render_view_host.h" | 21 #include "content/browser/renderer_host/test_render_view_host.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/browser/tab_contents/test_tab_contents.h" | 23 #include "content/browser/tab_contents/test_tab_contents.h" |
25 #include "content/common/page_transition_types.h" | 24 #include "content/common/page_transition_types.h" |
26 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
27 #include "crypto/sha2.h" | |
28 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
31 | 29 |
32 using ::testing::Return; | 30 using ::testing::Return; |
33 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
34 | 32 |
35 namespace safe_browsing { | 33 namespace safe_browsing { |
36 namespace { | 34 namespace { |
37 class MockClientSideDetectionService : public ClientSideDetectionService { | 35 class MockClientSideDetectionService : public ClientSideDetectionService { |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 GetFeatureMap(request, &features); | 467 GetFeatureMap(request, &features); |
470 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 468 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
471 features::kSafeBrowsingMaliciousUrl, | 469 features::kSafeBrowsingMaliciousUrl, |
472 "http://www.malware.com/"))); | 470 "http://www.malware.com/"))); |
473 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 471 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
474 features::kSafeBrowsingOriginalUrl, | 472 features::kSafeBrowsingOriginalUrl, |
475 "http://www.good.com/"))); | 473 "http://www.good.com/"))); |
476 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); | 474 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); |
477 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); | 475 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); |
478 } | 476 } |
479 | |
480 TEST_F(BrowserFeatureExtractorTest, URLHashes) { | |
481 ClientPhishingRequest request; | |
482 request.set_url("http://host.com/"); | |
483 request.set_client_score(0.8f); | |
484 | |
485 history_service()->AddPage(GURL("http://host.com/"), | |
486 history::SOURCE_BROWSED); | |
487 contents()->NavigateAndCommit(GURL("http://host.com/")); | |
488 | |
489 EXPECT_TRUE(ExtractFeatures(&request)); | |
490 EXPECT_EQ(crypto::SHA256HashString("host.com/").substr( | |
491 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | |
492 request.suffix_prefix_hash()); | |
493 | |
494 request.set_url("http://www.host.com/path/"); | |
495 history_service()->AddPage(GURL("http://www.host.com/path/"), | |
496 history::SOURCE_BROWSED); | |
497 contents()->NavigateAndCommit(GURL("http://www.host.com/path/")); | |
498 | |
499 EXPECT_TRUE(ExtractFeatures(&request)); | |
500 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/").substr( | |
501 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | |
502 request.suffix_prefix_hash()); | |
503 | |
504 request.set_url("http://user@www.host.com:1111/path/123?args"); | |
505 history_service()->AddPage( | |
506 GURL("http://user@www.host.com:1111/path/123?args"), | |
507 history::SOURCE_BROWSED); | |
508 contents()->NavigateAndCommit( | |
509 GURL("http://user@www.host.com:1111/path/123?args")); | |
510 | |
511 EXPECT_TRUE(ExtractFeatures(&request)); | |
512 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/123").substr( | |
513 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | |
514 request.suffix_prefix_hash()); | |
515 | |
516 // Check that escaping matches the SafeBrowsing specification. | |
517 request.set_url("http://www.host.com/A%21//B"); | |
518 history_service()->AddPage(GURL("http://www.host.com/A%21//B"), | |
519 history::SOURCE_BROWSED); | |
520 contents()->NavigateAndCommit(GURL("http://www.host.com/A%21//B")); | |
521 | |
522 EXPECT_TRUE(ExtractFeatures(&request)); | |
523 EXPECT_EQ(crypto::SHA256HashString("www.host.com/A!/B").substr( | |
524 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | |
525 request.suffix_prefix_hash()); | |
526 } | |
527 } // namespace safe_browsing | 477 } // namespace safe_browsing |
OLD | NEW |