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

Side by Side Diff: webkit/fileapi/file_system_mount_point_provider_unittest.cc

Issue 12193007: Deprecate MountPointProvider::IsAccessAllowed in favor of GetPermissionPolicy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base::FilePath fix Created 7 years, 10 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 | Annotate | Revision Log
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, 94 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, },
95 { FILE_PATH_LITERAL("//etc/hosts"), false, }, 95 { FILE_PATH_LITERAL("//etc/hosts"), false, },
96 { FILE_PATH_LITERAL("foo.txt"), true, }, 96 { FILE_PATH_LITERAL("foo.txt"), true, },
97 { FILE_PATH_LITERAL("a/b/c"), true, }, 97 { FILE_PATH_LITERAL("a/b/c"), true, },
98 // Any paths that includes parent references are considered invalid. 98 // Any paths that includes parent references are considered invalid.
99 { FILE_PATH_LITERAL(".."), false, }, 99 { FILE_PATH_LITERAL(".."), false, },
100 { FILE_PATH_LITERAL("tmp/.."), false, }, 100 { FILE_PATH_LITERAL("tmp/.."), false, },
101 { FILE_PATH_LITERAL("a/b/../c/.."), false, }, 101 { FILE_PATH_LITERAL("a/b/../c/.."), false, },
102 }; 102 };
103 103
104 const struct IsRestrictedNameTest {
105 base::FilePath::StringType name;
106 bool expected_dangerous;
107 } kIsRestrictedNameTestCases[] = {
108 // Names that contain strings that used to be restricted, but are now allowed.
109 { FILE_PATH_LITERAL("con"), false, },
110 { FILE_PATH_LITERAL("Con.txt"), false, },
111 { FILE_PATH_LITERAL("Prn.png"), false, },
112 { FILE_PATH_LITERAL("AUX"), false, },
113 { FILE_PATH_LITERAL("nUl."), false, },
114 { FILE_PATH_LITERAL("coM1"), false, },
115 { FILE_PATH_LITERAL("COM3.com"), false, },
116 { FILE_PATH_LITERAL("cOM7"), false, },
117 { FILE_PATH_LITERAL("com9"), false, },
118 { FILE_PATH_LITERAL("lpT1"), false, },
119 { FILE_PATH_LITERAL("LPT4.com"), false, },
120 { FILE_PATH_LITERAL("lPT8"), false, },
121 { FILE_PATH_LITERAL("lPT9"), false, },
122 { FILE_PATH_LITERAL("com1."), false, },
123
124 // Similar cases that have always been allowed.
125 { FILE_PATH_LITERAL("con3"), false, },
126 { FILE_PATH_LITERAL("PrnImage.png"), false, },
127 { FILE_PATH_LITERAL("AUXX"), false, },
128 { FILE_PATH_LITERAL("NULL"), false, },
129 { FILE_PATH_LITERAL("coM0"), false, },
130 { FILE_PATH_LITERAL("COM.com"), false, },
131 { FILE_PATH_LITERAL("lpT0"), false, },
132 { FILE_PATH_LITERAL("LPT.com"), false, },
133
134 // Ends with period or whitespace--used to be banned, now OK.
135 { FILE_PATH_LITERAL("b "), false, },
136 { FILE_PATH_LITERAL("b\t"), false, },
137 { FILE_PATH_LITERAL("b\n"), false, },
138 { FILE_PATH_LITERAL("b\r\n"), false, },
139 { FILE_PATH_LITERAL("b."), false, },
140 { FILE_PATH_LITERAL("b.."), false, },
141
142 // Similar cases that have always been allowed.
143 { FILE_PATH_LITERAL("b c"), false, },
144 { FILE_PATH_LITERAL("b\tc"), false, },
145 { FILE_PATH_LITERAL("b\nc"), false, },
146 { FILE_PATH_LITERAL("b\r\nc"), false, },
147 { FILE_PATH_LITERAL("b c d e f"), false, },
148 { FILE_PATH_LITERAL("b.c"), false, },
149 { FILE_PATH_LITERAL("b..c"), false, },
150
151 // Name that has restricted chars in it.
152 { FILE_PATH_LITERAL("\\"), true, },
153 { FILE_PATH_LITERAL("/"), true, },
154 { FILE_PATH_LITERAL("a\\b"), true, },
155 { FILE_PATH_LITERAL("a/b"), true, },
156 { FILE_PATH_LITERAL("ab\\"), true, },
157 { FILE_PATH_LITERAL("ab/"), true, },
158 { FILE_PATH_LITERAL("\\ab"), true, },
159 { FILE_PATH_LITERAL("/ab"), true, },
160 { FILE_PATH_LITERAL("ab/.txt"), true, },
161 { FILE_PATH_LITERAL("ab\\.txt"), true, },
162
163 // Names that contain chars that were formerly restricted, now OK.
164 { FILE_PATH_LITERAL("a<b"), false, },
165 { FILE_PATH_LITERAL("a>b"), false, },
166 { FILE_PATH_LITERAL("a:b"), false, },
167 { FILE_PATH_LITERAL("a?b"), false, },
168 { FILE_PATH_LITERAL("a|b"), false, },
169 { FILE_PATH_LITERAL("ab<.txt"), false, },
170 { FILE_PATH_LITERAL("ab>.txt"), false, },
171 { FILE_PATH_LITERAL("ab:.txt"), false, },
172 { FILE_PATH_LITERAL("ab?.txt"), false, },
173 { FILE_PATH_LITERAL("ab|.txt"), false, },
174 { FILE_PATH_LITERAL("<ab"), false, },
175 { FILE_PATH_LITERAL(">ab"), false, },
176 { FILE_PATH_LITERAL(":ab"), false, },
177 { FILE_PATH_LITERAL("?ab"), false, },
178 { FILE_PATH_LITERAL("|ab"), false, },
179
180 // Names that are restricted still.
181 { FILE_PATH_LITERAL(".."), true, },
182 { FILE_PATH_LITERAL("."), true, },
183
184 // Similar but safe cases.
185 { FILE_PATH_LITERAL(" ."), false, },
186 { FILE_PATH_LITERAL(". "), false, },
187 { FILE_PATH_LITERAL(" . "), false, },
188 { FILE_PATH_LITERAL(" .."), false, },
189 { FILE_PATH_LITERAL(".. "), false, },
190 { FILE_PATH_LITERAL(" .. "), false, },
191 { FILE_PATH_LITERAL("b."), false, },
192 { FILE_PATH_LITERAL(".b"), false, },
193 };
194
195 // For External filesystem. 104 // For External filesystem.
196 const base::FilePath::CharType kMountPoint[] = FILE_PATH_LITERAL("/tmp/testing") ; 105 const base::FilePath::CharType kMountPoint[] = FILE_PATH_LITERAL("/tmp/testing") ;
197 const base::FilePath::CharType kRootPath[] = FILE_PATH_LITERAL("/tmp"); 106 const base::FilePath::CharType kRootPath[] = FILE_PATH_LITERAL("/tmp");
198 const base::FilePath::CharType kVirtualPath[] = FILE_PATH_LITERAL("testing"); 107 const base::FilePath::CharType kVirtualPath[] = FILE_PATH_LITERAL("testing");
199 108
200 } // namespace 109 } // namespace
201 110
202 class FileSystemMountPointProviderTest : public testing::Test { 111 class FileSystemMountPointProviderTest : public testing::Test {
203 public: 112 public:
204 FileSystemMountPointProviderTest() 113 FileSystemMountPointProviderTest()
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), 296 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url),
388 kRootPathFileURITestCases[i].type, 297 kRootPathFileURITestCases[i].type,
389 true /* create */, &root_path)); 298 true /* create */, &root_path));
390 base::FilePath expected = file_system_path().AppendASCII( 299 base::FilePath expected = file_system_path().AppendASCII(
391 kRootPathFileURITestCases[i].expected_path); 300 kRootPathFileURITestCases[i].expected_path);
392 EXPECT_EQ(expected.value(), root_path.value()); 301 EXPECT_EQ(expected.value(), root_path.value());
393 EXPECT_TRUE(file_util::DirectoryExists(root_path)); 302 EXPECT_TRUE(file_util::DirectoryExists(root_path));
394 } 303 }
395 } 304 }
396 305
397 TEST_F(FileSystemMountPointProviderTest, IsRestrictedName) {
398 SetupNewContext(CreateDisallowFileAccessOptions());
399 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
400 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
401 << kIsRestrictedNameTestCases[i].name);
402 base::FilePath name(kIsRestrictedNameTestCases[i].name);
403 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
404 provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name));
405 }
406 }
407
408 } // namespace fileapi 306 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_mount_point_provider.h ('k') | webkit/fileapi/isolated_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698