Commit f8c0ec59 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Add IsInstallationExplicitlyBlocked function for extension management

Similar to ExtensionManagement::IsInstallationExplicitlyAllowed,
IsInstallationExplicitlyBlocked return true only if an extension's
installation is blocked by its id but not wildcard.

This function is going to be used by extension request feature. With it,
user can send extension install request to admin. Only extensions that
are not explicily blocked can be requested.

Bug: 1006899
Change-Id: I6160fee3ab25f4da095b51bd727fe53fb3b8760c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863635
Commit-Queue: Owen Min <zmin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706918}
parent 1a7448de
......@@ -166,6 +166,17 @@ bool ExtensionManagement::IsInstallationExplicitlyAllowed(
mode == INSTALLATION_ALLOWED;
}
bool ExtensionManagement::IsInstallationExplicitlyBlocked(
const ExtensionId& id) const {
auto it = settings_by_id_.find(id);
// No settings explicitly specified for |id|.
if (it == settings_by_id_.end())
return false;
// Checks if the extension is on the black list or removed list.
InstallationMode mode = it->second->installation_mode;
return mode == INSTALLATION_BLOCKED || mode == INSTALLATION_REMOVED;
}
bool ExtensionManagement::IsOffstoreInstallAllowed(
const GURL& url,
const GURL& referrer_url) const {
......
......@@ -112,6 +112,10 @@ class ExtensionManagement : public KeyedService {
// policy or not.
bool IsInstallationExplicitlyAllowed(const ExtensionId& id) const;
// Returns if an extension with id |id| is explicitly blocked by enterprise
// policy or not.
bool IsInstallationExplicitlyBlocked(const ExtensionId& id) const;
// Returns true if an extension download should be allowed to proceed.
bool IsOffstoreInstallAllowed(const GURL& url,
const GURL& referrer_url) const;
......
......@@ -43,6 +43,7 @@ const char kTargetExtension5[] = "efghijklmnopabcdefghijklmnopabcd";
const char kTargetExtension6[] = "fghijklmnopabcdefghijklmnopabcde";
const char kTargetExtension7[] = "ghijklmnopabcdefghijklmnopabcdef";
const char kTargetExtension8[] = "hijklmnopabcdefghijklmnopabcdefg";
const char kTargetExtension9[] = "ijklmnopabcdefghijklmnopabcdefgh";
const char kExampleUpdateUrl[] = "http://example.com/update_url";
const char kNonExistingExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
......@@ -78,6 +79,9 @@ const char kExampleDictPreference[] =
"ghijklmnopabcdefghijklmnopabcdef,hijklmnopabcdefghijklmnopabcdefg,": {
"installation_mode": "allowed",
},
"ijklmnopabcdefghijklmnopabcdefgh": {
"installation_mode": "removed",
},
"update_url:http://example.com/update_url": {
"installation_mode": "allowed",
"blocked_permissions": ["fileSystem", "bookmarks"],
......@@ -820,6 +824,7 @@ TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) {
const char* forced = kTargetExtension2;
const char* recommended = kTargetExtension3;
const char* blocked = kTargetExtension4;
const char* removed = kTargetExtension9;
const char* not_specified = kNonExistingExtension;
// BlacklistedByDefault() is true in example preference.
......@@ -828,14 +833,13 @@ TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) {
EXPECT_TRUE(
extension_management_->IsInstallationExplicitlyAllowed(recommended));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(removed));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyAllowed(not_specified));
{
// Set BlacklistedByDefault() to false.
PrefUpdater pref(pref_service_);
pref.SetBlacklistedByDefault(false);
}
// Set BlacklistedByDefault() to false.
PrefUpdater pref(pref_service_);
pref.SetBlacklistedByDefault(false);
// The result should remain the same.
EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed));
......@@ -843,10 +847,46 @@ TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) {
EXPECT_TRUE(
extension_management_->IsInstallationExplicitlyAllowed(recommended));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(removed));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyAllowed(not_specified));
}
TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyBlocked) {
SetExampleDictPref(kExampleDictPreference);
// Constant name indicates the installation_mode of extensions in example
// preference.
const char* allowed = kTargetExtension;
const char* forced = kTargetExtension2;
const char* recommended = kTargetExtension3;
const char* blocked = kTargetExtension4;
const char* removed = kTargetExtension9;
const char* not_specified = kNonExistingExtension;
// BlacklistedByDefault() is true in example preference.
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyBlocked(allowed));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyBlocked(forced));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyBlocked(recommended));
EXPECT_TRUE(extension_management_->IsInstallationExplicitlyBlocked(blocked));
EXPECT_TRUE(extension_management_->IsInstallationExplicitlyBlocked(removed));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyBlocked(not_specified));
PrefUpdater pref(pref_service_);
pref.SetBlacklistedByDefault(false);
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyBlocked(allowed));
EXPECT_FALSE(extension_management_->IsInstallationExplicitlyBlocked(forced));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyBlocked(recommended));
EXPECT_TRUE(extension_management_->IsInstallationExplicitlyBlocked(blocked));
EXPECT_TRUE(extension_management_->IsInstallationExplicitlyBlocked(removed));
EXPECT_FALSE(
extension_management_->IsInstallationExplicitlyBlocked(not_specified));
}
#if !defined(OS_CHROMEOS)
TEST_F(ExtensionManagementServiceTest, CloudReportingEnabledPolicy) {
// Enables the policy put the extension into forced list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment