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

Side by Side Diff: content/browser/fileapi/sandbox_file_system_backend_delegate_unittest.cc

Issue 2813353003: Move some File API backend unit tests next to the files that they cover. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
6
7 #include <memory>
8
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/test/scoped_task_environment.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "storage/browser/fileapi/file_system_url.h"
14 #include "storage/browser/test/test_file_system_options.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17
18 using storage::FileSystemURL;
19
20 namespace content {
21
22 namespace {
23
24 FileSystemURL CreateFileSystemURL(const char* path) {
25 const GURL kOrigin("http://foo/");
26 return storage::FileSystemURL::CreateForTest(
27 kOrigin,
28 storage::kFileSystemTypeTemporary,
29 base::FilePath::FromUTF8Unsafe(path));
30 }
31
32 } // namespace
33
34 class SandboxFileSystemBackendDelegateTest : public testing::Test {
35 protected:
36 void SetUp() override {
37 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
38 delegate_.reset(new storage::SandboxFileSystemBackendDelegate(
39 NULL /* quota_manager_proxy */,
40 base::ThreadTaskRunnerHandle::Get().get(), data_dir_.GetPath(),
41 NULL /* special_storage_policy */, CreateAllowFileAccessOptions()));
42 }
43
44 bool IsAccessValid(const FileSystemURL& url) const {
45 return delegate_->IsAccessValid(url);
46 }
47
48 base::ScopedTempDir data_dir_;
49 base::test::ScopedTaskEnvironment scoped_task_environment_;
50 std::unique_ptr<storage::SandboxFileSystemBackendDelegate> delegate_;
51 };
52
53 TEST_F(SandboxFileSystemBackendDelegateTest, IsAccessValid) {
54 // Normal case.
55 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("a")));
56
57 // Access to a path with parent references ('..') should be disallowed.
58 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("a/../b")));
59
60 // Access from non-allowed scheme should be disallowed.
61 EXPECT_FALSE(IsAccessValid(
62 FileSystemURL::CreateForTest(GURL("unknown://bar"),
63 storage::kFileSystemTypeTemporary,
64 base::FilePath::FromUTF8Unsafe("foo"))));
65
66 // Access with restricted name should be disallowed.
67 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(".")));
68 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("..")));
69
70 // This is also disallowed due to Windows XP parent path handling.
71 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("...")));
72
73 // These are identified as unsafe cases due to weird path handling
74 // on Windows.
75 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(" ..")));
76 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(".. ")));
77
78 // Similar but safe cases.
79 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(" .")));
80 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(". ")));
81 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("b.")));
82 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(".b")));
83
84 // A path that looks like a drive letter.
85 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("c:")));
86 }
87
88 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698