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

Side by Side Diff: chrome/common/zip_unittest.cc

Issue 8508003: zip: Add ZipReader and rework Unzip() using the new class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a win failure Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/zip_reader_unittest.cc ('k') | no next file » | 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) 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 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ASSERT_FALSE(zip::Unzip(path, output_dir)); 106 ASSERT_FALSE(zip::Unzip(path, output_dir));
107 FilePath evil_file = output_dir; 107 FilePath evil_file = output_dir;
108 evil_file = evil_file.AppendASCII( 108 evil_file = evil_file.AppendASCII(
109 "../levilevilevilevilevilevilevilevilevilevilevilevil"); 109 "../levilevilevilevilevilevilevilevilevilevilevilevil");
110 ASSERT_FALSE(file_util::PathExists(evil_file)); 110 ASSERT_FALSE(file_util::PathExists(evil_file));
111 } 111 }
112 112
113 TEST_F(ZipTest, UnzipEvil2) { 113 TEST_F(ZipTest, UnzipEvil2) {
114 FilePath path; 114 FilePath path;
115 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 115 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
116 // The zip file contains an evil file with invalid UTF-8 in its file
117 // name.
116 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip"); 118 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip");
117 // See the comment at UnzipEvil() for why we do this. 119 // See the comment at UnzipEvil() for why we do this.
118 FilePath output_dir = test_dir_.AppendASCII("out"); 120 FilePath output_dir = test_dir_.AppendASCII("out");
119 ASSERT_TRUE(zip::Unzip(path, output_dir)); 121 // This should fail as it contains an evil file.
122 ASSERT_FALSE(zip::Unzip(path, output_dir));
120 FilePath evil_file = output_dir; 123 FilePath evil_file = output_dir;
121 evil_file = evil_file.AppendASCII("../evil.txt"); 124 evil_file = evil_file.AppendASCII("../evil.txt");
122 ASSERT_FALSE(file_util::PathExists(evil_file)); 125 ASSERT_FALSE(file_util::PathExists(evil_file));
123 } 126 }
124 127
125 TEST_F(ZipTest, Zip) { 128 TEST_F(ZipTest, Zip) {
126 FilePath src_dir; 129 FilePath src_dir;
127 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir));
128 src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); 131 src_dir = src_dir.AppendASCII("zip").AppendASCII("test");
129 132
(...skipping 12 matching lines...) Expand all
142 145
143 ScopedTempDir temp_dir; 146 ScopedTempDir temp_dir;
144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 147 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
145 FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); 148 FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
146 149
147 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false)); 150 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false));
148 TestUnzipFile(zip_file, false); 151 TestUnzipFile(zip_file, false);
149 } 152 }
150 153
151 } // namespace 154 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/zip_reader_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698