Chromium Code Reviews| 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 "chrome/browser/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // not have any copy constructor which means it can't be stored in a callback | 121 // not have any copy constructor which means it can't be stored in a callback |
| 122 // easily. Note: check will be deleted automatically when the callback is | 122 // easily. Note: check will be deleted automatically when the callback is |
| 123 // deleted. | 123 // deleted. |
| 124 void OnSafeBrowsingResult( | 124 void OnSafeBrowsingResult( |
| 125 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check) { | 125 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check) { |
| 126 check->client->OnSafeBrowsingResult(*check); | 126 check->client->OnSafeBrowsingResult(*check); |
| 127 } | 127 } |
| 128 | 128 |
| 129 ACTION_P(CheckDownloadUrlDone, threat_type) { | 129 ACTION_P(CheckDownloadUrlDone, threat_type) { |
| 130 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check = | 130 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check = |
| 131 new SafeBrowsingDatabaseManager::SafeBrowsingCheck(); | 131 new SafeBrowsingDatabaseManager::SafeBrowsingCheck( |
| 132 check->urls = arg0; | 132 arg0, |
| 133 check->is_download = true; | 133 std::vector<SBFullHash>(), |
| 134 check->threat_type = threat_type; | 134 arg1, |
| 135 check->client = arg1; | 135 safe_browsing_util::BINURL); |
| 136 for (size_t i = 0; i < check->url_results.size(); ++i) | |
| 137 check->url_results[i] = threat_type; | |
| 136 BrowserThread::PostTask(BrowserThread::IO, | 138 BrowserThread::PostTask(BrowserThread::IO, |
| 137 FROM_HERE, | 139 FROM_HERE, |
| 138 base::Bind(&OnSafeBrowsingResult, | 140 base::Bind(&OnSafeBrowsingResult, |
| 139 base::Owned(check))); | 141 base::Owned(check))); |
| 140 } | 142 } |
| 141 | 143 |
| 142 class DownloadProtectionServiceTest : public testing::Test { | 144 class DownloadProtectionServiceTest : public testing::Test { |
| 143 protected: | 145 protected: |
| 144 virtual void SetUp() { | 146 virtual void SetUp() { |
| 145 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, | 147 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, |
| 146 &msg_loop_)); | 148 &msg_loop_)); |
| 147 // Start real threads for the IO and File threads so that the DCHECKs | 149 // Start real threads for the IO and File threads so that the DCHECKs |
| 148 // to test that we're on the correct thread work. | 150 // to test that we're on the correct thread work. |
| 149 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | 151 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); |
| 150 ASSERT_TRUE(io_thread_->Start()); | 152 ASSERT_TRUE(io_thread_->Start()); |
| 151 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); | 153 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); |
| 152 sb_service_->Initialize(); | 154 sb_service_->Initialize(); |
| 153 signature_util_ = new StrictMock<MockSignatureUtil>(); | 155 signature_util_ = new StrictMock<MockSignatureUtil>(); |
| 154 download_service_ = sb_service_->download_protection_service(); | 156 download_service_ = sb_service_->download_protection_service(); |
| 155 download_service_->signature_util_ = signature_util_; | 157 download_service_->signature_util_ = signature_util_; |
| 156 download_service_->SetEnabled(true); | 158 download_service_->SetEnabled(true); |
| 157 msg_loop_.RunUntilIdle(); | 159 msg_loop_.RunUntilIdle(); |
| 160 has_result_ = false; | |
| 158 | 161 |
| 159 FilePath source_path; | 162 FilePath source_path; |
| 160 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); | 163 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); |
| 161 testdata_path_ = source_path | 164 testdata_path_ = source_path |
| 162 .AppendASCII("chrome") | 165 .AppendASCII("chrome") |
| 163 .AppendASCII("test") | 166 .AppendASCII("test") |
| 164 .AppendASCII("data") | 167 .AppendASCII("data") |
| 165 .AppendASCII("safe_browsing") | 168 .AppendASCII("safe_browsing") |
| 166 .AppendASCII("download_protection"); | 169 .AppendASCII("download_protection"); |
| 167 } | 170 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 BrowserThread::UI, | 269 BrowserThread::UI, |
| 267 FROM_HERE, | 270 FROM_HERE, |
| 268 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, | 271 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, |
| 269 base::Unretained(this), thread)); | 272 base::Unretained(this), thread)); |
| 270 msg_loop_.Run(); | 273 msg_loop_.Run(); |
| 271 } | 274 } |
| 272 | 275 |
| 273 public: | 276 public: |
| 274 void CheckDoneCallback( | 277 void CheckDoneCallback( |
| 275 DownloadProtectionService::DownloadCheckResult result) { | 278 DownloadProtectionService::DownloadCheckResult result) { |
| 276 result_.reset(new DownloadProtectionService::DownloadCheckResult(result)); | 279 result_ = result; |
| 280 has_result_ = true; | |
| 277 msg_loop_.Quit(); | 281 msg_loop_.Quit(); |
| 278 } | 282 } |
| 279 | 283 |
| 280 void SendURLFetchComplete(net::TestURLFetcher* fetcher) { | 284 void SendURLFetchComplete(net::TestURLFetcher* fetcher) { |
| 281 fetcher->delegate()->OnURLFetchComplete(fetcher); | 285 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 282 } | 286 } |
| 283 | 287 |
| 284 void ExpectResult(DownloadProtectionService::DownloadCheckResult expected) { | 288 testing::AssertionResult IsResult( |
| 285 ASSERT_TRUE(result_.get()); | 289 DownloadProtectionService::DownloadCheckResult expected) { |
| 286 EXPECT_EQ(expected, *result_); | 290 if (!has_result_) |
| 291 return testing::AssertionFailure() << "No result"; | |
| 292 has_result_ = false; | |
| 293 return result_ == expected ? | |
| 294 testing::AssertionSuccess() : | |
| 295 testing::AssertionFailure() << "Expected " << expected << | |
| 296 ", got " << result_; | |
| 287 } | 297 } |
| 288 | 298 |
| 289 protected: | 299 protected: |
| 290 scoped_refptr<FakeSafeBrowsingService> sb_service_; | 300 scoped_refptr<FakeSafeBrowsingService> sb_service_; |
| 291 scoped_refptr<MockSignatureUtil> signature_util_; | 301 scoped_refptr<MockSignatureUtil> signature_util_; |
| 292 DownloadProtectionService* download_service_; | 302 DownloadProtectionService* download_service_; |
| 293 MessageLoop msg_loop_; | 303 MessageLoop msg_loop_; |
| 294 scoped_ptr<DownloadProtectionService::DownloadCheckResult> result_; | 304 DownloadProtectionService::DownloadCheckResult result_; |
| 305 bool has_result_; | |
|
Scott Hess - ex-Googler
2013/01/17 19:24:42
Yeah, I think that improved it. A pointer to an e
| |
| 295 scoped_ptr<content::TestBrowserThread> io_thread_; | 306 scoped_ptr<content::TestBrowserThread> io_thread_; |
| 296 scoped_ptr<content::TestBrowserThread> ui_thread_; | 307 scoped_ptr<content::TestBrowserThread> ui_thread_; |
| 297 FilePath testdata_path_; | 308 FilePath testdata_path_; |
| 298 }; | 309 }; |
| 299 | 310 |
| 300 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 311 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
| 301 DownloadProtectionService::DownloadInfo info; | 312 DownloadProtectionService::DownloadInfo info; |
| 302 download_service_->CheckClientDownload( | 313 download_service_->CheckClientDownload( |
| 303 info, | 314 info, |
| 304 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 315 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 305 base::Unretained(this))); | 316 base::Unretained(this))); |
| 306 msg_loop_.Run(); | 317 msg_loop_.Run(); |
| 307 ExpectResult(DownloadProtectionService::SAFE); | 318 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 308 | 319 |
| 309 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 320 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 310 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 321 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 311 info.download_url_chain.push_back(GURL("file://www.google.com/")); | 322 info.download_url_chain.push_back(GURL("file://www.google.com/")); |
| 312 download_service_->CheckClientDownload( | 323 download_service_->CheckClientDownload( |
| 313 info, | 324 info, |
| 314 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 325 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 315 base::Unretained(this))); | 326 base::Unretained(this))); |
| 316 msg_loop_.Run(); | 327 msg_loop_.Run(); |
| 317 ExpectResult(DownloadProtectionService::SAFE); | 328 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 318 } | 329 } |
| 319 | 330 |
| 320 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { | 331 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { |
| 321 DownloadProtectionService::DownloadInfo info; | 332 DownloadProtectionService::DownloadInfo info; |
| 322 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 333 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 323 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 334 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 324 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 335 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
| 325 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); | 336 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); |
| 326 info.referrer_url = GURL("http://www.google.com/"); | 337 info.referrer_url = GURL("http://www.google.com/"); |
| 327 | 338 |
| 328 EXPECT_CALL(*sb_service_->mock_database_manager(), | 339 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 329 MatchDownloadWhitelistUrl(_)) | 340 MatchDownloadWhitelistUrl(_)) |
| 330 .WillRepeatedly(Return(false)); | 341 .WillRepeatedly(Return(false)); |
| 331 EXPECT_CALL(*sb_service_->mock_database_manager(), | 342 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 332 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) | 343 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) |
| 333 .WillRepeatedly(Return(true)); | 344 .WillRepeatedly(Return(true)); |
| 334 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(2); | 345 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(2); |
| 335 | 346 |
| 336 download_service_->CheckClientDownload( | 347 download_service_->CheckClientDownload( |
| 337 info, | 348 info, |
| 338 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 349 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 339 base::Unretained(this))); | 350 base::Unretained(this))); |
| 340 msg_loop_.Run(); | 351 msg_loop_.Run(); |
| 341 ExpectResult(DownloadProtectionService::SAFE); | 352 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 342 | 353 |
| 343 // Check that the referrer is matched against the whitelist. | 354 // Check that the referrer is matched against the whitelist. |
| 344 info.download_url_chain.pop_back(); | 355 info.download_url_chain.pop_back(); |
| 345 info.referrer_url = GURL("http://www.google.com/a.exe"); | 356 info.referrer_url = GURL("http://www.google.com/a.exe"); |
| 346 download_service_->CheckClientDownload( | 357 download_service_->CheckClientDownload( |
| 347 info, | 358 info, |
| 348 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 359 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 349 base::Unretained(this))); | 360 base::Unretained(this))); |
| 350 msg_loop_.Run(); | 361 msg_loop_.Run(); |
| 351 ExpectResult(DownloadProtectionService::SAFE); | 362 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 352 } | 363 } |
| 353 | 364 |
| 354 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 365 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
| 355 net::FakeURLFetcherFactory factory; | 366 net::FakeURLFetcherFactory factory; |
| 356 // HTTP request will fail. | 367 // HTTP request will fail. |
| 357 factory.SetFakeResponse( | 368 factory.SetFakeResponse( |
| 358 DownloadProtectionService::GetDownloadRequestUrl(), "", false); | 369 DownloadProtectionService::GetDownloadRequestUrl(), "", false); |
| 359 | 370 |
| 360 DownloadProtectionService::DownloadInfo info; | 371 DownloadProtectionService::DownloadInfo info; |
| 361 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 372 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 362 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 373 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 363 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 374 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 364 info.referrer_url = GURL("http://www.google.com/"); | 375 info.referrer_url = GURL("http://www.google.com/"); |
| 365 | 376 |
| 366 EXPECT_CALL(*sb_service_->mock_database_manager(), | 377 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 367 MatchDownloadWhitelistUrl(_)) | 378 MatchDownloadWhitelistUrl(_)) |
| 368 .WillRepeatedly(Return(false)); | 379 .WillRepeatedly(Return(false)); |
| 369 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 380 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| 370 | 381 |
| 371 download_service_->CheckClientDownload( | 382 download_service_->CheckClientDownload( |
| 372 info, | 383 info, |
| 373 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 384 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 374 base::Unretained(this))); | 385 base::Unretained(this))); |
| 375 msg_loop_.Run(); | 386 msg_loop_.Run(); |
| 376 ExpectResult(DownloadProtectionService::SAFE); | 387 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 377 } | 388 } |
| 378 | 389 |
| 379 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { | 390 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { |
| 380 ClientDownloadResponse response; | 391 ClientDownloadResponse response; |
| 381 response.set_verdict(ClientDownloadResponse::SAFE); | 392 response.set_verdict(ClientDownloadResponse::SAFE); |
| 382 net::FakeURLFetcherFactory factory; | 393 net::FakeURLFetcherFactory factory; |
| 383 // Empty response means SAFE. | 394 // Empty response means SAFE. |
| 384 factory.SetFakeResponse( | 395 factory.SetFakeResponse( |
| 385 DownloadProtectionService::GetDownloadRequestUrl(), | 396 DownloadProtectionService::GetDownloadRequestUrl(), |
| 386 response.SerializeAsString(), | 397 response.SerializeAsString(), |
| 387 true); | 398 true); |
| 388 | 399 |
| 389 DownloadProtectionService::DownloadInfo info; | 400 DownloadProtectionService::DownloadInfo info; |
| 390 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 401 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 391 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 402 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 392 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 403 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 393 info.referrer_url = GURL("http://www.google.com/"); | 404 info.referrer_url = GURL("http://www.google.com/"); |
| 394 | 405 |
| 395 EXPECT_CALL(*sb_service_->mock_database_manager(), | 406 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 396 MatchDownloadWhitelistUrl(_)) | 407 MatchDownloadWhitelistUrl(_)) |
| 397 .WillRepeatedly(Return(false)); | 408 .WillRepeatedly(Return(false)); |
| 398 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(4); | 409 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(4); |
| 399 | 410 |
| 400 download_service_->CheckClientDownload( | 411 download_service_->CheckClientDownload( |
| 401 info, | 412 info, |
| 402 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 413 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 403 base::Unretained(this))); | 414 base::Unretained(this))); |
| 404 msg_loop_.Run(); | 415 msg_loop_.Run(); |
| 405 ExpectResult(DownloadProtectionService::SAFE); | 416 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 406 | 417 |
| 407 // Invalid response should be safe too. | 418 // Invalid response should be safe too. |
| 408 response.Clear(); | 419 response.Clear(); |
| 409 factory.SetFakeResponse( | 420 factory.SetFakeResponse( |
| 410 DownloadProtectionService::GetDownloadRequestUrl(), | 421 DownloadProtectionService::GetDownloadRequestUrl(), |
| 411 response.SerializePartialAsString(), | 422 response.SerializePartialAsString(), |
| 412 true); | 423 true); |
| 413 | 424 |
| 414 download_service_->CheckClientDownload( | 425 download_service_->CheckClientDownload( |
| 415 info, | 426 info, |
| 416 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 427 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 417 base::Unretained(this))); | 428 base::Unretained(this))); |
| 418 msg_loop_.Run(); | 429 msg_loop_.Run(); |
| 419 ExpectResult(DownloadProtectionService::SAFE); | 430 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 420 | 431 |
| 421 // If the response is dangerous the result should also be marked as dangerous. | 432 // If the response is dangerous the result should also be marked as dangerous. |
| 422 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 433 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 423 factory.SetFakeResponse( | 434 factory.SetFakeResponse( |
| 424 DownloadProtectionService::GetDownloadRequestUrl(), | 435 DownloadProtectionService::GetDownloadRequestUrl(), |
| 425 response.SerializeAsString(), | 436 response.SerializeAsString(), |
| 426 true); | 437 true); |
| 427 | 438 |
| 428 download_service_->CheckClientDownload( | 439 download_service_->CheckClientDownload( |
| 429 info, | 440 info, |
| 430 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 441 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 431 base::Unretained(this))); | 442 base::Unretained(this))); |
| 432 msg_loop_.Run(); | 443 msg_loop_.Run(); |
| 433 #if defined(OS_WIN) | 444 #if defined(OS_WIN) |
| 434 ExpectResult(DownloadProtectionService::DANGEROUS); | 445 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 435 #else | 446 #else |
| 436 ExpectResult(DownloadProtectionService::SAFE); | 447 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 437 #endif | 448 #endif |
| 438 | 449 |
| 439 // If the response is uncommon the result should also be marked as uncommon. | 450 // If the response is uncommon the result should also be marked as uncommon. |
| 440 response.set_verdict(ClientDownloadResponse::UNCOMMON); | 451 response.set_verdict(ClientDownloadResponse::UNCOMMON); |
| 441 factory.SetFakeResponse( | 452 factory.SetFakeResponse( |
| 442 DownloadProtectionService::GetDownloadRequestUrl(), | 453 DownloadProtectionService::GetDownloadRequestUrl(), |
| 443 response.SerializeAsString(), | 454 response.SerializeAsString(), |
| 444 true); | 455 true); |
| 445 | 456 |
| 446 download_service_->CheckClientDownload( | 457 download_service_->CheckClientDownload( |
| 447 info, | 458 info, |
| 448 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 459 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 449 base::Unretained(this))); | 460 base::Unretained(this))); |
| 450 msg_loop_.Run(); | 461 msg_loop_.Run(); |
| 451 #if defined(OS_WIN) | 462 #if defined(OS_WIN) |
| 452 ExpectResult(DownloadProtectionService::UNCOMMON); | 463 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); |
| 453 #else | 464 #else |
| 454 ExpectResult(DownloadProtectionService::SAFE); | 465 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 455 #endif | 466 #endif |
| 456 } | 467 } |
| 457 | 468 |
| 458 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 469 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
| 459 ClientDownloadResponse response; | 470 ClientDownloadResponse response; |
| 460 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 471 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 461 net::FakeURLFetcherFactory factory; | 472 net::FakeURLFetcherFactory factory; |
| 462 factory.SetFakeResponse( | 473 factory.SetFakeResponse( |
| 463 DownloadProtectionService::GetDownloadRequestUrl(), | 474 DownloadProtectionService::GetDownloadRequestUrl(), |
| 464 response.SerializeAsString(), | 475 response.SerializeAsString(), |
| 465 true); | 476 true); |
| 466 | 477 |
| 467 DownloadProtectionService::DownloadInfo info; | 478 DownloadProtectionService::DownloadInfo info; |
| 468 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 479 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 469 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 480 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 470 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); | 481 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); |
| 471 info.referrer_url = GURL("http://www.google.com/"); | 482 info.referrer_url = GURL("http://www.google.com/"); |
| 472 | 483 |
| 473 EXPECT_CALL(*sb_service_->mock_database_manager(), | 484 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 474 MatchDownloadWhitelistUrl(_)) | 485 MatchDownloadWhitelistUrl(_)) |
| 475 .WillRepeatedly(Return(false)); | 486 .WillRepeatedly(Return(false)); |
| 476 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1); | 487 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1); |
| 477 | 488 |
| 478 download_service_->CheckClientDownload( | 489 download_service_->CheckClientDownload( |
| 479 info, | 490 info, |
| 480 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 491 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 481 base::Unretained(this))); | 492 base::Unretained(this))); |
| 482 msg_loop_.Run(); | 493 msg_loop_.Run(); |
| 483 #if defined(OS_WIN) | 494 #if defined(OS_WIN) |
| 484 ExpectResult(DownloadProtectionService::DANGEROUS); | 495 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 485 #else | 496 #else |
| 486 ExpectResult(DownloadProtectionService::SAFE); | 497 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 487 #endif | 498 #endif |
| 488 } | 499 } |
| 489 | 500 |
| 490 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { | 501 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { |
| 491 ClientDownloadResponse response; | 502 ClientDownloadResponse response; |
| 492 response.set_verdict(ClientDownloadResponse::SAFE); | 503 response.set_verdict(ClientDownloadResponse::SAFE); |
| 493 net::FakeURLFetcherFactory factory; | 504 net::FakeURLFetcherFactory factory; |
| 494 // Empty response means SAFE. | 505 // Empty response means SAFE. |
| 495 factory.SetFakeResponse( | 506 factory.SetFakeResponse( |
| 496 DownloadProtectionService::GetDownloadRequestUrl(), | 507 DownloadProtectionService::GetDownloadRequestUrl(), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 514 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 525 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( |
| 515 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), | 526 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), |
| 516 file_contents.data(), file_contents.size())); | 527 file_contents.data(), file_contents.size())); |
| 517 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); | 528 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); |
| 518 | 529 |
| 519 download_service_->CheckClientDownload( | 530 download_service_->CheckClientDownload( |
| 520 info, | 531 info, |
| 521 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 532 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 522 base::Unretained(this))); | 533 base::Unretained(this))); |
| 523 msg_loop_.Run(); | 534 msg_loop_.Run(); |
| 524 ExpectResult(DownloadProtectionService::SAFE); | 535 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 525 Mock::VerifyAndClearExpectations(sb_service_); | 536 Mock::VerifyAndClearExpectations(sb_service_); |
| 526 Mock::VerifyAndClearExpectations(signature_util_); | 537 Mock::VerifyAndClearExpectations(signature_util_); |
| 527 | 538 |
| 528 // Now check with an executable in the zip file as well. | 539 // Now check with an executable in the zip file as well. |
| 529 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 540 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( |
| 530 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), | 541 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), |
| 531 file_contents.data(), file_contents.size())); | 542 file_contents.data(), file_contents.size())); |
| 532 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); | 543 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); |
| 533 | 544 |
| 534 EXPECT_CALL(*sb_service_->mock_database_manager(), | 545 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 535 MatchDownloadWhitelistUrl(_)) | 546 MatchDownloadWhitelistUrl(_)) |
| 536 .WillRepeatedly(Return(false)); | 547 .WillRepeatedly(Return(false)); |
| 537 | 548 |
| 538 download_service_->CheckClientDownload( | 549 download_service_->CheckClientDownload( |
| 539 info, | 550 info, |
| 540 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 551 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 541 base::Unretained(this))); | 552 base::Unretained(this))); |
| 542 msg_loop_.Run(); | 553 msg_loop_.Run(); |
| 543 ExpectResult(DownloadProtectionService::SAFE); | 554 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 544 Mock::VerifyAndClearExpectations(signature_util_); | 555 Mock::VerifyAndClearExpectations(signature_util_); |
| 545 | 556 |
| 546 // If the response is dangerous the result should also be marked as | 557 // If the response is dangerous the result should also be marked as |
| 547 // dangerous. | 558 // dangerous. |
| 548 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 559 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 549 factory.SetFakeResponse( | 560 factory.SetFakeResponse( |
| 550 DownloadProtectionService::GetDownloadRequestUrl(), | 561 DownloadProtectionService::GetDownloadRequestUrl(), |
| 551 response.SerializeAsString(), | 562 response.SerializeAsString(), |
| 552 true); | 563 true); |
| 553 | 564 |
| 554 download_service_->CheckClientDownload( | 565 download_service_->CheckClientDownload( |
| 555 info, | 566 info, |
| 556 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 567 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 557 base::Unretained(this))); | 568 base::Unretained(this))); |
| 558 msg_loop_.Run(); | 569 msg_loop_.Run(); |
| 559 #if defined(OS_WIN) | 570 #if defined(OS_WIN) |
| 560 ExpectResult(DownloadProtectionService::DANGEROUS); | 571 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 561 #else | 572 #else |
| 562 ExpectResult(DownloadProtectionService::SAFE); | 573 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 563 #endif | 574 #endif |
| 564 Mock::VerifyAndClearExpectations(signature_util_); | 575 Mock::VerifyAndClearExpectations(signature_util_); |
| 565 } | 576 } |
| 566 | 577 |
| 567 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 578 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { |
| 568 base::ScopedTempDir download_dir; | 579 base::ScopedTempDir download_dir; |
| 569 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 580 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 570 | 581 |
| 571 DownloadProtectionService::DownloadInfo info; | 582 DownloadProtectionService::DownloadInfo info; |
| 572 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); | 583 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); |
| 573 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); | 584 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); |
| 574 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 585 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
| 575 info.referrer_url = GURL("http://www.google.com/"); | 586 info.referrer_url = GURL("http://www.google.com/"); |
| 576 | 587 |
| 577 std::string file_contents = "corrupt zip file"; | 588 std::string file_contents = "corrupt zip file"; |
| 578 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 589 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( |
| 579 download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")), | 590 download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")), |
| 580 file_contents.data(), file_contents.size())); | 591 file_contents.data(), file_contents.size())); |
| 581 | 592 |
| 582 download_service_->CheckClientDownload( | 593 download_service_->CheckClientDownload( |
| 583 info, | 594 info, |
| 584 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 595 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 585 base::Unretained(this))); | 596 base::Unretained(this))); |
| 586 msg_loop_.Run(); | 597 msg_loop_.Run(); |
| 587 ExpectResult(DownloadProtectionService::SAFE); | 598 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 588 Mock::VerifyAndClearExpectations(sb_service_); | 599 Mock::VerifyAndClearExpectations(sb_service_); |
| 589 Mock::VerifyAndClearExpectations(signature_util_); | 600 Mock::VerifyAndClearExpectations(signature_util_); |
| 590 } | 601 } |
| 591 | 602 |
| 592 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { | 603 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { |
| 593 ClientDownloadResponse response; | 604 ClientDownloadResponse response; |
| 594 // Even if the server verdict is dangerous we should return SAFE because | 605 // Even if the server verdict is dangerous we should return SAFE because |
| 595 // DownloadProtectionService::IsSupportedDownload() will return false | 606 // DownloadProtectionService::IsSupportedDownload() will return false |
| 596 // for crx downloads. | 607 // for crx downloads. |
| 597 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 608 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 612 MatchDownloadWhitelistUrl(_)) | 623 MatchDownloadWhitelistUrl(_)) |
| 613 .WillRepeatedly(Return(false)); | 624 .WillRepeatedly(Return(false)); |
| 614 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1); | 625 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1); |
| 615 | 626 |
| 616 EXPECT_FALSE(download_service_->IsSupportedDownload(info)); | 627 EXPECT_FALSE(download_service_->IsSupportedDownload(info)); |
| 617 download_service_->CheckClientDownload( | 628 download_service_->CheckClientDownload( |
| 618 info, | 629 info, |
| 619 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 630 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 620 base::Unretained(this))); | 631 base::Unretained(this))); |
| 621 msg_loop_.Run(); | 632 msg_loop_.Run(); |
| 622 ExpectResult(DownloadProtectionService::SAFE); | 633 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 623 } | 634 } |
| 624 | 635 |
| 625 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 636 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 626 net::TestURLFetcherFactory factory; | 637 net::TestURLFetcherFactory factory; |
| 627 | 638 |
| 628 DownloadProtectionService::DownloadInfo info; | 639 DownloadProtectionService::DownloadInfo info; |
| 629 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); | 640 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); |
| 630 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); | 641 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); |
| 631 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 642 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
| 632 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 643 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 // CheckClientDownload must still be called. | 769 // CheckClientDownload must still be called. |
| 759 EXPECT_CALL(*sb_service_->mock_database_manager(), | 770 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 760 CheckDownloadUrl(ContainerEq(info.download_url_chain), | 771 CheckDownloadUrl(ContainerEq(info.download_url_chain), |
| 761 NotNull())) | 772 NotNull())) |
| 762 .WillOnce(Return(true)); | 773 .WillOnce(Return(true)); |
| 763 download_service_->CheckDownloadUrl( | 774 download_service_->CheckDownloadUrl( |
| 764 info, | 775 info, |
| 765 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 776 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 766 base::Unretained(this))); | 777 base::Unretained(this))); |
| 767 msg_loop_.Run(); | 778 msg_loop_.Run(); |
| 768 ExpectResult(DownloadProtectionService::SAFE); | 779 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 769 Mock::VerifyAndClearExpectations(sb_service_); | 780 Mock::VerifyAndClearExpectations(sb_service_); |
| 770 | 781 |
| 771 EXPECT_CALL(*sb_service_->mock_database_manager(), | 782 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 772 CheckDownloadUrl(ContainerEq(info.download_url_chain), | 783 CheckDownloadUrl(ContainerEq(info.download_url_chain), |
| 773 NotNull())) | 784 NotNull())) |
| 774 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), | 785 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), |
| 775 Return(false))); | 786 Return(false))); |
| 776 download_service_->CheckDownloadUrl( | 787 download_service_->CheckDownloadUrl( |
| 777 info, | 788 info, |
| 778 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 789 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 779 base::Unretained(this))); | 790 base::Unretained(this))); |
| 780 msg_loop_.Run(); | 791 msg_loop_.Run(); |
| 781 ExpectResult(DownloadProtectionService::SAFE); | 792 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 782 Mock::VerifyAndClearExpectations(sb_service_); | 793 Mock::VerifyAndClearExpectations(sb_service_); |
| 783 | 794 |
| 784 EXPECT_CALL(*sb_service_->mock_database_manager(), | 795 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 785 CheckDownloadUrl(ContainerEq(info.download_url_chain), | 796 CheckDownloadUrl(ContainerEq(info.download_url_chain), |
| 786 NotNull())) | 797 NotNull())) |
| 787 .WillOnce(DoAll( | 798 .WillOnce(DoAll( |
| 788 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), | 799 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), |
| 789 Return(false))); | 800 Return(false))); |
| 790 download_service_->CheckDownloadUrl( | 801 download_service_->CheckDownloadUrl( |
| 791 info, | 802 info, |
| 792 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 803 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 793 base::Unretained(this))); | 804 base::Unretained(this))); |
| 794 msg_loop_.Run(); | 805 msg_loop_.Run(); |
| 795 ExpectResult(DownloadProtectionService::SAFE); | 806 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 796 Mock::VerifyAndClearExpectations(sb_service_); | 807 Mock::VerifyAndClearExpectations(sb_service_); |
| 797 | 808 |
| 798 EXPECT_CALL(*sb_service_->mock_database_manager(), | 809 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 799 CheckDownloadUrl(ContainerEq(info.download_url_chain), | 810 CheckDownloadUrl(ContainerEq(info.download_url_chain), |
| 800 NotNull())) | 811 NotNull())) |
| 801 .WillOnce(DoAll( | 812 .WillOnce(DoAll( |
| 802 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), | 813 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), |
| 803 Return(false))); | 814 Return(false))); |
| 804 download_service_->CheckDownloadUrl( | 815 download_service_->CheckDownloadUrl( |
| 805 info, | 816 info, |
| 806 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 817 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 807 base::Unretained(this))); | 818 base::Unretained(this))); |
| 808 msg_loop_.Run(); | 819 msg_loop_.Run(); |
| 809 ExpectResult(DownloadProtectionService::DANGEROUS); | 820 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 810 } | 821 } |
| 811 | 822 |
| 812 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { | 823 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { |
| 813 net::TestURLFetcherFactory factory; | 824 net::TestURLFetcherFactory factory; |
| 814 | 825 |
| 815 DownloadProtectionService::DownloadInfo info; | 826 DownloadProtectionService::DownloadInfo info; |
| 816 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 827 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
| 817 info.referrer_url = GURL("http://www.google.com/"); | 828 info.referrer_url = GURL("http://www.google.com/"); |
| 818 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 829 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 819 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 830 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 820 | 831 |
| 821 EXPECT_CALL(*sb_service_->mock_database_manager(), | 832 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 822 MatchDownloadWhitelistUrl(_)) | 833 MatchDownloadWhitelistUrl(_)) |
| 823 .WillRepeatedly(Return(false)); | 834 .WillRepeatedly(Return(false)); |
| 824 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 835 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| 825 | 836 |
| 826 download_service_->download_request_timeout_ms_ = 10; | 837 download_service_->download_request_timeout_ms_ = 10; |
| 827 download_service_->CheckClientDownload( | 838 download_service_->CheckClientDownload( |
| 828 info, | 839 info, |
| 829 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 840 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 830 base::Unretained(this))); | 841 base::Unretained(this))); |
| 831 | 842 |
| 832 // The request should time out because the HTTP request hasn't returned | 843 // The request should time out because the HTTP request hasn't returned |
| 833 // anything yet. | 844 // anything yet. |
| 834 msg_loop_.Run(); | 845 msg_loop_.Run(); |
| 835 ExpectResult(DownloadProtectionService::SAFE); | 846 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 836 } | 847 } |
| 837 | 848 |
| 838 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { | 849 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { |
| 839 // We'll pass this cert in as the "issuer", even though it isn't really | 850 // We'll pass this cert in as the "issuer", even though it isn't really |
| 840 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care | 851 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care |
| 841 // about this. | 852 // about this. |
| 842 scoped_refptr<net::X509Certificate> issuer_cert( | 853 scoped_refptr<net::X509Certificate> issuer_cert( |
| 843 ReadTestCertificate("issuer.pem")); | 854 ReadTestCertificate("issuer.pem")); |
| 844 ASSERT_TRUE(issuer_cert.get()); | 855 ASSERT_TRUE(issuer_cert.get()); |
| 845 std::string cert_base = "cert/" + base::HexEncode( | 856 std::string cert_base = "cert/" + base::HexEncode( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); | 917 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); |
| 907 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 918 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
| 908 | 919 |
| 909 cert = ReadTestCertificate("test_c.pem"); | 920 cert = ReadTestCertificate("test_c.pem"); |
| 910 ASSERT_TRUE(cert.get()); | 921 ASSERT_TRUE(cert.get()); |
| 911 whitelist_strings.clear(); | 922 whitelist_strings.clear(); |
| 912 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); | 923 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); |
| 913 EXPECT_THAT(whitelist_strings, ElementsAre()); | 924 EXPECT_THAT(whitelist_strings, ElementsAre()); |
| 914 } | 925 } |
| 915 } // namespace safe_browsing | 926 } // namespace safe_browsing |
| OLD | NEW |