| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/common/pepper_permission_util.h" | 5 #include "chrome/common/pepper_permission_util.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 scoped_ptr<base::DictionaryValue> manifest = | 29 scoped_ptr<base::DictionaryValue> manifest = |
| 30 DictionaryBuilder() | 30 DictionaryBuilder() |
| 31 .Set("name", "Has Dependent Modules") | 31 .Set("name", "Has Dependent Modules") |
| 32 .Set("version", "1.0") | 32 .Set("version", "1.0") |
| 33 .Set("manifest_version", 2) | 33 .Set("manifest_version", 2) |
| 34 .Set("import", std::move(ListBuilder().Append(std::move( | 34 .Set("import", std::move(ListBuilder().Append(std::move( |
| 35 DictionaryBuilder().Set("id", import_id))))) | 35 DictionaryBuilder().Set("id", import_id))))) |
| 36 .Build(); | 36 .Build(); |
| 37 | 37 |
| 38 return ExtensionBuilder() | 38 return ExtensionBuilder() |
| 39 .SetManifest(manifest.Pass()) | 39 .SetManifest(std::move(manifest)) |
| 40 .AddFlags(Extension::FROM_WEBSTORE) | 40 .AddFlags(Extension::FROM_WEBSTORE) |
| 41 .SetID(id) | 41 .SetID(id) |
| 42 .Build(); | 42 .Build(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 TEST(PepperPermissionUtilTest, ExtensionWhitelisting) { | 47 TEST(PepperPermissionUtilTest, ExtensionWhitelisting) { |
| 48 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); | 48 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); |
| 49 ExtensionSet extensions; | 49 ExtensionSet extensions; |
| 50 std::string whitelisted_id = | 50 std::string whitelisted_id = |
| 51 crx_file::id_util::GenerateId("whitelisted_extension"); | 51 crx_file::id_util::GenerateId("whitelisted_extension"); |
| 52 scoped_ptr<base::DictionaryValue> manifest = | 52 scoped_ptr<base::DictionaryValue> manifest = |
| 53 DictionaryBuilder() | 53 DictionaryBuilder() |
| 54 .Set("name", "Whitelisted Extension") | 54 .Set("name", "Whitelisted Extension") |
| 55 .Set("version", "1.0") | 55 .Set("version", "1.0") |
| 56 .Set("manifest_version", 2) | 56 .Set("manifest_version", 2) |
| 57 .Build(); | 57 .Build(); |
| 58 scoped_refptr<Extension> ext = ExtensionBuilder() | 58 scoped_refptr<Extension> ext = ExtensionBuilder() |
| 59 .SetManifest(manifest.Pass()) | 59 .SetManifest(std::move(manifest)) |
| 60 .SetID(whitelisted_id) | 60 .SetID(whitelisted_id) |
| 61 .Build(); | 61 .Build(); |
| 62 extensions.Insert(ext); | 62 extensions.Insert(ext); |
| 63 std::set<std::string> whitelist; | 63 std::set<std::string> whitelist; |
| 64 std::string url = std::string("chrome-extension://") + whitelisted_id + | 64 std::string url = std::string("chrome-extension://") + whitelisted_id + |
| 65 std::string("/manifest.nmf"); | 65 std::string("/manifest.nmf"); |
| 66 std::string bad_scheme_url = | 66 std::string bad_scheme_url = |
| 67 std::string("http://") + whitelisted_id + std::string("/manifest.nmf"); | 67 std::string("http://") + whitelisted_id + std::string("/manifest.nmf"); |
| 68 std::string bad_host_url = std::string("chrome-extension://") + | 68 std::string bad_host_url = std::string("chrome-extension://") + |
| 69 crx_file::id_util::GenerateId("bad_host"); | 69 crx_file::id_util::GenerateId("bad_host"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 94 .Set("export", | 94 .Set("export", |
| 95 std::move( | 95 std::move( |
| 96 DictionaryBuilder() | 96 DictionaryBuilder() |
| 97 .Set("resources", std::move(ListBuilder().Append("*"))) | 97 .Set("resources", std::move(ListBuilder().Append("*"))) |
| 98 // Add the extension to the whitelist. This | 98 // Add the extension to the whitelist. This |
| 99 // restricts import to |whitelisted_id| only. | 99 // restricts import to |whitelisted_id| only. |
| 100 .Set("whitelist", | 100 .Set("whitelist", |
| 101 std::move(ListBuilder().Append(whitelisted_id))))) | 101 std::move(ListBuilder().Append(whitelisted_id))))) |
| 102 .Build(); | 102 .Build(); |
| 103 scoped_refptr<Extension> shared_module = | 103 scoped_refptr<Extension> shared_module = |
| 104 ExtensionBuilder().SetManifest(shared_module_manifest.Pass()).Build(); | 104 ExtensionBuilder().SetManifest(std::move(shared_module_manifest)).Build(); |
| 105 | 105 |
| 106 scoped_refptr<Extension> ext = | 106 scoped_refptr<Extension> ext = |
| 107 CreateExtensionImportingModule(shared_module->id(), whitelisted_id); | 107 CreateExtensionImportingModule(shared_module->id(), whitelisted_id); |
| 108 std::string extension_url = | 108 std::string extension_url = |
| 109 std::string("chrome-extension://") + ext->id() + std::string("/foo.html"); | 109 std::string("chrome-extension://") + ext->id() + std::string("/foo.html"); |
| 110 | 110 |
| 111 std::set<std::string> whitelist; | 111 std::set<std::string> whitelist; |
| 112 // Important: whitelist *only* the shared module. | 112 // Important: whitelist *only* the shared module. |
| 113 whitelist.insert(shared_module->id()); | 113 whitelist.insert(shared_module->id()); |
| 114 | 114 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 134 GURL(not_in_sm_whitelist_url), &extensions, whitelist)); | 134 GURL(not_in_sm_whitelist_url), &extensions, whitelist)); |
| 135 | 135 |
| 136 // Note that the whitelist should be empty after this call, so tests checking | 136 // Note that the whitelist should be empty after this call, so tests checking |
| 137 // for failure to import will fail because of this. | 137 // for failure to import will fail because of this. |
| 138 whitelist.erase(shared_module->id()); | 138 whitelist.erase(shared_module->id()); |
| 139 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( | 139 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( |
| 140 GURL(extension_url), &extensions, whitelist)); | 140 GURL(extension_url), &extensions, whitelist)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace extensions | 143 } // namespace extensions |
| OLD | NEW |