summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcraigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 21:15:45 +0000
committercraigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 21:15:45 +0000
commit830074e64684ea4387f6013e47453f0fd17b62bb (patch)
treec49773c1892ef2e0f3bb32db1af30cbfaff281a5
parente5e6e25f97934963c9e86c1a60e61b45621e59a3 (diff)
downloadchromium_src-830074e64684ea4387f6013e47453f0fd17b62bb.zip
chromium_src-830074e64684ea4387f6013e47453f0fd17b62bb.tar.gz
chromium_src-830074e64684ea4387f6013e47453f0fd17b62bb.tar.bz2
Added GetEnterprisePolicyInfo() automation hook.
GetEnterpriseInfo() will return a dictionary containing policy-related information as well as all Mandatory and Recommended policies. BUG=chromium-os:17872 TEST=Manual test Review URL: http://codereview.chromium.org/7399032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93473 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc2
-rw-r--r--chrome/browser/automation/testing_automation_provider.h3
-rw-r--r--chrome/browser/automation/testing_automation_provider_chromeos.cc116
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc14
-rw-r--r--chrome/browser/policy/browser_policy_connector.h4
-rw-r--r--chrome/browser/policy/cloud_policy_subsystem.cc4
-rw-r--r--chrome/browser/policy/cloud_policy_subsystem.h3
-rwxr-xr-xchrome/test/functional/chromeos_policy.py24
-rw-r--r--chrome/test/pyautolib/pyauto.py33
-rw-r--r--chrome/tools/build/generate_policy_source.py7
10 files changed, 181 insertions, 29 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 6294541..e26268b 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2230,6 +2230,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::IsEnterpriseDevice;
handler_map["FetchEnterprisePolicy"] =
&TestingAutomationProvider::FetchEnterprisePolicy;
+ handler_map["GetEnterprisePolicyInfo"] =
+ &TestingAutomationProvider::GetEnterprisePolicyInfo;
handler_map["GetUpdateInfo"] = &TestingAutomationProvider::GetUpdateInfo;
handler_map["UpdateCheck"] = &TestingAutomationProvider::UpdateCheck;
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index d69269e..399e798 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -1207,6 +1207,9 @@ class TestingAutomationProvider : public AutomationProvider,
void FetchEnterprisePolicy(DictionaryValue* args,
IPC::Message* reply_message);
+ void GetEnterprisePolicyInfo(DictionaryValue* args,
+ IPC::Message* reply_message);
+
void GetUpdateInfo(base::DictionaryValue* args, IPC::Message* reply_message);
diff --git a/chrome/browser/automation/testing_automation_provider_chromeos.cc b/chrome/browser/automation/testing_automation_provider_chromeos.cc
index 6bfe08f..70205bc 100644
--- a/chrome/browser/automation/testing_automation_provider_chromeos.cc
+++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc
@@ -6,9 +6,9 @@
#include "base/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/automation/automation_provider_json.h"
#include "chrome/browser/automation/automation_provider_observers.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/audio_handler.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
@@ -21,7 +21,11 @@
#include "chrome/browser/chromeos/network_state_notifier.h"
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
#include "chrome/browser/policy/browser_policy_connector.h"
+#include "chrome/browser/policy/cloud_policy_cache_base.h"
+#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h"
+#include "chrome/browser/policy/enterprise_install_attributes.h"
+#include "policy/policy_constants.h"
using chromeos::CrosLibrary;
using chromeos::NetworkLibrary;
@@ -132,8 +136,8 @@ void UpdateCheckCallback(void* user_data, chromeos::UpdateResult result,
delete reply;
}
-const std::string VPNProviderTypeToString(chromeos::VirtualNetwork::ProviderType
- provider_type) {
+const std::string VPNProviderTypeToString(
+ chromeos::VirtualNetwork::ProviderType provider_type) {
switch (provider_type) {
case chromeos::VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK:
return std::string("L2TP_IPSEC_PSK");
@@ -146,6 +150,49 @@ const std::string VPNProviderTypeToString(chromeos::VirtualNetwork::ProviderType
}
}
+const char* EnterpriseStatusToString(
+ policy::CloudPolicySubsystem::PolicySubsystemState state) {
+ switch (state) {
+ case policy::CloudPolicySubsystem::UNENROLLED:
+ return "UNENROLLED";
+ case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN:
+ return "BAD_GAIA_TOKEN";
+ case policy::CloudPolicySubsystem::UNMANAGED:
+ return "UNMANAGED";
+ case policy::CloudPolicySubsystem::NETWORK_ERROR:
+ return "NETWORK_ERROR";
+ case policy::CloudPolicySubsystem::LOCAL_ERROR:
+ return "LOCAL_ERROR";
+ case policy::CloudPolicySubsystem::TOKEN_FETCHED:
+ return "TOKEN_FETCHED";
+ case policy::CloudPolicySubsystem::SUCCESS:
+ return "SUCCESS";
+ default:
+ return "UNKNOWN_STATE";
+ }
+}
+
+// Fills the supplied DictionaryValue with all policy settings held by the
+// given CloudPolicySubsystem (Device or User subsystems) at the given
+// PolicyLevel (Mandatory or Recommended policies).
+DictionaryValue* CreateDictionaryWithPolicies(
+ policy::CloudPolicySubsystem* policy_subsystem,
+ policy::CloudPolicyCacheBase::PolicyLevel policy_level) {
+ DictionaryValue* dict = new DictionaryValue;
+ policy::CloudPolicyCacheBase* policy_cache =
+ policy_subsystem->GetCloudPolicyCacheBase();
+ if (policy_cache) {
+ const policy::PolicyMap* policy_map = policy_cache->policy(policy_level);
+ if (policy_map) {
+ policy::PolicyMap::const_iterator i;
+ for (i = policy_map->begin(); i != policy_map->end(); i++)
+ dict->Set(policy::key::kMapPolicyString[i->first],
+ i->second->DeepCopy());
+ }
+ }
+ return dict;
+}
+
} // namespace
void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args,
@@ -708,7 +755,7 @@ void TestingAutomationProvider::FetchEnterprisePolicy(
return;
}
policy::CloudPolicySubsystem* policy_subsystem =
- connector->device_cloud_policy_subsystem();
+ connector->user_cloud_policy_subsystem();
if (policy_subsystem) {
new CloudPolicyObserver(this, reply_message, connector, policy_subsystem);
connector->FetchDevicePolicy();
@@ -718,6 +765,67 @@ void TestingAutomationProvider::FetchEnterprisePolicy(
}
}
+void TestingAutomationProvider::GetEnterprisePolicyInfo(
+ DictionaryValue* args, IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+
+ policy::BrowserPolicyConnector* connector =
+ g_browser_process->browser_policy_connector();
+ if (!connector) {
+ reply.SendError("Unable to access BrowserPolicyConnector");
+ return;
+ }
+ policy::CloudPolicySubsystem* user_cloud_policy =
+ connector->user_cloud_policy_subsystem();
+ policy::CloudPolicySubsystem* device_cloud_policy =
+ connector->device_cloud_policy_subsystem();
+ const policy::CloudPolicyDataStore* user_data_store =
+ connector->GetUserCloudPolicyDataStore();
+ const policy::CloudPolicyDataStore* device_data_store =
+ connector->GetDeviceCloudPolicyDataStore();
+ if (!user_cloud_policy || !device_cloud_policy) {
+ reply.SendError("Unable to access a CloudPolicySubsystem");
+ return;
+ }
+ if (!user_data_store || !device_data_store) {
+ reply.SendError("Unable to access a CloudPolicyDataStore");
+ return;
+ }
+
+ // Get various policy related fields.
+ return_value->SetString("enterprise_domain",
+ connector->GetEnterpriseDomain());
+ return_value->SetString("user_cloud_policy",
+ EnterpriseStatusToString(user_cloud_policy->state()));
+ return_value->SetString("device_cloud_policy",
+ EnterpriseStatusToString(device_cloud_policy->state()));
+ return_value->SetString("device_id", device_data_store->device_id());
+ return_value->SetString("device_token", device_data_store->device_token());
+ return_value->SetString("gaia_token", device_data_store->gaia_token());
+ return_value->SetString("machine_id", device_data_store->machine_id());
+ return_value->SetString("machine_model", device_data_store->machine_model());
+ return_value->SetString("user_name", device_data_store->user_name());
+ return_value->SetBoolean("device_token_cache_loaded",
+ device_data_store->token_cache_loaded());
+ return_value->SetBoolean("user_token_cache_loaded",
+ user_data_store->token_cache_loaded());
+ // Get PolicyMaps.
+ return_value->Set("device_mandatory_policies",
+ CreateDictionaryWithPolicies(device_cloud_policy,
+ policy::CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY));
+ return_value->Set("user_mandatory_policies",
+ CreateDictionaryWithPolicies(user_cloud_policy,
+ policy::CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY));
+ return_value->Set("device_recommended_policies",
+ CreateDictionaryWithPolicies(device_cloud_policy,
+ policy::CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
+ return_value->Set("user_recommended_policies",
+ CreateDictionaryWithPolicies(user_cloud_policy,
+ policy::CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
+ reply.SendSuccess(return_value.get());
+}
+
void TestingAutomationProvider::GetUpdateInfo(DictionaryValue* args,
IPC::Message* reply_message) {
if (!EnsureCrosLibraryLoaded(this, reply_message))
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 51bfa71..1072fd2 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -138,6 +138,20 @@ ConfigurationPolicyProvider*
return recommended_cloud_provider_.get();
}
+const CloudPolicyDataStore*
+ BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() const {
+#if defined(OS_CHROMEOS)
+ return device_data_store_.get();
+#else
+ return NULL;
+#endif
+}
+
+const CloudPolicyDataStore*
+ BrowserPolicyConnector::GetUserCloudPolicyDataStore() const {
+ return user_data_store_.get();
+}
+
ConfigurationPolicyProvider*
BrowserPolicyConnector::CreateManagedPlatformProvider() {
const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list =
diff --git a/chrome/browser/policy/browser_policy_connector.h b/chrome/browser/policy/browser_policy_connector.h
index 780a1c8..1070a49 100644
--- a/chrome/browser/policy/browser_policy_connector.h
+++ b/chrome/browser/policy/browser_policy_connector.h
@@ -95,6 +95,10 @@ class BrowserPolicyConnector : public NotificationObserver {
const FilePath& policy_dir,
TokenService* token_service);
+ // Only used in testing.
+ const CloudPolicyDataStore* GetDeviceCloudPolicyDataStore() const;
+ const CloudPolicyDataStore* GetUserCloudPolicyDataStore() const;
+
private:
friend class ::TestingBrowserProcess;
diff --git a/chrome/browser/policy/cloud_policy_subsystem.cc b/chrome/browser/policy/cloud_policy_subsystem.cc
index 9fd0060..35da26e 100644
--- a/chrome/browser/policy/cloud_policy_subsystem.cc
+++ b/chrome/browser/policy/cloud_policy_subsystem.cc
@@ -193,6 +193,10 @@ void CloudPolicySubsystem::CreateCloudPolicyController() {
notifier_.get()));
}
+CloudPolicyCacheBase* CloudPolicySubsystem::GetCloudPolicyCacheBase() const {
+ return cloud_policy_cache_.get();
+}
+
CloudPolicySubsystem::CloudPolicySubsystem()
: refresh_pref_name_(NULL) {}
diff --git a/chrome/browser/policy/cloud_policy_subsystem.h b/chrome/browser/policy/cloud_policy_subsystem.h
index 0dfd897..f96a12d 100644
--- a/chrome/browser/policy/cloud_policy_subsystem.h
+++ b/chrome/browser/policy/cloud_policy_subsystem.h
@@ -98,6 +98,9 @@ class CloudPolicySubsystem
// Schedule initialization of the policy backend service.
void ScheduleServiceInitialization(int64 delay_milliseconds);
+ // Only used in testing.
+ CloudPolicyCacheBase* GetCloudPolicyCacheBase() const;
+
private:
friend class TestingCloudPolicySubsystem;
diff --git a/chrome/test/functional/chromeos_policy.py b/chrome/test/functional/chromeos_policy.py
deleted file mode 100755
index cd22fb3..0000000
--- a/chrome/test/functional/chromeos_policy.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/python
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import pyauto_functional
-import pyauto
-
-
-class EnterprisePolicyTest(pyauto.PyUITest):
- """Test for enterprise policy.
-
- The device is expected to be manually enrolled and logged in as an
- enterprise user.
- """
-
-
- def testPolicy(self):
- self.assertTrue(self.IsEnterpriseDevice())
- self.FetchEnterprisePolicy()
-
-
-if __name__ == '__main__':
- pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 860fd97..4bf630a19 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -3426,6 +3426,33 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
result = self._GetResultFromJSONRequest(cmd_dict, windex=-1)
return result.get('enterprise')
+ def GetEnterprisePolicyInfo(self):
+ """Get details about enterprise policy on chromeos.
+
+ Returns:
+ A dictionary including information about the enterprise policy.
+ Sample:
+ {u'device_token_cache_loaded': True,
+ u'device_cloud_policy_state': u'success',
+ u'device_id': u'11111-222222222-33333333-4444444',
+ u'device_mandatory_policies': {},
+ u'device_recommended_policies': {},
+ u'device_token': u'ABjmT7nqGWTHRLO',
+ u'enterprise_domain': u'example.com',
+ u'gaia_token': u'',
+ u'machine_id': u'123456789',
+ u'machine_model': u'COMPUTER',
+ u'user_cache_loaded': True,
+ u'user_cloud_policy_state': u'success',
+ u'user_mandatory_policies': {u'AuthSchemes': u'',
+ u'AutoFillEnabled': True,
+ u'ChromeOsLockOnIdleSuspend': True}
+ u'user_recommended_policies': {},
+ u'user_name': u'user@example.com'}
+ """
+ cmd_dict = { 'command': 'GetEnterprisePolicyInfo' }
+ return self._GetResultFromJSONRequest(cmd_dict, windex=-1)
+
def FetchEnterprisePolicy(self):
"""Fetch enterprise policy from server.
@@ -3433,13 +3460,17 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
fails. This is separate from any auto policy fetches the device may perform
on its own.
+ Returns:
+ The dictionary of policy info obtained from GetEnterprisePolicyInfo().
+
Raises:
pyauto_errors.JSONInterfaceError if the fetch fails.
"""
cmd_dict = {
'command': 'FetchEnterprisePolicy',
}
- return self._GetResultFromJSONRequest(cmd_dict, windex=-1)
+ self._GetResultFromJSONRequest(cmd_dict, windex=-1)
+ return self.GetEnterprisePolicyInfo()
def GetUpdateInfo(self):
"""Gets the status of the ChromeOS updater.
diff --git a/chrome/tools/build/generate_policy_source.py b/chrome/tools/build/generate_policy_source.py
index 9ee8083..e5fe160 100644
--- a/chrome/tools/build/generate_policy_source.py
+++ b/chrome/tools/build/generate_policy_source.py
@@ -99,6 +99,8 @@ def _WritePolicyConstantHeader(template_file_contents, args, opts):
'namespace key {\n\n')
for policy_name in _GetPolicyNameList(template_file_contents):
f.write('extern const char k' + policy_name + '[];\n')
+ f.write('\n// Only used in testing.'
+ '\nextern const char* kMapPolicyString[];\n')
f.write('\n} // namespace key\n\n'
'} // namespace policy\n\n'
'#endif // CHROME_COMMON_POLICY_CONSTANTS_H_\n')
@@ -124,6 +126,11 @@ def _WritePolicyConstantSource(template_file_contents, args, opts):
f.write('namespace key {\n\n')
for policy_name in _GetPolicyNameList(template_file_contents):
f.write('const char k%s[] = "%s";\n' % (policy_name, policy_name))
+ f.write('\n// Only used in testing.'
+ '\nconst char* kMapPolicyString[] = {\n ')
+ for policy_name in _GetPolicyNameList(template_file_contents):
+ f.write('\n "%s",' % policy_name)
+ f.write('\n};\n')
f.write('\n} // namespace key\n\n'
'} // namespace policy\n')