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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
7 // service. | 7 // service. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 #error This test requires SAFE_BROWSING_DB_LOCAL. | 63 #error This test requires SAFE_BROWSING_DB_LOCAL. |
64 #endif | 64 #endif |
65 | 65 |
66 using content::BrowserThread; | 66 using content::BrowserThread; |
67 using content::InterstitialPage; | 67 using content::InterstitialPage; |
68 using content::WebContents; | 68 using content::WebContents; |
69 using ::testing::_; | 69 using ::testing::_; |
70 using ::testing::Mock; | 70 using ::testing::Mock; |
71 using ::testing::StrictMock; | 71 using ::testing::StrictMock; |
72 | 72 |
| 73 namespace safe_browsing { |
| 74 |
73 namespace { | 75 namespace { |
74 | 76 |
75 void InvokeFullHashCallback( | 77 void InvokeFullHashCallback( |
76 SafeBrowsingProtocolManager::FullHashCallback callback, | 78 SafeBrowsingProtocolManager::FullHashCallback callback, |
77 const std::vector<SBFullHashResult>& result) { | 79 const std::vector<SBFullHashResult>& result) { |
78 callback.Run(result, base::TimeDelta::FromMinutes(45)); | 80 callback.Run(result, base::TimeDelta::FromMinutes(45)); |
79 } | 81 } |
80 | 82 |
81 class FakeSafeBrowsingService : public SafeBrowsingService { | 83 class FakeSafeBrowsingService : public SafeBrowsingService { |
82 public: | 84 public: |
(...skipping 26 matching lines...) Expand all Loading... |
109 | 111 |
110 SafeBrowsingService* CreateSafeBrowsingService() override { | 112 SafeBrowsingService* CreateSafeBrowsingService() override { |
111 return new FakeSafeBrowsingService(url_prefix_); | 113 return new FakeSafeBrowsingService(url_prefix_); |
112 } | 114 } |
113 | 115 |
114 private: | 116 private: |
115 std::string url_prefix_; | 117 std::string url_prefix_; |
116 }; | 118 }; |
117 | 119 |
118 // A SafeBrowingDatabase class that allows us to inject the malicious URLs. | 120 // A SafeBrowingDatabase class that allows us to inject the malicious URLs. |
119 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase { | 121 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase { |
120 public: | 122 public: |
121 TestSafeBrowsingDatabase() {} | 123 TestSafeBrowsingDatabase() {} |
122 | 124 |
123 ~TestSafeBrowsingDatabase() override {} | 125 ~TestSafeBrowsingDatabase() override {} |
124 | 126 |
125 // Initializes the database with the given filename. | 127 // Initializes the database with the given filename. |
126 void Init(const base::FilePath& filename) override {} | 128 void Init(const base::FilePath& filename) override {} |
127 | 129 |
128 // Deletes the current database and creates a new one. | 130 // Deletes the current database and creates a new one. |
129 bool ResetDatabase() override { | 131 bool ResetDatabase() override { |
130 badurls_.clear(); | 132 badurls_.clear(); |
131 return true; | 133 return true; |
132 } | 134 } |
133 | 135 |
134 // Called on the IO thread to check if the given URL is safe or not. If we | 136 // Called on the IO thread to check if the given URL is safe or not. If we |
135 // can synchronously determine that the URL is safe, CheckUrl returns true, | 137 // can synchronously determine that the URL is safe, CheckUrl returns true, |
136 // otherwise it returns false. | 138 // otherwise it returns false. |
137 bool ContainsBrowseUrl(const GURL& url, | 139 bool ContainsBrowseUrl(const GURL& url, |
138 std::vector<SBPrefix>* prefix_hits, | 140 std::vector<SBPrefix>* prefix_hits, |
139 std::vector<SBFullHashResult>* cache_hits) override { | 141 std::vector<SBFullHashResult>* cache_hits) override { |
140 cache_hits->clear(); | 142 cache_hits->clear(); |
141 return ContainsUrl(safe_browsing::MALWARE, | 143 return ContainsUrl(MALWARE, PHISH, std::vector<GURL>(1, url), prefix_hits); |
142 safe_browsing::PHISH, | |
143 std::vector<GURL>(1, url), | |
144 prefix_hits); | |
145 } | 144 } |
146 bool ContainsUnwantedSoftwareUrl( | 145 bool ContainsUnwantedSoftwareUrl( |
147 const GURL& url, | 146 const GURL& url, |
148 std::vector<SBPrefix>* prefix_hits, | 147 std::vector<SBPrefix>* prefix_hits, |
149 std::vector<SBFullHashResult>* cache_hits) override { | 148 std::vector<SBFullHashResult>* cache_hits) override { |
150 cache_hits->clear(); | 149 cache_hits->clear(); |
151 return ContainsUrl(safe_browsing::UNWANTEDURL, | 150 return ContainsUrl(UNWANTEDURL, UNWANTEDURL, std::vector<GURL>(1, url), |
152 safe_browsing::UNWANTEDURL, | |
153 std::vector<GURL>(1, url), | |
154 prefix_hits); | 151 prefix_hits); |
155 } | 152 } |
156 bool ContainsDownloadUrlPrefixes( | 153 bool ContainsDownloadUrlPrefixes( |
157 const std::vector<SBPrefix>& prefixes, | 154 const std::vector<SBPrefix>& prefixes, |
158 std::vector<SBPrefix>* prefix_hits) override { | 155 std::vector<SBPrefix>* prefix_hits) override { |
159 bool found = | 156 bool found = ContainsUrlPrefixes(BINURL, BINURL, prefixes, prefix_hits); |
160 ContainsUrlPrefixes(safe_browsing::BINURL, | |
161 safe_browsing::BINURL, prefixes, prefix_hits); | |
162 if (!found) | 157 if (!found) |
163 return false; | 158 return false; |
164 DCHECK_LE(1U, prefix_hits->size()); | 159 DCHECK_LE(1U, prefix_hits->size()); |
165 return true; | 160 return true; |
166 } | 161 } |
167 bool ContainsCsdWhitelistedUrl(const GURL& url) override { return true; } | 162 bool ContainsCsdWhitelistedUrl(const GURL& url) override { return true; } |
168 bool ContainsDownloadWhitelistedString(const std::string& str) override { | 163 bool ContainsDownloadWhitelistedString(const std::string& str) override { |
169 return true; | 164 return true; |
170 } | 165 } |
171 bool ContainsDownloadWhitelistedUrl(const GURL& url) override { return true; } | 166 bool ContainsDownloadWhitelistedUrl(const GURL& url) override { return true; } |
(...skipping 29 matching lines...) Expand all Loading... |
201 bool IsMalwareIPMatchKillSwitchOn() override { return false; } | 196 bool IsMalwareIPMatchKillSwitchOn() override { return false; } |
202 bool IsCsdWhitelistKillSwitchOn() override { return false; } | 197 bool IsCsdWhitelistKillSwitchOn() override { return false; } |
203 | 198 |
204 // Fill up the database with test URL. | 199 // Fill up the database with test URL. |
205 void AddUrl(const GURL& url, | 200 void AddUrl(const GURL& url, |
206 const SBFullHashResult& full_hash, | 201 const SBFullHashResult& full_hash, |
207 const std::vector<SBPrefix>& prefix_hits) { | 202 const std::vector<SBPrefix>& prefix_hits) { |
208 Hits* hits_for_url = &badurls_[url.spec()]; | 203 Hits* hits_for_url = &badurls_[url.spec()]; |
209 hits_for_url->list_ids.push_back(full_hash.list_id); | 204 hits_for_url->list_ids.push_back(full_hash.list_id); |
210 hits_for_url->prefix_hits.insert(hits_for_url->prefix_hits.end(), | 205 hits_for_url->prefix_hits.insert(hits_for_url->prefix_hits.end(), |
211 prefix_hits.begin(), | 206 prefix_hits.begin(), prefix_hits.end()); |
212 prefix_hits.end()); | |
213 bad_prefixes_.insert( | 207 bad_prefixes_.insert( |
214 std::make_pair(full_hash.list_id, full_hash.hash.prefix)); | 208 std::make_pair(full_hash.list_id, full_hash.hash.prefix)); |
215 } | 209 } |
216 | 210 |
217 private: | 211 private: |
218 // Stores |list_ids| of safe browsing lists that match some |prefix_hits|. | 212 // Stores |list_ids| of safe browsing lists that match some |prefix_hits|. |
219 struct Hits { | 213 struct Hits { |
220 std::vector<int> list_ids; | 214 std::vector<int> list_ids; |
221 std::vector<SBPrefix> prefix_hits; | 215 std::vector<SBPrefix> prefix_hits; |
222 }; | 216 }; |
223 | 217 |
224 bool ContainsUrl(int list_id0, | 218 bool ContainsUrl(int list_id0, |
225 int list_id1, | 219 int list_id1, |
226 const std::vector<GURL>& urls, | 220 const std::vector<GURL>& urls, |
227 std::vector<SBPrefix>* prefix_hits) { | 221 std::vector<SBPrefix>* prefix_hits) { |
228 bool hit = false; | 222 bool hit = false; |
229 for (const GURL& url : urls) { | 223 for (const GURL& url : urls) { |
230 base::hash_map<std::string, Hits>::const_iterator | 224 base::hash_map<std::string, Hits>::const_iterator badurls_it = |
231 badurls_it = badurls_.find(url.spec()); | 225 badurls_.find(url.spec()); |
232 | 226 |
233 if (badurls_it == badurls_.end()) | 227 if (badurls_it == badurls_.end()) |
234 continue; | 228 continue; |
235 | 229 |
236 std::vector<int> list_ids_for_url = badurls_it->second.list_ids; | 230 std::vector<int> list_ids_for_url = badurls_it->second.list_ids; |
237 if (std::find(list_ids_for_url.begin(), list_ids_for_url.end(), list_id0) | 231 if (std::find(list_ids_for_url.begin(), list_ids_for_url.end(), list_id0) |
238 != list_ids_for_url.end() || | 232 != list_ids_for_url.end() || |
239 std::find(list_ids_for_url.begin(), list_ids_for_url.end(), list_id1) | 233 std::find(list_ids_for_url.begin(), list_ids_for_url.end(), list_id1) |
240 != list_ids_for_url.end()) { | 234 != list_ids_for_url.end()) { |
241 prefix_hits->insert(prefix_hits->end(), | 235 prefix_hits->insert(prefix_hits->end(), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 274 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
281 bool enable_download_protection, | 275 bool enable_download_protection, |
282 bool enable_client_side_whitelist, | 276 bool enable_client_side_whitelist, |
283 bool enable_download_whitelist, | 277 bool enable_download_whitelist, |
284 bool enable_extension_blacklist, | 278 bool enable_extension_blacklist, |
285 bool enable_ip_blacklist, | 279 bool enable_ip_blacklist, |
286 bool enabled_unwanted_software_list) override { | 280 bool enabled_unwanted_software_list) override { |
287 db_ = new TestSafeBrowsingDatabase(); | 281 db_ = new TestSafeBrowsingDatabase(); |
288 return db_; | 282 return db_; |
289 } | 283 } |
290 TestSafeBrowsingDatabase* GetDb() { | 284 TestSafeBrowsingDatabase* GetDb() { return db_; } |
291 return db_; | 285 |
292 } | |
293 private: | 286 private: |
294 // Owned by the SafebrowsingService. | 287 // Owned by the SafebrowsingService. |
295 TestSafeBrowsingDatabase* db_; | 288 TestSafeBrowsingDatabase* db_; |
296 }; | 289 }; |
297 | 290 |
298 // A TestProtocolManager that could return fixed responses from | 291 // A TestProtocolManager that could return fixed responses from |
299 // safebrowsing server for testing purpose. | 292 // safebrowsing server for testing purpose. |
300 class TestProtocolManager : public SafeBrowsingProtocolManager { | 293 class TestProtocolManager : public SafeBrowsingProtocolManager { |
301 public: | 294 public: |
302 TestProtocolManager(SafeBrowsingProtocolManagerDelegate* delegate, | 295 TestProtocolManager(SafeBrowsingProtocolManagerDelegate* delegate, |
303 net::URLRequestContextGetter* request_context_getter, | 296 net::URLRequestContextGetter* request_context_getter, |
304 const SafeBrowsingProtocolConfig& config) | 297 const SafeBrowsingProtocolConfig& config) |
305 : SafeBrowsingProtocolManager(delegate, request_context_getter, config) { | 298 : SafeBrowsingProtocolManager(delegate, request_context_getter, config) { |
306 create_count_++; | 299 create_count_++; |
307 } | 300 } |
308 | 301 |
309 ~TestProtocolManager() override { delete_count_++; } | 302 ~TestProtocolManager() override { delete_count_++; } |
310 | 303 |
311 // This function is called when there is a prefix hit in local safebrowsing | 304 // This function is called when there is a prefix hit in local safebrowsing |
312 // database and safebrowsing service issues a get hash request to backends. | 305 // database and safebrowsing service issues a get hash request to backends. |
313 // We return a result from the prefilled full_hashes_ hash_map to simulate | 306 // We return a result from the prefilled full_hashes_ hash_map to simulate |
314 // server's response. At the same time, latency is added to simulate real | 307 // server's response. At the same time, latency is added to simulate real |
315 // life network issues. | 308 // life network issues. |
316 void GetFullHash(const std::vector<SBPrefix>& prefixes, | 309 void GetFullHash(const std::vector<SBPrefix>& prefixes, |
317 SafeBrowsingProtocolManager::FullHashCallback callback, | 310 SafeBrowsingProtocolManager::FullHashCallback callback, |
318 bool is_download, | 311 bool is_download, |
319 bool is_extended_reporting) override { | 312 bool is_extended_reporting) override { |
320 BrowserThread::PostDelayedTask( | 313 BrowserThread::PostDelayedTask( |
321 BrowserThread::IO, FROM_HERE, | 314 BrowserThread::IO, FROM_HERE, |
322 base::Bind(InvokeFullHashCallback, callback, full_hashes_), | 315 base::Bind(InvokeFullHashCallback, callback, full_hashes_), delay_); |
323 delay_); | |
324 } | 316 } |
325 | 317 |
326 // Prepare the GetFullHash results for the next request. | 318 // Prepare the GetFullHash results for the next request. |
327 void AddGetFullHashResponse(const SBFullHashResult& full_hash_result) { | 319 void AddGetFullHashResponse(const SBFullHashResult& full_hash_result) { |
328 full_hashes_.push_back(full_hash_result); | 320 full_hashes_.push_back(full_hash_result); |
329 } | 321 } |
330 | 322 |
331 void IntroduceDelay(const base::TimeDelta& delay) { | 323 void IntroduceDelay(const base::TimeDelta& delay) { delay_ = delay; } |
332 delay_ = delay; | |
333 } | |
334 | 324 |
335 static int create_count() { | 325 static int create_count() { return create_count_; } |
336 return create_count_; | |
337 } | |
338 | 326 |
339 static int delete_count() { | 327 static int delete_count() { return delete_count_; } |
340 return delete_count_; | |
341 } | |
342 | 328 |
343 private: | 329 private: |
344 std::vector<SBFullHashResult> full_hashes_; | 330 std::vector<SBFullHashResult> full_hashes_; |
345 base::TimeDelta delay_; | 331 base::TimeDelta delay_; |
346 static int create_count_; | 332 static int create_count_; |
347 static int delete_count_; | 333 static int delete_count_; |
348 }; | 334 }; |
349 | 335 |
350 // static | 336 // static |
351 int TestProtocolManager::create_count_ = 0; | 337 int TestProtocolManager::create_count_ = 0; |
352 // static | 338 // static |
353 int TestProtocolManager::delete_count_ = 0; | 339 int TestProtocolManager::delete_count_ = 0; |
354 | 340 |
355 // Factory that creates TestProtocolManager instances. | 341 // Factory that creates TestProtocolManager instances. |
356 class TestSBProtocolManagerFactory : public SBProtocolManagerFactory { | 342 class TestSBProtocolManagerFactory : public SBProtocolManagerFactory { |
357 public: | 343 public: |
358 TestSBProtocolManagerFactory() : pm_(NULL) {} | 344 TestSBProtocolManagerFactory() : pm_(NULL) {} |
359 ~TestSBProtocolManagerFactory() override {} | 345 ~TestSBProtocolManagerFactory() override {} |
360 | 346 |
361 SafeBrowsingProtocolManager* CreateProtocolManager( | 347 SafeBrowsingProtocolManager* CreateProtocolManager( |
362 SafeBrowsingProtocolManagerDelegate* delegate, | 348 SafeBrowsingProtocolManagerDelegate* delegate, |
363 net::URLRequestContextGetter* request_context_getter, | 349 net::URLRequestContextGetter* request_context_getter, |
364 const SafeBrowsingProtocolConfig& config) override { | 350 const SafeBrowsingProtocolConfig& config) override { |
365 pm_ = new TestProtocolManager(delegate, request_context_getter, config); | 351 pm_ = new TestProtocolManager(delegate, request_context_getter, config); |
366 return pm_; | 352 return pm_; |
367 } | 353 } |
368 | 354 |
369 TestProtocolManager* GetProtocolManager() { | 355 TestProtocolManager* GetProtocolManager() { return pm_; } |
370 return pm_; | |
371 } | |
372 | 356 |
373 private: | 357 private: |
374 // Owned by the SafebrowsingService. | 358 // Owned by the SafebrowsingService. |
375 TestProtocolManager* pm_; | 359 TestProtocolManager* pm_; |
376 }; | 360 }; |
377 | 361 |
378 class MockObserver : public SafeBrowsingUIManager::Observer { | 362 class MockObserver : public SafeBrowsingUIManager::Observer { |
379 public: | 363 public: |
380 MockObserver() {} | 364 MockObserver() {} |
381 virtual ~MockObserver() {} | 365 virtual ~MockObserver() {} |
(...skipping 27 matching lines...) Expand all Loading... |
409 | 393 |
410 scoped_refptr<SafeBrowsingService> service_; | 394 scoped_refptr<SafeBrowsingService> service_; |
411 const bool expected_enabled_; | 395 const bool expected_enabled_; |
412 }; | 396 }; |
413 | 397 |
414 } // namespace | 398 } // namespace |
415 | 399 |
416 // Tests the safe browsing blocking page in a browser. | 400 // Tests the safe browsing blocking page in a browser. |
417 class SafeBrowsingServiceTest : public InProcessBrowserTest { | 401 class SafeBrowsingServiceTest : public InProcessBrowserTest { |
418 public: | 402 public: |
419 SafeBrowsingServiceTest() { | 403 SafeBrowsingServiceTest() {} |
420 } | |
421 | 404 |
422 static void GenUrlFullhashResult(const GURL& url, | 405 static void GenUrlFullhashResult(const GURL& url, |
423 int list_id, | 406 int list_id, |
424 SBFullHashResult* full_hash) { | 407 SBFullHashResult* full_hash) { |
425 std::string host; | 408 std::string host; |
426 std::string path; | 409 std::string path; |
427 safe_browsing::CanonicalizeUrl(url, &host, &path, NULL); | 410 CanonicalizeUrl(url, &host, &path, NULL); |
428 full_hash->hash = safe_browsing::SBFullHashForString(host + path); | 411 full_hash->hash = SBFullHashForString(host + path); |
429 full_hash->list_id = list_id; | 412 full_hash->list_id = list_id; |
430 } | 413 } |
431 | 414 |
432 void SetUp() override { | 415 void SetUp() override { |
433 // InProcessBrowserTest::SetUp() instantiates SafebrowsingService and | 416 // InProcessBrowserTest::SetUp() instantiates SafebrowsingService and |
434 // RegisterFactory has to be called before SafeBrowsingService is created. | 417 // RegisterFactory has to be called before SafeBrowsingService is created. |
435 sb_factory_.reset(new TestSafeBrowsingServiceFactory( | 418 sb_factory_.reset(new TestSafeBrowsingServiceFactory( |
436 "https://definatelynotarealdomain/safebrowsing")); | 419 "https://definatelynotarealdomain/safebrowsing")); |
437 SafeBrowsingService::RegisterFactory(sb_factory_.get()); | 420 SafeBrowsingService::RegisterFactory(sb_factory_.get()); |
438 SafeBrowsingDatabase::RegisterFactory(&db_factory_); | 421 SafeBrowsingDatabase::RegisterFactory(&db_factory_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return LocalDatabaseManagerForService(sb_service)->check_timeout_; | 503 return LocalDatabaseManagerForService(sb_service)->check_timeout_; |
521 } | 504 } |
522 | 505 |
523 static void SetCheckTimeout(SafeBrowsingService* sb_service, | 506 static void SetCheckTimeout(SafeBrowsingService* sb_service, |
524 const base::TimeDelta& delay) { | 507 const base::TimeDelta& delay) { |
525 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; | 508 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; |
526 } | 509 } |
527 | 510 |
528 void CreateCSDService() { | 511 void CreateCSDService() { |
529 #if defined(SAFE_BROWSING_CSD) | 512 #if defined(SAFE_BROWSING_CSD) |
530 safe_browsing::ClientSideDetectionService* csd_service = | 513 ClientSideDetectionService* csd_service = |
531 safe_browsing::ClientSideDetectionService::Create(NULL); | 514 ClientSideDetectionService::Create(NULL); |
532 SafeBrowsingService* sb_service = | 515 SafeBrowsingService* sb_service = |
533 g_browser_process->safe_browsing_service(); | 516 g_browser_process->safe_browsing_service(); |
534 | 517 |
535 // A CSD service should already exist. | 518 // A CSD service should already exist. |
536 EXPECT_TRUE(sb_service->csd_service_); | 519 EXPECT_TRUE(sb_service->csd_service_); |
537 | 520 |
538 sb_service->csd_service_.reset(csd_service); | 521 sb_service->csd_service_.reset(csd_service); |
539 sb_service->RefreshState(); | 522 sb_service->RefreshState(); |
540 #endif | 523 #endif |
541 } | 524 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 }; | 577 }; |
595 | 578 |
596 class SafeBrowsingServiceMetadataTest | 579 class SafeBrowsingServiceMetadataTest |
597 : public SafeBrowsingServiceTest, | 580 : public SafeBrowsingServiceTest, |
598 public ::testing::WithParamInterface<MalwareMetadataTestType> { | 581 public ::testing::WithParamInterface<MalwareMetadataTestType> { |
599 public: | 582 public: |
600 SafeBrowsingServiceMetadataTest() {} | 583 SafeBrowsingServiceMetadataTest() {} |
601 | 584 |
602 void GenUrlFullhashResultWithMetadata(const GURL& url, | 585 void GenUrlFullhashResultWithMetadata(const GURL& url, |
603 SBFullHashResult* full_hash) { | 586 SBFullHashResult* full_hash) { |
604 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash); | 587 GenUrlFullhashResult(url, MALWARE, full_hash); |
605 | 588 |
606 safe_browsing::MalwarePatternType proto; | 589 MalwarePatternType proto; |
607 switch (GetParam()) { | 590 switch (GetParam()) { |
608 case METADATA_NONE: | 591 case METADATA_NONE: |
609 full_hash->metadata = std::string(); | 592 full_hash->metadata = std::string(); |
610 break; | 593 break; |
611 case METADATA_LANDING: | 594 case METADATA_LANDING: |
612 proto.set_pattern_type(safe_browsing::MalwarePatternType::LANDING); | 595 proto.set_pattern_type(MalwarePatternType::LANDING); |
613 full_hash->metadata = proto.SerializeAsString(); | 596 full_hash->metadata = proto.SerializeAsString(); |
614 break; | 597 break; |
615 case METADATA_DISTRIBUTION: | 598 case METADATA_DISTRIBUTION: |
616 proto.set_pattern_type(safe_browsing::MalwarePatternType::DISTRIBUTION); | 599 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION); |
617 full_hash->metadata = proto.SerializeAsString(); | 600 full_hash->metadata = proto.SerializeAsString(); |
618 break; | 601 break; |
619 } | 602 } |
620 } | 603 } |
621 | 604 |
622 private: | 605 private: |
623 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); | 606 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); |
624 }; | 607 }; |
625 | 608 |
626 namespace { | 609 namespace { |
(...skipping 21 matching lines...) Expand all Loading... |
648 EXPECT_TRUE(ShowingInterstitialPage()); | 631 EXPECT_TRUE(ShowingInterstitialPage()); |
649 } | 632 } |
650 | 633 |
651 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { | 634 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { |
652 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 635 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
653 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); | 636 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); |
654 | 637 |
655 // Add the iframe url as malware and then load the parent page. | 638 // Add the iframe url as malware and then load the parent page. |
656 SBFullHashResult malware_full_hash; | 639 SBFullHashResult malware_full_hash; |
657 GenUrlFullhashResultWithMetadata(iframe_url, &malware_full_hash); | 640 GenUrlFullhashResultWithMetadata(iframe_url, &malware_full_hash); |
658 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(iframe_url))) | 641 EXPECT_CALL(observer_, |
659 .Times(1); | 642 OnSafeBrowsingMatch(IsUnsafeResourceFor(iframe_url))).Times(1); |
660 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))) | 643 EXPECT_CALL(observer_, |
661 .Times(1); | 644 OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))).Times(1); |
662 SetupResponseForUrl(iframe_url, malware_full_hash); | 645 SetupResponseForUrl(iframe_url, malware_full_hash); |
663 ui_test_utils::NavigateToURL(browser(), main_url); | 646 ui_test_utils::NavigateToURL(browser(), main_url); |
664 // All types should show the interstitial. | 647 // All types should show the interstitial. |
665 EXPECT_TRUE(ShowingInterstitialPage()); | 648 EXPECT_TRUE(ShowingInterstitialPage()); |
666 } | 649 } |
667 | 650 |
668 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareImg) { | 651 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareImg) { |
669 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 652 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
670 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 653 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
671 | 654 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 METADATA_LANDING, | 688 METADATA_LANDING, |
706 METADATA_DISTRIBUTION)); | 689 METADATA_DISTRIBUTION)); |
707 | 690 |
708 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { | 691 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { |
709 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 692 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
710 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 693 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
711 | 694 |
712 // Add the img url as coming from a site serving UwS and then load the parent | 695 // Add the img url as coming from a site serving UwS and then load the parent |
713 // page. | 696 // page. |
714 SBFullHashResult uws_full_hash; | 697 SBFullHashResult uws_full_hash; |
715 GenUrlFullhashResult(img_url, safe_browsing::UNWANTEDURL, | 698 GenUrlFullhashResult(img_url, UNWANTEDURL, &uws_full_hash); |
716 &uws_full_hash); | |
717 SetupResponseForUrl(img_url, uws_full_hash); | 699 SetupResponseForUrl(img_url, uws_full_hash); |
718 | 700 |
719 ui_test_utils::NavigateToURL(browser(), main_url); | 701 ui_test_utils::NavigateToURL(browser(), main_url); |
720 | 702 |
721 EXPECT_FALSE(ShowingInterstitialPage()); | 703 EXPECT_FALSE(ShowingInterstitialPage()); |
722 } | 704 } |
723 | 705 |
724 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) { | 706 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) { |
725 GURL url = embedded_test_server()->GetURL(kEmptyPage); | 707 GURL url = embedded_test_server()->GetURL(kEmptyPage); |
726 | 708 |
727 // After adding the url to safebrowsing database and getfullhash result, | 709 // After adding the url to safebrowsing database and getfullhash result, |
728 // we should see the interstitial page. | 710 // we should see the interstitial page. |
729 SBFullHashResult malware_full_hash; | 711 SBFullHashResult malware_full_hash; |
730 GenUrlFullhashResult(url, safe_browsing::MALWARE, &malware_full_hash); | 712 GenUrlFullhashResult(url, MALWARE, &malware_full_hash); |
731 EXPECT_CALL(observer_, | 713 EXPECT_CALL(observer_, |
732 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1); | 714 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1); |
733 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1) | 715 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))) |
| 716 .Times(1) |
734 .WillOnce(testing::Invoke( | 717 .WillOnce(testing::Invoke( |
735 this, &SafeBrowsingServiceTest::ProceedAndWhitelist)); | 718 this, &SafeBrowsingServiceTest::ProceedAndWhitelist)); |
736 SetupResponseForUrl(url, malware_full_hash); | 719 SetupResponseForUrl(url, malware_full_hash); |
737 | 720 |
738 ui_test_utils::NavigateToURL(browser(), url); | 721 ui_test_utils::NavigateToURL(browser(), url); |
739 // Mock calls OnBlockingPageDone set to proceed, so the interstitial | 722 // Mock calls OnBlockingPageDone set to proceed, so the interstitial |
740 // is removed. | 723 // is removed. |
741 EXPECT_FALSE(ShowingInterstitialPage()); | 724 EXPECT_FALSE(ShowingInterstitialPage()); |
742 Mock::VerifyAndClearExpectations(&observer_); | 725 Mock::VerifyAndClearExpectations(&observer_); |
743 | 726 |
(...skipping 30 matching lines...) Expand all Loading... |
774 } | 757 } |
775 | 758 |
776 private: | 759 private: |
777 prerender::PrerenderManager::PrerenderManagerMode old_prerender_mode_; | 760 prerender::PrerenderManager::PrerenderManagerMode old_prerender_mode_; |
778 } set_prefetch_for_test(true); | 761 } set_prefetch_for_test(true); |
779 | 762 |
780 // Even though we have added this uri to the safebrowsing database and | 763 // Even though we have added this uri to the safebrowsing database and |
781 // getfullhash result, we should not see the interstitial page since the | 764 // getfullhash result, we should not see the interstitial page since the |
782 // only malware was a prefetch target. | 765 // only malware was a prefetch target. |
783 SBFullHashResult malware_full_hash; | 766 SBFullHashResult malware_full_hash; |
784 GenUrlFullhashResult(malware_url, safe_browsing::MALWARE, | 767 GenUrlFullhashResult(malware_url, MALWARE, &malware_full_hash); |
785 &malware_full_hash); | |
786 SetupResponseForUrl(malware_url, malware_full_hash); | 768 SetupResponseForUrl(malware_url, malware_full_hash); |
787 ui_test_utils::NavigateToURL(browser(), url); | 769 ui_test_utils::NavigateToURL(browser(), url); |
788 EXPECT_FALSE(ShowingInterstitialPage()); | 770 EXPECT_FALSE(ShowingInterstitialPage()); |
789 Mock::VerifyAndClear(&observer_); | 771 Mock::VerifyAndClear(&observer_); |
790 | 772 |
791 // However, when we navigate to the malware page, we should still get | 773 // However, when we navigate to the malware page, we should still get |
792 // the interstitial. | 774 // the interstitial. |
793 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(malware_url))) | 775 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(malware_url))) |
794 .Times(1); | 776 .Times(1); |
795 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) | 777 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) |
796 .Times(1); | 778 .Times(1); |
797 ui_test_utils::NavigateToURL(browser(), malware_url); | 779 ui_test_utils::NavigateToURL(browser(), malware_url); |
798 EXPECT_TRUE(ShowingInterstitialPage()); | 780 EXPECT_TRUE(ShowingInterstitialPage()); |
799 Mock::VerifyAndClear(&observer_); | 781 Mock::VerifyAndClear(&observer_); |
800 } | 782 } |
801 | 783 |
802 } // namespace | 784 } // namespace |
803 | 785 |
804 class TestSBClient | 786 class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>, |
805 : public base::RefCountedThreadSafe<TestSBClient>, | 787 public SafeBrowsingDatabaseManager::Client { |
806 public SafeBrowsingDatabaseManager::Client { | |
807 public: | 788 public: |
808 TestSBClient() | 789 TestSBClient() |
809 : threat_type_(SB_THREAT_TYPE_SAFE), | 790 : threat_type_(SB_THREAT_TYPE_SAFE), |
810 safe_browsing_service_(g_browser_process->safe_browsing_service()) { | 791 safe_browsing_service_(g_browser_process->safe_browsing_service()) {} |
811 } | |
812 | 792 |
813 SBThreatType GetThreatType() const { | 793 SBThreatType GetThreatType() const { return threat_type_; } |
814 return threat_type_; | |
815 } | |
816 | 794 |
817 void CheckDownloadUrl(const std::vector<GURL>& url_chain) { | 795 void CheckDownloadUrl(const std::vector<GURL>& url_chain) { |
818 BrowserThread::PostTask( | 796 BrowserThread::PostTask( |
819 BrowserThread::IO, FROM_HERE, | 797 BrowserThread::IO, FROM_HERE, |
820 base::Bind(&TestSBClient::CheckDownloadUrlOnIOThread, | 798 base::Bind(&TestSBClient::CheckDownloadUrlOnIOThread, this, url_chain)); |
821 this, url_chain)); | |
822 content::RunMessageLoop(); // Will stop in OnCheckDownloadUrlResult. | 799 content::RunMessageLoop(); // Will stop in OnCheckDownloadUrlResult. |
823 } | 800 } |
824 | 801 |
825 void CheckBrowseUrl(const GURL& url) { | 802 void CheckBrowseUrl(const GURL& url) { |
826 BrowserThread::PostTask( | 803 BrowserThread::PostTask( |
827 BrowserThread::IO, FROM_HERE, | 804 BrowserThread::IO, FROM_HERE, |
828 base::Bind(&TestSBClient::CheckBrowseUrlOnIOThread, this, url)); | 805 base::Bind(&TestSBClient::CheckBrowseUrlOnIOThread, this, url)); |
829 content::RunMessageLoop(); // Will stop in OnCheckBrowseUrlResult. | 806 content::RunMessageLoop(); // Will stop in OnCheckBrowseUrlResult. |
830 } | 807 } |
831 | 808 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 866 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
890 std::vector<GURL> badbin_urls(1, badbin_url); | 867 std::vector<GURL> badbin_urls(1, badbin_url); |
891 | 868 |
892 scoped_refptr<TestSBClient> client(new TestSBClient); | 869 scoped_refptr<TestSBClient> client(new TestSBClient); |
893 client->CheckDownloadUrl(badbin_urls); | 870 client->CheckDownloadUrl(badbin_urls); |
894 | 871 |
895 // Since badbin_url is not in database, it is considered to be safe. | 872 // Since badbin_url is not in database, it is considered to be safe. |
896 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 873 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
897 | 874 |
898 SBFullHashResult full_hash_result; | 875 SBFullHashResult full_hash_result; |
899 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 876 GenUrlFullhashResult(badbin_url, BINURL, &full_hash_result); |
900 &full_hash_result); | |
901 SetupResponseForUrl(badbin_url, full_hash_result); | 877 SetupResponseForUrl(badbin_url, full_hash_result); |
902 | 878 |
903 client->CheckDownloadUrl(badbin_urls); | 879 client->CheckDownloadUrl(badbin_urls); |
904 | 880 |
905 // Now, the badbin_url is not safe since it is added to download database. | 881 // Now, the badbin_url is not safe since it is added to download database. |
906 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 882 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
907 } | 883 } |
908 | 884 |
909 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckUnwantedSoftwareUrl) { | 885 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckUnwantedSoftwareUrl) { |
910 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | 886 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); |
911 { | 887 { |
912 scoped_refptr<TestSBClient> client(new TestSBClient); | 888 scoped_refptr<TestSBClient> client(new TestSBClient); |
913 | 889 |
914 // Since bad_url is not in database, it is considered to be | 890 // Since bad_url is not in database, it is considered to be |
915 // safe. | 891 // safe. |
916 client->CheckBrowseUrl(bad_url); | 892 client->CheckBrowseUrl(bad_url); |
917 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 893 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
918 | 894 |
919 SBFullHashResult full_hash_result; | 895 SBFullHashResult full_hash_result; |
920 GenUrlFullhashResult( | 896 GenUrlFullhashResult(bad_url, UNWANTEDURL, &full_hash_result); |
921 bad_url, safe_browsing::UNWANTEDURL, &full_hash_result); | |
922 SetupResponseForUrl(bad_url, full_hash_result); | 897 SetupResponseForUrl(bad_url, full_hash_result); |
923 | 898 |
924 // Now, the bad_url is not safe since it is added to download | 899 // Now, the bad_url is not safe since it is added to download |
925 // database. | 900 // database. |
926 client->CheckBrowseUrl(bad_url); | 901 client->CheckBrowseUrl(bad_url); |
927 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | 902 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); |
928 } | 903 } |
929 | 904 |
930 // The unwantedness should survive across multiple clients. | 905 // The unwantedness should survive across multiple clients. |
931 { | 906 { |
932 scoped_refptr<TestSBClient> client(new TestSBClient); | 907 scoped_refptr<TestSBClient> client(new TestSBClient); |
933 client->CheckBrowseUrl(bad_url); | 908 client->CheckBrowseUrl(bad_url); |
934 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | 909 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); |
935 } | 910 } |
936 | 911 |
937 // An unwanted URL also marked as malware should be flagged as malware. | 912 // An unwanted URL also marked as malware should be flagged as malware. |
938 { | 913 { |
939 scoped_refptr<TestSBClient> client(new TestSBClient); | 914 scoped_refptr<TestSBClient> client(new TestSBClient); |
940 | 915 |
941 SBFullHashResult full_hash_result; | 916 SBFullHashResult full_hash_result; |
942 GenUrlFullhashResult( | 917 GenUrlFullhashResult(bad_url, MALWARE, &full_hash_result); |
943 bad_url, safe_browsing::MALWARE, &full_hash_result); | |
944 SetupResponseForUrl(bad_url, full_hash_result); | 918 SetupResponseForUrl(bad_url, full_hash_result); |
945 | 919 |
946 client->CheckBrowseUrl(bad_url); | 920 client->CheckBrowseUrl(bad_url); |
947 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 921 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
948 } | 922 } |
949 } | 923 } |
950 | 924 |
951 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckBrowseUrl) { | 925 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckBrowseUrl) { |
952 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | 926 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); |
953 { | 927 { |
954 scoped_refptr<TestSBClient> client(new TestSBClient); | 928 scoped_refptr<TestSBClient> client(new TestSBClient); |
955 | 929 |
956 // Since bad_url is not in database, it is considered to be | 930 // Since bad_url is not in database, it is considered to be |
957 // safe. | 931 // safe. |
958 client->CheckBrowseUrl(bad_url); | 932 client->CheckBrowseUrl(bad_url); |
959 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 933 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
960 | 934 |
961 SBFullHashResult full_hash_result; | 935 SBFullHashResult full_hash_result; |
962 GenUrlFullhashResult( | 936 GenUrlFullhashResult(bad_url, MALWARE, &full_hash_result); |
963 bad_url, safe_browsing::MALWARE, &full_hash_result); | |
964 SetupResponseForUrl(bad_url, full_hash_result); | 937 SetupResponseForUrl(bad_url, full_hash_result); |
965 | 938 |
966 // Now, the bad_url is not safe since it is added to download | 939 // Now, the bad_url is not safe since it is added to download |
967 // database. | 940 // database. |
968 client->CheckBrowseUrl(bad_url); | 941 client->CheckBrowseUrl(bad_url); |
969 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 942 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
970 } | 943 } |
971 | 944 |
972 // The unwantedness should survive across multiple clients. | 945 // The unwantedness should survive across multiple clients. |
973 { | 946 { |
974 scoped_refptr<TestSBClient> client(new TestSBClient); | 947 scoped_refptr<TestSBClient> client(new TestSBClient); |
975 client->CheckBrowseUrl(bad_url); | 948 client->CheckBrowseUrl(bad_url); |
976 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 949 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
977 } | 950 } |
978 | 951 |
979 // Adding the unwanted state to an existing malware URL should have no impact | 952 // Adding the unwanted state to an existing malware URL should have no impact |
980 // (i.e. a malware hit should still prevail). | 953 // (i.e. a malware hit should still prevail). |
981 { | 954 { |
982 scoped_refptr<TestSBClient> client(new TestSBClient); | 955 scoped_refptr<TestSBClient> client(new TestSBClient); |
983 | 956 |
984 SBFullHashResult full_hash_result; | 957 SBFullHashResult full_hash_result; |
985 GenUrlFullhashResult( | 958 GenUrlFullhashResult(bad_url, UNWANTEDURL, &full_hash_result); |
986 bad_url, safe_browsing::UNWANTEDURL, &full_hash_result); | |
987 SetupResponseForUrl(bad_url, full_hash_result); | 959 SetupResponseForUrl(bad_url, full_hash_result); |
988 | 960 |
989 client->CheckBrowseUrl(bad_url); | 961 client->CheckBrowseUrl(bad_url); |
990 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 962 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
991 } | 963 } |
992 } | 964 } |
993 | 965 |
994 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrlRedirects) { | 966 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrlRedirects) { |
995 GURL original_url = embedded_test_server()->GetURL(kEmptyPage); | 967 GURL original_url = embedded_test_server()->GetURL(kEmptyPage); |
996 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 968 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
997 GURL final_url = embedded_test_server()->GetURL(kEmptyPage); | 969 GURL final_url = embedded_test_server()->GetURL(kEmptyPage); |
998 std::vector<GURL> badbin_urls; | 970 std::vector<GURL> badbin_urls; |
999 badbin_urls.push_back(original_url); | 971 badbin_urls.push_back(original_url); |
1000 badbin_urls.push_back(badbin_url); | 972 badbin_urls.push_back(badbin_url); |
1001 badbin_urls.push_back(final_url); | 973 badbin_urls.push_back(final_url); |
1002 | 974 |
1003 scoped_refptr<TestSBClient> client(new TestSBClient); | 975 scoped_refptr<TestSBClient> client(new TestSBClient); |
1004 client->CheckDownloadUrl(badbin_urls); | 976 client->CheckDownloadUrl(badbin_urls); |
1005 | 977 |
1006 // Since badbin_url is not in database, it is considered to be safe. | 978 // Since badbin_url is not in database, it is considered to be safe. |
1007 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 979 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
1008 | 980 |
1009 SBFullHashResult full_hash_result; | 981 SBFullHashResult full_hash_result; |
1010 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 982 GenUrlFullhashResult(badbin_url, BINURL, &full_hash_result); |
1011 &full_hash_result); | |
1012 SetupResponseForUrl(badbin_url, full_hash_result); | 983 SetupResponseForUrl(badbin_url, full_hash_result); |
1013 | 984 |
1014 client->CheckDownloadUrl(badbin_urls); | 985 client->CheckDownloadUrl(badbin_urls); |
1015 | 986 |
1016 // Now, the badbin_url is not safe since it is added to download database. | 987 // Now, the badbin_url is not safe since it is added to download database. |
1017 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 988 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
1018 } | 989 } |
1019 | 990 |
1020 #if defined(OS_WIN) | 991 #if defined(OS_WIN) |
1021 // http://crbug.com/396409 | 992 // http://crbug.com/396409 |
1022 #define MAYBE_CheckDownloadUrlTimedOut DISABLED_CheckDownloadUrlTimedOut | 993 #define MAYBE_CheckDownloadUrlTimedOut DISABLED_CheckDownloadUrlTimedOut |
1023 #else | 994 #else |
1024 #define MAYBE_CheckDownloadUrlTimedOut CheckDownloadUrlTimedOut | 995 #define MAYBE_CheckDownloadUrlTimedOut CheckDownloadUrlTimedOut |
1025 #endif | 996 #endif |
1026 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 997 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
1027 MAYBE_CheckDownloadUrlTimedOut) { | 998 MAYBE_CheckDownloadUrlTimedOut) { |
1028 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 999 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
1029 std::vector<GURL> badbin_urls(1, badbin_url); | 1000 std::vector<GURL> badbin_urls(1, badbin_url); |
1030 | 1001 |
1031 scoped_refptr<TestSBClient> client(new TestSBClient); | 1002 scoped_refptr<TestSBClient> client(new TestSBClient); |
1032 SBFullHashResult full_hash_result; | 1003 SBFullHashResult full_hash_result; |
1033 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 1004 GenUrlFullhashResult(badbin_url, BINURL, &full_hash_result); |
1034 &full_hash_result); | |
1035 SetupResponseForUrl(badbin_url, full_hash_result); | 1005 SetupResponseForUrl(badbin_url, full_hash_result); |
1036 client->CheckDownloadUrl(badbin_urls); | 1006 client->CheckDownloadUrl(badbin_urls); |
1037 | 1007 |
1038 // badbin_url is not safe since it is added to download database. | 1008 // badbin_url is not safe since it is added to download database. |
1039 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 1009 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
1040 | 1010 |
1041 // | 1011 // |
1042 // Now introducing delays and we should hit timeout. | 1012 // Now introducing delays and we should hit timeout. |
1043 // | 1013 // |
1044 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1014 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1045 base::TimeDelta default_urlcheck_timeout = GetCheckTimeout(sb_service); | 1015 base::TimeDelta default_urlcheck_timeout = GetCheckTimeout(sb_service); |
1046 IntroduceGetHashDelay(base::TimeDelta::FromSeconds(1)); | 1016 IntroduceGetHashDelay(base::TimeDelta::FromSeconds(1)); |
1047 SetCheckTimeout(sb_service, base::TimeDelta::FromMilliseconds(1)); | 1017 SetCheckTimeout(sb_service, base::TimeDelta::FromMilliseconds(1)); |
1048 client->CheckDownloadUrl(badbin_urls); | 1018 client->CheckDownloadUrl(badbin_urls); |
1049 | 1019 |
1050 // There should be a timeout and the hash would be considered as safe. | 1020 // There should be a timeout and the hash would be considered as safe. |
1051 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 1021 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
1052 | 1022 |
1053 // Need to set the timeout back to the default value. | 1023 // Need to set the timeout back to the default value. |
1054 SetCheckTimeout(sb_service, default_urlcheck_timeout); | 1024 SetCheckTimeout(sb_service, default_urlcheck_timeout); |
1055 } | 1025 } |
1056 | 1026 |
1057 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { | 1027 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { |
1058 CreateCSDService(); | 1028 CreateCSDService(); |
1059 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1029 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1060 safe_browsing::ClientSideDetectionService* csd_service = | 1030 ClientSideDetectionService* csd_service = |
1061 sb_service->safe_browsing_detection_service(); | 1031 sb_service->safe_browsing_detection_service(); |
1062 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1032 PrefService* pref_service = browser()->profile()->GetPrefs(); |
1063 | 1033 |
1064 ASSERT_TRUE(sb_service != NULL); | 1034 ASSERT_TRUE(sb_service != NULL); |
1065 ASSERT_TRUE(csd_service != NULL); | 1035 ASSERT_TRUE(csd_service != NULL); |
1066 ASSERT_TRUE(pref_service != NULL); | 1036 ASSERT_TRUE(pref_service != NULL); |
1067 | 1037 |
1068 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1038 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
1069 | 1039 |
1070 // SBS might still be starting, make sure this doesn't flake. | 1040 // SBS might still be starting, make sure this doesn't flake. |
1071 EXPECT_TRUE(sb_service->enabled_by_prefs()); | 1041 EXPECT_TRUE(sb_service->enabled_by_prefs()); |
1072 WaitForIOAndCheckEnabled(sb_service, true); | 1042 WaitForIOAndCheckEnabled(sb_service, true); |
1073 EXPECT_TRUE(csd_service->enabled()); | 1043 EXPECT_TRUE(csd_service->enabled()); |
1074 | 1044 |
1075 // Add a new Profile. SBS should keep running. | 1045 // Add a new Profile. SBS should keep running. |
1076 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | 1046 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); |
1077 scoped_ptr<Profile> profile2(Profile::CreateProfile( | 1047 scoped_ptr<Profile> profile2(Profile::CreateProfile( |
1078 temp_profile_dir_.path(), NULL, Profile::CREATE_MODE_SYNCHRONOUS)); | 1048 temp_profile_dir_.path(), NULL, Profile::CREATE_MODE_SYNCHRONOUS)); |
1079 ASSERT_TRUE(profile2.get() != NULL); | 1049 ASSERT_TRUE(profile2.get() != NULL); |
1080 StartupTaskRunnerServiceFactory::GetForProfile(profile2.get())-> | 1050 StartupTaskRunnerServiceFactory::GetForProfile(profile2.get())-> |
1081 StartDeferredTaskRunners(); | 1051 StartDeferredTaskRunners(); |
1082 PrefService* pref_service2 = profile2->GetPrefs(); | 1052 PrefService* pref_service2 = profile2->GetPrefs(); |
1083 EXPECT_TRUE(pref_service2->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1053 EXPECT_TRUE(pref_service2->GetBoolean(prefs::kSafeBrowsingEnabled)); |
1084 // We don't expect the state to have changed, but if it did, wait for it. | 1054 // We don't expect the state to have changed, but if it did, wait for it. |
1085 EXPECT_TRUE(sb_service->enabled_by_prefs()); | 1055 EXPECT_TRUE(sb_service->enabled_by_prefs()); |
1086 WaitForIOAndCheckEnabled(sb_service, true); | 1056 WaitForIOAndCheckEnabled(sb_service, true); |
1087 EXPECT_TRUE(csd_service->enabled()); | 1057 EXPECT_TRUE(csd_service->enabled()); |
1088 | 1058 |
1089 // Change one of the prefs. SBS should keep running. | 1059 // Change one of the prefs. SBS should keep running. |
1090 pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false); | 1060 pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false); |
1091 EXPECT_TRUE(sb_service->enabled_by_prefs()); | 1061 EXPECT_TRUE(sb_service->enabled_by_prefs()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 } | 1119 } |
1150 | 1120 |
1151 protected: | 1121 protected: |
1152 Profile* profile2_; | 1122 Profile* profile2_; |
1153 }; | 1123 }; |
1154 | 1124 |
1155 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, | 1125 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, |
1156 DontStartAfterShutdown) { | 1126 DontStartAfterShutdown) { |
1157 CreateCSDService(); | 1127 CreateCSDService(); |
1158 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1128 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1159 safe_browsing::ClientSideDetectionService* csd_service = | 1129 ClientSideDetectionService* csd_service = |
1160 sb_service->safe_browsing_detection_service(); | 1130 sb_service->safe_browsing_detection_service(); |
1161 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1131 PrefService* pref_service = browser()->profile()->GetPrefs(); |
1162 | 1132 |
1163 ASSERT_TRUE(sb_service != NULL); | 1133 ASSERT_TRUE(sb_service != NULL); |
1164 ASSERT_TRUE(csd_service != NULL); | 1134 ASSERT_TRUE(csd_service != NULL); |
1165 ASSERT_TRUE(pref_service != NULL); | 1135 ASSERT_TRUE(pref_service != NULL); |
1166 | 1136 |
1167 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1137 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
1168 | 1138 |
1169 // SBS might still be starting, make sure this doesn't flake. | 1139 // SBS might still be starting, make sure this doesn't flake. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 return false; | 1213 return false; |
1244 } | 1214 } |
1245 | 1215 |
1246 sql::Connection db; | 1216 sql::Connection db; |
1247 if (!db.Open(cookie_path)) { | 1217 if (!db.Open(cookie_path)) { |
1248 EXPECT_TRUE(false); | 1218 EXPECT_TRUE(false); |
1249 return false; | 1219 return false; |
1250 } | 1220 } |
1251 // Ensure the host value in the cookie file matches the test server we will | 1221 // Ensure the host value in the cookie file matches the test server we will |
1252 // be connecting to. | 1222 // be connecting to. |
1253 sql::Statement smt(db.GetUniqueStatement( | 1223 sql::Statement smt( |
1254 "UPDATE cookies SET host_key = ?")); | 1224 db.GetUniqueStatement("UPDATE cookies SET host_key = ?")); |
1255 if (!smt.is_valid()) { | 1225 if (!smt.is_valid()) { |
1256 EXPECT_TRUE(false); | 1226 EXPECT_TRUE(false); |
1257 return false; | 1227 return false; |
1258 } | 1228 } |
1259 if (!smt.BindString(0, embedded_test_server()->base_url().host())) { | 1229 if (!smt.BindString(0, embedded_test_server()->base_url().host())) { |
1260 EXPECT_TRUE(false); | 1230 EXPECT_TRUE(false); |
1261 return false; | 1231 return false; |
1262 } | 1232 } |
1263 if (!smt.Run()) { | 1233 if (!smt.Run()) { |
1264 EXPECT_TRUE(false); | 1234 EXPECT_TRUE(false); |
1265 return false; | 1235 return false; |
1266 } | 1236 } |
1267 | 1237 |
1268 return InProcessBrowserTest::SetUpUserDataDirectory(); | 1238 return InProcessBrowserTest::SetUpUserDataDirectory(); |
1269 } | 1239 } |
1270 | 1240 |
1271 void TearDownInProcessBrowserTestFixture() override { | 1241 void TearDownInProcessBrowserTestFixture() override { |
1272 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 1242 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
1273 | 1243 |
1274 sql::Connection db; | 1244 sql::Connection db; |
1275 base::FilePath cookie_path( | 1245 base::FilePath cookie_path( |
1276 SafeBrowsingService::GetCookieFilePathForTesting()); | 1246 SafeBrowsingService::GetCookieFilePathForTesting()); |
1277 ASSERT_TRUE(db.Open(cookie_path)); | 1247 ASSERT_TRUE(db.Open(cookie_path)); |
1278 | 1248 |
1279 sql::Statement smt(db.GetUniqueStatement( | 1249 sql::Statement smt( |
1280 "SELECT name, value FROM cookies ORDER BY name")); | 1250 db.GetUniqueStatement("SELECT name, value FROM cookies ORDER BY name")); |
1281 ASSERT_TRUE(smt.is_valid()); | 1251 ASSERT_TRUE(smt.is_valid()); |
1282 | 1252 |
1283 ASSERT_TRUE(smt.Step()); | 1253 ASSERT_TRUE(smt.Step()); |
1284 ASSERT_EQ("a", smt.ColumnString(0)); | 1254 ASSERT_EQ("a", smt.ColumnString(0)); |
1285 ASSERT_EQ("b", smt.ColumnString(1)); | 1255 ASSERT_EQ("b", smt.ColumnString(1)); |
1286 ASSERT_TRUE(smt.Step()); | 1256 ASSERT_TRUE(smt.Step()); |
1287 ASSERT_EQ("c", smt.ColumnString(0)); | 1257 ASSERT_EQ("c", smt.ColumnString(0)); |
1288 ASSERT_EQ("d", smt.ColumnString(1)); | 1258 ASSERT_EQ("d", smt.ColumnString(1)); |
1289 EXPECT_FALSE(smt.Step()); | 1259 EXPECT_FALSE(smt.Step()); |
1290 } | 1260 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 | 1318 |
1349 // Test that a Local Safe Browsing database update request both sends cookies | 1319 // Test that a Local Safe Browsing database update request both sends cookies |
1350 // and can save cookies. | 1320 // and can save cookies. |
1351 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest, | 1321 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest, |
1352 TestSBUpdateCookies) { | 1322 TestSBUpdateCookies) { |
1353 content::WindowedNotificationObserver observer( | 1323 content::WindowedNotificationObserver observer( |
1354 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1324 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
1355 content::Source<SafeBrowsingDatabaseManager>( | 1325 content::Source<SafeBrowsingDatabaseManager>( |
1356 sb_service_->database_manager().get())); | 1326 sb_service_->database_manager().get())); |
1357 BrowserThread::PostTask( | 1327 BrowserThread::PostTask( |
1358 BrowserThread::IO, | 1328 BrowserThread::IO, FROM_HERE, |
1359 FROM_HERE, | |
1360 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1329 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
1361 observer.Wait(); | 1330 observer.Wait(); |
1362 } | 1331 } |
| 1332 |
| 1333 } // namespace safe_browsing |
OLD | NEW |