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

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

Issue 750773003: Safebrowsing download protection: also check blob URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 865
866 #if defined(OS_WIN) || defined(OS_MACOSX) 866 #if defined(OS_WIN) || defined(OS_MACOSX)
867 // OSX sends pings for evaluation purposes. 867 // OSX sends pings for evaluation purposes.
868 EXPECT_TRUE(HasClientDownloadRequest()); 868 EXPECT_TRUE(HasClientDownloadRequest());
869 ClearClientDownloadRequest(); 869 ClearClientDownloadRequest();
870 #else 870 #else
871 EXPECT_FALSE(HasClientDownloadRequest()); 871 EXPECT_FALSE(HasClientDownloadRequest());
872 #endif 872 #endif
873 } 873 }
874 874
875 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) {
876 ClientDownloadResponse response;
877 response.set_verdict(ClientDownloadResponse::DANGEROUS);
878 net::FakeURLFetcherFactory factory(NULL);
879 factory.SetFakeResponse(DownloadProtectionService::GetDownloadRequestUrl(),
880 response.SerializeAsString(), net::HTTP_OK,
881 net::URLRequestStatus::SUCCESS);
882
883 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
884 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
885 std::vector<GURL> url_chain;
886 url_chain.push_back(
887 GURL("blob:http://www.evil.com/50b85f60-71e4-11e4-82f8-0800200c9a66"));
888 GURL referrer("http://www.google.com/");
889 std::string hash = "hash";
890
891 content::MockDownloadItem item;
892 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
893 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
894 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
895 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
896 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL()));
897 EXPECT_CALL(item, GetTabReferrerUrl())
898 .WillRepeatedly(ReturnRef(GURL::EmptyGURL()));
899 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
900 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
901 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
902 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
903
904 EXPECT_CALL(*sb_service_->mock_database_manager(),
905 MatchDownloadWhitelistUrl(_)).WillRepeatedly(Return(false));
906 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(a_tmp, _))
907 .Times(1);
908 EXPECT_CALL(*binary_feature_extractor_.get(), ExtractImageHeaders(a_tmp, _))
909 .Times(1);
910
911 download_service_->CheckClientDownload(
912 &item,
913 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
914 base::Unretained(this)));
915 MessageLoop::current()->Run();
916 #if defined(OS_WIN)
917 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
918 #else
919 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
920 #endif
921
922 #if defined(OS_WIN) || defined(OS_MACOSX)
923 // OSX sends pings for evaluation purposes.
924 EXPECT_TRUE(HasClientDownloadRequest());
925 ClearClientDownloadRequest();
926 #else
927 EXPECT_FALSE(HasClientDownloadRequest());
928 #endif
929 }
930
875 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { 931 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
876 ClientDownloadResponse response; 932 ClientDownloadResponse response;
877 response.set_verdict(ClientDownloadResponse::SAFE); 933 response.set_verdict(ClientDownloadResponse::SAFE);
878 net::FakeURLFetcherFactory factory(NULL); 934 net::FakeURLFetcherFactory factory(NULL);
879 // Empty response means SAFE. 935 // Empty response means SAFE.
880 factory.SetFakeResponse( 936 factory.SetFakeResponse(
881 DownloadProtectionService::GetDownloadRequestUrl(), 937 DownloadProtectionService::GetDownloadRequestUrl(),
882 response.SerializeAsString(), 938 response.SerializeAsString(),
883 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 939 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
884 940
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1820 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1765 1821
1766 cert = ReadTestCertificate("test_c.pem"); 1822 cert = ReadTestCertificate("test_c.pem");
1767 ASSERT_TRUE(cert.get()); 1823 ASSERT_TRUE(cert.get());
1768 whitelist_strings.clear(); 1824 whitelist_strings.clear();
1769 GetCertificateWhitelistStrings( 1825 GetCertificateWhitelistStrings(
1770 *cert.get(), *issuer_cert.get(), &whitelist_strings); 1826 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1771 EXPECT_THAT(whitelist_strings, ElementsAre()); 1827 EXPECT_THAT(whitelist_strings, ElementsAre());
1772 } 1828 }
1773 } // namespace safe_browsing 1829 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698