| OLD | NEW |
| (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 "base/memory/ref_counted.h" |
| 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/chromeos/extensions/signin_screen_policy_provider.h" |
| 8 #include "components/version_info/version_info.h" |
| 9 #include "extensions/common/extension_builder.h" |
| 10 #include "extensions/common/features/feature_channel.h" |
| 11 #include "extensions/common/features/feature_session_type.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using extensions::Extension; |
| 15 |
| 16 namespace { |
| 17 |
| 18 scoped_refptr<extensions::Extension> CreateTestApp( |
| 19 const std::string& extension_id, |
| 20 extensions::Manifest::Location location) { |
| 21 return extensions::ExtensionBuilder() |
| 22 .SetManifest( |
| 23 extensions::DictionaryBuilder() |
| 24 .Set("name", "test app") |
| 25 .Set("version", "1") |
| 26 .Set("manifest_version", 2) |
| 27 .Set("app", |
| 28 extensions::DictionaryBuilder() |
| 29 .Set("background", |
| 30 extensions::DictionaryBuilder() |
| 31 .Set("persistent", "false") |
| 32 .Set("scripts", extensions::ListBuilder() |
| 33 .Append("background.js") |
| 34 .Build()) |
| 35 .Build()) |
| 36 .Build()) |
| 37 .Set("storage", |
| 38 extensions::DictionaryBuilder() |
| 39 .Set("managed_schema", "managed_storage_schema.json") |
| 40 .Build()) |
| 41 .Set("permissions", extensions::ListBuilder() |
| 42 .Append("usb") |
| 43 .Append("alwaysOnTopWindows") |
| 44 .Build()) |
| 45 .Build()) |
| 46 .SetID(extension_id) |
| 47 .SetLocation(location) |
| 48 .Build(); |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
| 53 class SigninScreenPolicyProviderTest : public testing::Test { |
| 54 protected: |
| 55 chromeos::SigninScreenPolicyProvider provider_; |
| 56 }; |
| 57 |
| 58 TEST_F(SigninScreenPolicyProviderTest, AllowPolicyExtensionOnDev) { |
| 59 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 60 scoped_refptr<extensions::Extension> extension = |
| 61 CreateTestApp("abacabadabacabaeabacabadabacabaf", |
| 62 extensions::Manifest::Location::EXTERNAL_POLICY); |
| 63 base::string16 error; |
| 64 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error)); |
| 65 EXPECT_TRUE(error.empty()); |
| 66 } |
| 67 |
| 68 TEST_F(SigninScreenPolicyProviderTest, DenyRandomPolicyExtensionOnStable) { |
| 69 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE); |
| 70 scoped_refptr<extensions::Extension> extension = |
| 71 CreateTestApp("abacabadabacabaeabacabadabacabaf", |
| 72 extensions::Manifest::Location::EXTERNAL_POLICY); |
| 73 base::string16 error; |
| 74 EXPECT_FALSE(provider_.UserMayLoad(extension.get(), &error)); |
| 75 EXPECT_FALSE(error.empty()); |
| 76 } |
| 77 |
| 78 TEST_F(SigninScreenPolicyProviderTest, AllowEssentialExtensionOnStable) { |
| 79 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE); |
| 80 scoped_refptr<extensions::Extension> extension = |
| 81 CreateTestApp("beknehfpfkghjoafdifaflglpjkojoco" /* gnubby */, |
| 82 extensions::Manifest::Location::EXTERNAL_COMPONENT); |
| 83 base::string16 error; |
| 84 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error)); |
| 85 EXPECT_TRUE(error.empty()); |
| 86 } |
| 87 |
| 88 TEST_F(SigninScreenPolicyProviderTest, |
| 89 AllowWhitelistedExtensionViaPolicyOnStable) { |
| 90 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE); |
| 91 scoped_refptr<extensions::Extension> extension = CreateTestApp( |
| 92 "khpfeaanjngmcnplbdlpegiifgpfgdco" /* smart card connector */, |
| 93 extensions::Manifest::Location::EXTERNAL_POLICY); |
| 94 base::string16 error; |
| 95 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error)); |
| 96 EXPECT_TRUE(error.empty()); |
| 97 } |
| 98 |
| 99 TEST_F(SigninScreenPolicyProviderTest, |
| 100 DenyNonPolicyWhitelistedExtensionOnStable) { |
| 101 extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE); |
| 102 scoped_refptr<extensions::Extension> extension = CreateTestApp( |
| 103 "khpfeaanjngmcnplbdlpegiifgpfgdco" /* smart card connector */, |
| 104 extensions::Manifest::Location::EXTERNAL_COMPONENT); |
| 105 base::string16 error; |
| 106 EXPECT_FALSE(provider_.UserMayLoad(extension.get(), &error)); |
| 107 EXPECT_FALSE(error.empty()); |
| 108 } |
| 109 |
| 110 TEST_F(SigninScreenPolicyProviderTest, DenyRandomNonPolicyExtensionOnDev) { |
| 111 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 112 scoped_refptr<extensions::Extension> extension = |
| 113 CreateTestApp("abacabadabacabaeabacabadabacabaf", |
| 114 extensions::Manifest::Location::EXTERNAL_COMPONENT); |
| 115 base::string16 error; |
| 116 EXPECT_FALSE(provider_.UserMayLoad(extension.get(), &error)); |
| 117 EXPECT_FALSE(error.empty()); |
| 118 } |
| OLD | NEW |