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

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

Issue 264923011: Add a whitelist check for nacl-nonsfi mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback, add a test Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2014 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 "chrome/common/pepper_permission_util.h"
6
7 #include <set>
8 #include <string>
9
10 #include "extensions/common/extension_builder.h"
11 #include "extensions/common/extension_set.h"
12 #include "extensions/common/id_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using chrome::IsExtensionOrSharedModuleWhitelisted;
16
17 namespace extensions {
18
19 namespace {
20
21 // Return an extension with |id| which imports a module with the given
22 // |import_id|.
23 scoped_refptr<Extension> CreateExtensionImportingModule(
24 const std::string& import_id, const std::string& id) {
25 scoped_ptr<base::DictionaryValue> manifest =
26 DictionaryBuilder()
27 .Set("name", "Has Dependent Modules")
28 .Set("version", "1.0")
29 .Set("manifest_version", 2)
30 .Set("import",
31 ListBuilder().Append(DictionaryBuilder().Set("id", import_id)))
32 .Build();
33
34 return ExtensionBuilder().SetManifest(manifest.Pass())
35 .AddFlags(Extension::FROM_WEBSTORE)
36 .SetID(id)
37 .Build();
38 }
39
40 } // namespace
41
42
43 TEST(PepperPermissionUtilTest, ExtensionWhitelisting) {
44 ExtensionSet extensions;
45 std::string id = id_util::GenerateId("whitelisted_extension");
46 scoped_ptr<base::DictionaryValue> manifest =
47 DictionaryBuilder().Set("name", "Whitelisted Extension")
48 .Set("version", "1.0")
49 .Set("manifest_version", 2)
50 .Build();
51 scoped_refptr<Extension> ext =
52 ExtensionBuilder().SetManifest(manifest.Pass())
53 .SetID(id)
54 .Build();
55 extensions.Insert(ext);
56 std::set<std::string> whitelist;
57 std::string url =
58 std::string("chrome-extension://") + id + std::string("/manifest.nmf");
59 std::string bad_scheme_url =
60 std::string("http://") + id + std::string("/manifest.nmf");
61 std::string bad_host_url =
62 std::string("chrome-extension://") + id_util::GenerateId("bad_host");
63 std::string("/manifest.nmf");
64
65 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(GURL(url),
66 &extensions,
67 whitelist));
68 whitelist.insert(id);
69 EXPECT_TRUE(IsExtensionOrSharedModuleWhitelisted(GURL(url),
70 &extensions,
71 whitelist));
72 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(GURL(bad_scheme_url),
73 &extensions,
74 whitelist));
75 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(GURL(bad_host_url),
76 &extensions,
77 whitelist));
78 }
79
80 TEST(PepperPermissionUtilTest, SharedModuleWhitelisting) {
81 ExtensionSet extensions;
82 std::string id = id_util::GenerateId("extension_id");
83 std::string bad_id = id_util::GenerateId("bad_id");
84
85 scoped_ptr<base::DictionaryValue> shared_module_manifest =
86 DictionaryBuilder()
87 .Set("name", "Whitelisted Shared Module")
88 .Set("version", "1.0")
89 .Set("manifest_version", 2)
90 .Set("export",
91 DictionaryBuilder().Set("resources",
92 ListBuilder().Append("*"))
93 .Set("whitelist",
94 ListBuilder().Append(id)))
95 .Build();
96 scoped_refptr<Extension> shared_module =
97 ExtensionBuilder().SetManifest(shared_module_manifest.Pass())
98 .Build();
99
100 scoped_refptr<Extension> ext =
101 CreateExtensionImportingModule(shared_module->id(), id);
102 std::string extension_url =
103 std::string("chrome-extension://") + ext->id() + std::string("/foo.html");
104
105 std::set<std::string> whitelist;
106 // Important: whitelist *only* the shared module.
107 whitelist.insert(shared_module->id());
108
109 extensions.Insert(ext);
110 // This should fail because shared_module is not in the set of extensions.
111 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(GURL(extension_url),
112 &extensions,
113 whitelist));
114 extensions.Insert(shared_module);
115 EXPECT_TRUE(IsExtensionOrSharedModuleWhitelisted(GURL(extension_url),
116 &extensions,
117 whitelist));
118
119 scoped_refptr<Extension> bad_ext =
120 CreateExtensionImportingModule(shared_module->id(), bad_id);
121 std::string bad_extension_url =
122 std::string("chrome-extension://") + bad_ext->id() +
123 std::string("/foo.html");
124
125 extensions.Insert(bad_ext);
126 // This should fail because bad_ext is not whitelisted to use shared_module.
127 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(GURL(bad_extension_url),
128 &extensions,
129 whitelist));
130
131 }
132
133 } // namespace extensions
134
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698