| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/incident_reporting/binary_integrity_analy
zer_win.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy
zer_win.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/test/scoped_path_override.h" | 14 #include "base/test/scoped_path_override.h" |
| 15 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 15 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
| 16 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" | 16 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_version.h" | 18 #include "chrome/common/chrome_version.h" |
| 19 #include "chrome/common/safe_browsing/csd.pb.h" | 19 #include "chrome/common/safe_browsing/csd.pb.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 class BinaryIntegrityAnalyzerWinTest : public ::testing::Test { | 50 class BinaryIntegrityAnalyzerWinTest : public ::testing::Test { |
| 51 public: | 51 public: |
| 52 BinaryIntegrityAnalyzerWinTest(); | 52 BinaryIntegrityAnalyzerWinTest(); |
| 53 | 53 |
| 54 protected: | 54 protected: |
| 55 base::FilePath test_data_dir_; | 55 base::FilePath test_data_dir_; |
| 56 base::ScopedTempDir temp_dir_; | 56 base::ScopedTempDir temp_dir_; |
| 57 scoped_ptr<base::ScopedPathOverride> exe_dir_override_; | 57 std::unique_ptr<base::ScopedPathOverride> exe_dir_override_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 BinaryIntegrityAnalyzerWinTest::BinaryIntegrityAnalyzerWinTest() { | 60 BinaryIntegrityAnalyzerWinTest::BinaryIntegrityAnalyzerWinTest() { |
| 61 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 61 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 62 base::CreateDirectory(temp_dir_.path().AppendASCII(CHROME_VERSION_STRING)); | 62 base::CreateDirectory(temp_dir_.path().AppendASCII(CHROME_VERSION_STRING)); |
| 63 | 63 |
| 64 // We retrieve DIR_TEST_DATA here because it is based on DIR_EXE and we are | 64 // We retrieve DIR_TEST_DATA here because it is based on DIR_EXE and we are |
| 65 // about to override the path to the latter. | 65 // about to override the path to the latter. |
| 66 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)) | 66 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)) |
| 67 NOTREACHED(); | 67 NOTREACHED(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 97 signed_binary_path = | 97 signed_binary_path = |
| 98 signed_binary_path.Append(L"safe_browsing").Append(kSignedBinaryDll); | 98 signed_binary_path.Append(L"safe_browsing").Append(kSignedBinaryDll); |
| 99 | 99 |
| 100 base::FilePath chrome_elf_path(temp_dir_.path()); | 100 base::FilePath chrome_elf_path(temp_dir_.path()); |
| 101 chrome_elf_path = | 101 chrome_elf_path = |
| 102 chrome_elf_path.Append(TEXT(CHROME_VERSION_STRING)).Append(kChromeElfDll); | 102 chrome_elf_path.Append(TEXT(CHROME_VERSION_STRING)).Append(kChromeElfDll); |
| 103 | 103 |
| 104 ASSERT_TRUE(base::CopyFile(signed_binary_path, chrome_elf_path)); | 104 ASSERT_TRUE(base::CopyFile(signed_binary_path, chrome_elf_path)); |
| 105 | 105 |
| 106 // Run check on an integral binary. | 106 // Run check on an integral binary. |
| 107 scoped_ptr<MockIncidentReceiver> mock_receiver( | 107 std::unique_ptr<MockIncidentReceiver> mock_receiver( |
| 108 new StrictMock<MockIncidentReceiver>()); | 108 new StrictMock<MockIncidentReceiver>()); |
| 109 scoped_ptr<Incident> incident_to_clear; | 109 std::unique_ptr<Incident> incident_to_clear; |
| 110 EXPECT_CALL(*mock_receiver, DoClearIncidentForProcess(_)) | 110 EXPECT_CALL(*mock_receiver, DoClearIncidentForProcess(_)) |
| 111 .WillOnce(TakeIncident(&incident_to_clear)); | 111 .WillOnce(TakeIncident(&incident_to_clear)); |
| 112 | 112 |
| 113 VerifyBinaryIntegrity(std::move(mock_receiver)); | 113 VerifyBinaryIntegrity(std::move(mock_receiver)); |
| 114 | 114 |
| 115 ASSERT_TRUE(incident_to_clear); | 115 ASSERT_TRUE(incident_to_clear); |
| 116 ASSERT_EQ(IncidentType::BINARY_INTEGRITY, incident_to_clear->GetType()); | 116 ASSERT_EQ(IncidentType::BINARY_INTEGRITY, incident_to_clear->GetType()); |
| 117 | 117 |
| 118 // Run check on an infected binary. | 118 // Run check on an infected binary. |
| 119 ASSERT_TRUE(EraseFileContent(chrome_elf_path)); | 119 ASSERT_TRUE(EraseFileContent(chrome_elf_path)); |
| 120 | 120 |
| 121 mock_receiver.reset(new StrictMock<MockIncidentReceiver>()); | 121 mock_receiver.reset(new StrictMock<MockIncidentReceiver>()); |
| 122 scoped_ptr<Incident> incident; | 122 std::unique_ptr<Incident> incident; |
| 123 EXPECT_CALL(*mock_receiver, DoAddIncidentForProcess(_)) | 123 EXPECT_CALL(*mock_receiver, DoAddIncidentForProcess(_)) |
| 124 .WillOnce(TakeIncident(&incident)); | 124 .WillOnce(TakeIncident(&incident)); |
| 125 | 125 |
| 126 VerifyBinaryIntegrity(std::move(mock_receiver)); | 126 VerifyBinaryIntegrity(std::move(mock_receiver)); |
| 127 | 127 |
| 128 // Verify that the cleared and reported incidents have the same key. | 128 // Verify that the cleared and reported incidents have the same key. |
| 129 ASSERT_EQ(incident->GetKey(), incident_to_clear->GetKey()); | 129 ASSERT_EQ(incident->GetKey(), incident_to_clear->GetKey()); |
| 130 // Verify that the incident report contains the expected data. | 130 // Verify that the incident report contains the expected data. |
| 131 scoped_ptr<ClientIncidentReport_IncidentData> incident_data( | 131 std::unique_ptr<ClientIncidentReport_IncidentData> incident_data( |
| 132 incident->TakePayload()); | 132 incident->TakePayload()); |
| 133 ASSERT_TRUE(incident_data->has_binary_integrity()); | 133 ASSERT_TRUE(incident_data->has_binary_integrity()); |
| 134 ASSERT_TRUE(incident_data->binary_integrity().has_file_basename()); | 134 ASSERT_TRUE(incident_data->binary_integrity().has_file_basename()); |
| 135 ASSERT_EQ("chrome_elf.dll", | 135 ASSERT_EQ("chrome_elf.dll", |
| 136 incident_data->binary_integrity().file_basename()); | 136 incident_data->binary_integrity().file_basename()); |
| 137 ASSERT_TRUE(incident_data->binary_integrity().has_signature()); | 137 ASSERT_TRUE(incident_data->binary_integrity().has_signature()); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace safe_browsing | 140 } // namespace safe_browsing |
| OLD | NEW |