OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sandboxed_dmg_analyzer_mac.h" | 5 #include "chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.h" |
6 | 6 |
7 #include <mach-o/loader.h> | 7 #include <mach-o/loader.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/safe_browsing/archive_analyzer_results.h" | 18 #include "chrome/common/safe_browsing/archive_analyzer_results.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 actual_sha256); | 135 actual_sha256); |
135 } else { | 136 } else { |
136 ADD_FAILURE() << "Unepxected result file " << binary.file_basename(); | 137 ADD_FAILURE() << "Unepxected result file " << binary.file_basename(); |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 EXPECT_TRUE(got_executable); | 141 EXPECT_TRUE(got_executable); |
141 EXPECT_TRUE(got_dylib); | 142 EXPECT_TRUE(got_dylib); |
142 } | 143 } |
143 | 144 |
| 145 TEST_F(SandboxedDMGAnalyzerTest, AnalyzeDmgNoSignature) { |
| 146 base::FilePath unsigned_dmg; |
| 147 ASSERT_NO_FATAL_FAILURE(unsigned_dmg = GetFilePath("mach_o_in_dmg.dmg")); |
| 148 |
| 149 ArchiveAnalyzerResults results; |
| 150 AnalyzeFile(unsigned_dmg, &results); |
| 151 |
| 152 EXPECT_TRUE(results.success); |
| 153 EXPECT_EQ(0u, results.signature_blob.size()); |
| 154 EXPECT_EQ(nullptr, results.signature_blob.data()); |
| 155 } |
| 156 |
| 157 TEST_F(SandboxedDMGAnalyzerTest, AnalyzeDmgWithSignature) { |
| 158 base::FilePath signed_dmg; |
| 159 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg)); |
| 160 signed_dmg = signed_dmg.AppendASCII("safe_browsing") |
| 161 .AppendASCII("mach_o") |
| 162 .AppendASCII("signed-archive.dmg"); |
| 163 |
| 164 ArchiveAnalyzerResults results; |
| 165 AnalyzeFile(signed_dmg, &results); |
| 166 |
| 167 EXPECT_TRUE(results.success); |
| 168 EXPECT_EQ(2215u, results.signature_blob.size()); |
| 169 |
| 170 base::FilePath signed_dmg_signature; |
| 171 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg_signature)); |
| 172 signed_dmg_signature = signed_dmg_signature.AppendASCII("safe_browsing") |
| 173 .AppendASCII("mach_o") |
| 174 .AppendASCII("signed-archive-signature.data"); |
| 175 |
| 176 std::string from_file; |
| 177 base::ReadFileToString(signed_dmg_signature, &from_file); |
| 178 EXPECT_EQ(2215u, from_file.length()); |
| 179 std::string signature(results.signature_blob.begin(), |
| 180 results.signature_blob.end()); |
| 181 EXPECT_EQ(from_file, signature); |
| 182 } |
| 183 |
144 } // namespace | 184 } // namespace |
145 } // namespace safe_browsing | 185 } // namespace safe_browsing |
OLD | NEW |