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

Side by Side Diff: extensions/utility/unpacker_unittest.cc

Issue 2321823002: Exclude exe files while unzipping CRXes (Closed)
Patch Set: Ignore case Created 4 years, 3 months 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
« no previous file with comments | « extensions/utility/unpacker.cc ('k') | extensions/utility/utility_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 5 #include <memory>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/pattern.h" 10 #include "base/strings/pattern.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const char kExpected[] = "Could not decode image: "; 188 const char kExpected[] = "Could not decode image: ";
189 SetupUnpacker("bad_image.crx"); 189 SetupUnpacker("bad_image.crx");
190 EXPECT_FALSE(unpacker_->Run()); 190 EXPECT_FALSE(unpacker_->Run());
191 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), 191 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(),
192 ASCIIToUTF16(kExpected), 192 ASCIIToUTF16(kExpected),
193 base::CompareCase::INSENSITIVE_ASCII)) 193 base::CompareCase::INSENSITIVE_ASCII))
194 << "Expected prefix: \"" << kExpected << "\", actual error: \"" 194 << "Expected prefix: \"" << kExpected << "\", actual error: \""
195 << unpacker_->error_message() << "\""; 195 << unpacker_->error_message() << "\"";
196 } 196 }
197 197
198 base::FilePath CreateEmptyTestFile(const base::FilePath& test_dir,
199 const base::FilePath& file_path) {
200 base::FilePath test_file(test_dir.Append(file_path));
201 base::FilePath temp_file;
202 EXPECT_TRUE(base::CreateTemporaryFileInDir(test_dir, &temp_file));
203 EXPECT_TRUE(base::Move(temp_file, test_file));
204 return test_file;
205 }
206
207 TEST_F(UnpackerTest, BlockedFileTypes) {
208 const struct {
209 const base::FilePath::CharType* input;
210 bool expected;
211 } cases[] = {
212 {FILE_PATH_LITERAL("foo"), true},
213 {FILE_PATH_LITERAL("foo.nexe"), true},
214 {FILE_PATH_LITERAL("foo.dll"), true},
215 {FILE_PATH_LITERAL("foo.jpg.exe"), false},
216 {FILE_PATH_LITERAL("foo.exe"), false},
217 {FILE_PATH_LITERAL("foo.EXE"), false},
218 };
219
220 base::ScopedTempDir temp_dir;
221 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
222
223 for (size_t i = 0; i < arraysize(cases); ++i) {
224 base::FilePath input(cases[i].input);
225 base::FilePath test_file(CreateEmptyTestFile(temp_dir.path(), input));
226 bool observed = Unpacker::ShouldExtractFile(test_file);
227 EXPECT_EQ(cases[i].expected, observed) << "i: " << i
228 << ", input: " << test_file.value();
229 }
230 }
231
198 } // namespace extensions 232 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/utility/unpacker.cc ('k') | extensions/utility/utility_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698