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/signature_evaluator_mac.h" | 5 #include "chrome/browser/safe_browsing/signature_evaluator_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/xattr.h> | 10 #include <sys/xattr.h> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 base::FilePath dir_exe; | 56 base::FilePath dir_exe; |
57 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dir_exe)); | 57 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dir_exe)); |
58 base::FilePath file_exe; | 58 base::FilePath file_exe; |
59 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe)); | 59 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &file_exe)); |
60 | 60 |
61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
62 } | 62 } |
63 | 63 |
64 bool SetupXattrs(const base::FilePath& path) { | 64 bool SetupXattrs(const base::FilePath& path) { |
65 char sentinel = 'A'; | 65 char sentinel = 'A'; |
66 for (const auto& xattr : xattrs) { | 66 for (auto* xattr : xattrs) { |
67 std::vector<uint8_t> buf(10); | 67 std::vector<uint8_t> buf(10); |
68 memset(&buf[0], sentinel++, buf.size()); | 68 memset(&buf[0], sentinel++, buf.size()); |
69 if (setxattr(path.value().c_str(), xattr, &buf[0], buf.size(), 0, 0) != 0) | 69 if (setxattr(path.value().c_str(), xattr, &buf[0], buf.size(), 0, 0) != 0) |
70 return false; | 70 return false; |
71 } | 71 } |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 base::FilePath testdata_path_; | 75 base::FilePath testdata_path_; |
76 base::ScopedTempDir temp_dir_; | 76 base::ScopedTempDir temp_dir_; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 EXPECT_TRUE(executable32->has_signature()); | 315 EXPECT_TRUE(executable32->has_signature()); |
316 EXPECT_TRUE(executable32->has_image_headers()); | 316 EXPECT_TRUE(executable32->has_image_headers()); |
317 | 317 |
318 EXPECT_TRUE(mainmenunib->has_relative_path()); | 318 EXPECT_TRUE(mainmenunib->has_relative_path()); |
319 EXPECT_EQ("Contents/Resources/Base.lproj/MainMenu.nib", | 319 EXPECT_EQ("Contents/Resources/Base.lproj/MainMenu.nib", |
320 mainmenunib->relative_path()); | 320 mainmenunib->relative_path()); |
321 EXPECT_TRUE(mainmenunib->has_signature()); | 321 EXPECT_TRUE(mainmenunib->has_signature()); |
322 EXPECT_EQ(6, mainmenunib->signature().xattr_size()); | 322 EXPECT_EQ(6, mainmenunib->signature().xattr_size()); |
323 // Manually convert the global xattrs array to a vector | 323 // Manually convert the global xattrs array to a vector |
324 std::vector<std::string> xattrs_known; | 324 std::vector<std::string> xattrs_known; |
325 for (const auto& xattr : xattrs) | 325 for (auto* xattr : xattrs) |
326 xattrs_known.push_back(xattr); | 326 xattrs_known.push_back(xattr); |
327 | 327 |
328 std::vector<std::string> xattrs_seen; | 328 std::vector<std::string> xattrs_seen; |
329 for (const auto& xattr : mainmenunib->signature().xattr()) { | 329 for (const auto& xattr : mainmenunib->signature().xattr()) { |
330 ASSERT_TRUE(xattr.has_key()); | 330 ASSERT_TRUE(xattr.has_key()); |
331 EXPECT_TRUE(xattr.has_value()); | 331 EXPECT_TRUE(xattr.has_value()); |
332 xattrs_seen.push_back(xattr.key()); | 332 xattrs_seen.push_back(xattr.key()); |
333 } | 333 } |
334 EXPECT_THAT(xattrs_known, ::testing::ContainerEq(xattrs_seen)); | 334 EXPECT_THAT(xattrs_known, ::testing::ContainerEq(xattrs_seen)); |
335 } | 335 } |
336 | 336 |
337 } // namespace safe_browsing | 337 } // namespace safe_browsing |
OLD | NEW |