OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 void TestUnzipFile(const base::FilePath::StringType& filename, | 66 void TestUnzipFile(const base::FilePath::StringType& filename, |
67 bool expect_hidden_files) { | 67 bool expect_hidden_files) { |
68 base::FilePath test_dir; | 68 base::FilePath test_dir; |
69 ASSERT_TRUE(GetTestDataDirectory(&test_dir)); | 69 ASSERT_TRUE(GetTestDataDirectory(&test_dir)); |
70 TestUnzipFile(test_dir.Append(filename), expect_hidden_files); | 70 TestUnzipFile(test_dir.Append(filename), expect_hidden_files); |
71 } | 71 } |
72 | 72 |
73 void TestUnzipFile(const base::FilePath& path, bool expect_hidden_files) { | 73 void TestUnzipFile(const base::FilePath& path, bool expect_hidden_files) { |
74 ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); | 74 ASSERT_TRUE(base::PathExists(path)) << "no file " << path.value(); |
75 ASSERT_TRUE(zip::Unzip(path, test_dir_)); | 75 ASSERT_TRUE(zip::Unzip(path, test_dir_)); |
76 | 76 |
77 base::FileEnumerator files(test_dir_, true, | 77 base::FileEnumerator files(test_dir_, true, |
78 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); | 78 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); |
79 base::FilePath next_path = files.Next(); | 79 base::FilePath next_path = files.Next(); |
80 size_t count = 0; | 80 size_t count = 0; |
81 while (!next_path.value().empty()) { | 81 while (!next_path.value().empty()) { |
82 if (next_path.value().find(FILE_PATH_LITERAL(".svn")) == | 82 if (next_path.value().find(FILE_PATH_LITERAL(".svn")) == |
83 base::FilePath::StringType::npos) { | 83 base::FilePath::StringType::npos) { |
84 EXPECT_EQ(zip_contents_.count(next_path), 1U) << | 84 EXPECT_EQ(zip_contents_.count(next_path), 1U) << |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ASSERT_TRUE(GetTestDataDirectory(&path)); | 123 ASSERT_TRUE(GetTestDataDirectory(&path)); |
124 path = path.AppendASCII("evil.zip"); | 124 path = path.AppendASCII("evil.zip"); |
125 // Unzip the zip file into a sub directory of test_dir_ so evil.zip | 125 // Unzip the zip file into a sub directory of test_dir_ so evil.zip |
126 // won't create a persistent file outside test_dir_ in case of a | 126 // won't create a persistent file outside test_dir_ in case of a |
127 // failure. | 127 // failure. |
128 base::FilePath output_dir = test_dir_.AppendASCII("out"); | 128 base::FilePath output_dir = test_dir_.AppendASCII("out"); |
129 ASSERT_FALSE(zip::Unzip(path, output_dir)); | 129 ASSERT_FALSE(zip::Unzip(path, output_dir)); |
130 base::FilePath evil_file = output_dir; | 130 base::FilePath evil_file = output_dir; |
131 evil_file = evil_file.AppendASCII( | 131 evil_file = evil_file.AppendASCII( |
132 "../levilevilevilevilevilevilevilevilevilevilevilevil"); | 132 "../levilevilevilevilevilevilevilevilevilevilevilevil"); |
133 ASSERT_FALSE(file_util::PathExists(evil_file)); | 133 ASSERT_FALSE(base::PathExists(evil_file)); |
134 } | 134 } |
135 | 135 |
136 TEST_F(ZipTest, UnzipEvil2) { | 136 TEST_F(ZipTest, UnzipEvil2) { |
137 base::FilePath path; | 137 base::FilePath path; |
138 ASSERT_TRUE(GetTestDataDirectory(&path)); | 138 ASSERT_TRUE(GetTestDataDirectory(&path)); |
139 // The zip file contains an evil file with invalid UTF-8 in its file | 139 // The zip file contains an evil file with invalid UTF-8 in its file |
140 // name. | 140 // name. |
141 path = path.AppendASCII("evil_via_invalid_utf8.zip"); | 141 path = path.AppendASCII("evil_via_invalid_utf8.zip"); |
142 // See the comment at UnzipEvil() for why we do this. | 142 // See the comment at UnzipEvil() for why we do this. |
143 base::FilePath output_dir = test_dir_.AppendASCII("out"); | 143 base::FilePath output_dir = test_dir_.AppendASCII("out"); |
144 // This should fail as it contains an evil file. | 144 // This should fail as it contains an evil file. |
145 ASSERT_FALSE(zip::Unzip(path, output_dir)); | 145 ASSERT_FALSE(zip::Unzip(path, output_dir)); |
146 base::FilePath evil_file = output_dir; | 146 base::FilePath evil_file = output_dir; |
147 evil_file = evil_file.AppendASCII("../evil.txt"); | 147 evil_file = evil_file.AppendASCII("../evil.txt"); |
148 ASSERT_FALSE(file_util::PathExists(evil_file)); | 148 ASSERT_FALSE(base::PathExists(evil_file)); |
149 } | 149 } |
150 | 150 |
151 TEST_F(ZipTest, Zip) { | 151 TEST_F(ZipTest, Zip) { |
152 base::FilePath src_dir; | 152 base::FilePath src_dir; |
153 ASSERT_TRUE(GetTestDataDirectory(&src_dir)); | 153 ASSERT_TRUE(GetTestDataDirectory(&src_dir)); |
154 src_dir = src_dir.AppendASCII("test"); | 154 src_dir = src_dir.AppendASCII("test"); |
155 | 155 |
156 base::ScopedTempDir temp_dir; | 156 base::ScopedTempDir temp_dir; |
157 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 157 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
158 base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); | 158 base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); | 198 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); |
199 // Check the path in the entry just in case. | 199 // Check the path in the entry just in case. |
200 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); | 200 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); |
201 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); | 201 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); |
202 } | 202 } |
203 } | 203 } |
204 #endif // defined(OS_POSIX) | 204 #endif // defined(OS_POSIX) |
205 | 205 |
206 } // namespace | 206 } // namespace |
207 | 207 |
OLD | NEW |