summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy
diff options
context:
space:
mode:
authorjkummerow@chromium.org <jkummerow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-24 14:30:50 +0000
committerjkummerow@chromium.org <jkummerow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-24 14:30:50 +0000
commit62fed2f49842268ddc5963b9a8b8110d08a06779 (patch)
tree4a0c881eaaa219ca87852e501d51030c60341405 /chrome/browser/policy
parent78dac21222e3d00c3b7848cfd56509c1b62d4c6b (diff)
downloadchromium_src-62fed2f49842268ddc5963b9a8b8110d08a06779.zip
chromium_src-62fed2f49842268ddc5963b9a8b8110d08a06779.tar.gz
chromium_src-62fed2f49842268ddc5963b9a8b8110d08a06779.tar.bz2
Device management constants cleanup
• Move device management protocol constants into shared header file • Filter out policies with unwanted keys when decoding server response This also fixes bug 62058. BUG=62481 TEST=existing unit tests still work: DeviceManagementPolicyProviderTest.*:DeviceTokenFetcherTest.* Review URL: http://codereview.chromium.org/5348001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67259 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy')
-rw-r--r--chrome/browser/policy/device_management_policy_cache.cc5
-rw-r--r--chrome/browser/policy/device_management_policy_cache_unittest.cc3
-rw-r--r--chrome/browser/policy/device_management_policy_provider.cc3
-rw-r--r--chrome/browser/policy/device_management_service_browsertest.cc9
-rw-r--r--chrome/browser/policy/device_management_service_unittest.cc17
-rw-r--r--chrome/browser/policy/mock_device_management_backend.h3
-rw-r--r--chrome/browser/policy/proto/device_management_constants.cc12
-rw-r--r--chrome/browser/policy/proto/device_management_constants.h15
8 files changed, 52 insertions, 15 deletions
diff --git a/chrome/browser/policy/device_management_policy_cache.cc b/chrome/browser/policy/device_management_policy_cache.cc
index 534794d..2cc2bc5 100644
--- a/chrome/browser/policy/device_management_policy_cache.cc
+++ b/chrome/browser/policy/device_management_policy_cache.cc
@@ -12,6 +12,7 @@
#include "base/task.h"
#include "base/values.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
using google::protobuf::RepeatedField;
@@ -222,6 +223,10 @@ DictionaryValue* DeviceManagementPolicyCache::DecodePolicy(
for (setting = policy.setting().begin();
setting != policy.setting().end();
++setting) {
+ // Wrong policy key? Skip.
+ if (setting->policy_key().compare(kChromeDevicePolicySettingKey) != 0)
+ continue;
+
// No policy value? Skip.
if (!setting->has_policy_value())
continue;
diff --git a/chrome/browser/policy/device_management_policy_cache_unittest.cc b/chrome/browser/policy/device_management_policy_cache_unittest.cc
index 45e78fc..e1482f1 100644
--- a/chrome/browser/policy/device_management_policy_cache_unittest.cc
+++ b/chrome/browser/policy/device_management_policy_cache_unittest.cc
@@ -12,6 +12,7 @@
#include "base/scoped_temp_dir.h"
#include "base/values.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,7 +26,7 @@ class DeviceManagementPolicyCacheTestBase : public testing::Test {
const std::string& name,
const std::string& value) {
em::DevicePolicySetting* setting = policy->add_setting();
- setting->set_policy_key("test");
+ setting->set_policy_key(kChromeDevicePolicySettingKey);
em::GenericSetting* policy_value = setting->mutable_policy_value();
em::GenericNamedValue* named_value = policy_value->add_named_value();
named_value->set_name(name);
diff --git a/chrome/browser/policy/device_management_policy_provider.cc b/chrome/browser/policy/device_management_policy_provider.cc
index f191564..5b50d6f 100644
--- a/chrome/browser/policy/device_management_policy_provider.cc
+++ b/chrome/browser/policy/device_management_policy_provider.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/policy/device_management_backend.h"
#include "chrome/browser/policy/device_management_policy_cache.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
@@ -19,8 +20,6 @@
namespace policy {
-const char kChromePolicyScope[] = "chromeos/device";
-const char kChromeDevicePolicySettingKey[] = "chrome-policy";
const int64 kPolicyRefreshRateInMilliseconds = 3 * 60 * 60 * 1000; // 3 hours
const int64 kPolicyRefreshMaxEarlierInMilliseconds = 20 * 60 * 1000; // 20 mins
// These are the base values for delays before retrying after an error. They
diff --git a/chrome/browser/policy/device_management_service_browsertest.cc b/chrome/browser/policy/device_management_service_browsertest.cc
index 70a8e1b..6c07e9e 100644
--- a/chrome/browser/policy/device_management_service_browsertest.cc
+++ b/chrome/browser/policy/device_management_service_browsertest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/policy/device_management_backend_mock.h"
#include "chrome/browser/policy/device_management_service.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/in_process_browser_test.h"
@@ -114,10 +115,10 @@ IN_PROC_BROWSER_TEST_F(DeviceManagementServiceIntegrationTest,
EXPECT_CALL(delegate, HandlePolicyResponse(_))
.WillOnce(InvokeWithoutArgs(QuitMessageLoop));
em::DevicePolicyRequest request;
- request.set_policy_scope("chrome");
+ request.set_policy_scope(kChromePolicyScope);
em::DevicePolicySettingRequest* setting_request =
request.add_setting_request();
- setting_request->set_key("policy");
+ setting_request->set_key(kChromeDevicePolicySettingKey);
backend->ProcessPolicyRequest(token_, "testid", request, &delegate);
MessageLoop::current()->Run();
@@ -165,10 +166,10 @@ IN_PROC_BROWSER_TEST_F(DeviceManagementServiceIntegrationTest,
EXPECT_CALL(delegate, HandlePolicyResponse(_))
.WillOnce(InvokeWithoutArgs(QuitMessageLoop));
em::DevicePolicyRequest request;
- request.set_policy_scope("chrome");
+ request.set_policy_scope(kChromePolicyScope);
em::DevicePolicySettingRequest* setting_request =
request.add_setting_request();
- setting_request->set_key("policy");
+ setting_request->set_key(kChromeDevicePolicySettingKey);
backend->ProcessPolicyRequest(token_, "testid", request, &delegate);
MessageLoop::current()->Run();
diff --git a/chrome/browser/policy/device_management_service_unittest.cc b/chrome/browser/policy/device_management_service_unittest.cc
index ea6fece..1a11424 100644
--- a/chrome/browser/policy/device_management_service_unittest.cc
+++ b/chrome/browser/policy/device_management_service_unittest.cc
@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <vector>
+
#include "base/message_loop.h"
#include "base/string_split.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/policy/device_management_backend_impl.h"
#include "chrome/browser/policy/device_management_backend_mock.h"
#include "chrome/browser/policy/device_management_service.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/common/net/test_url_fetcher_factory.h"
#include "chrome/test/test_url_request_context_getter.h"
#include "net/base/escape.h"
@@ -136,10 +139,10 @@ TEST_P(DeviceManagementServiceFailedRequestTest, PolicyRequest) {
DevicePolicyResponseDelegateMock mock;
EXPECT_CALL(mock, OnError(GetParam().expected_error_));
em::DevicePolicyRequest request;
- request.set_policy_scope("Chrome");
+ request.set_policy_scope(kChromePolicyScope);
em::DevicePolicySettingRequest* setting_request =
request.add_setting_request();
- setting_request->set_key("policy");
+ setting_request->set_key(kChromeDevicePolicySettingKey);
backend_->ProcessPolicyRequest(kDMToken, kDeviceId, request, &mock);
TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
ASSERT_TRUE(fetcher);
@@ -352,7 +355,7 @@ TEST_F(DeviceManagementServiceTest, PolicyRequest) {
DevicePolicyResponseDelegateMock mock;
em::DevicePolicyResponse expected_response;
em::DevicePolicySetting* policy_setting = expected_response.add_setting();
- policy_setting->set_policy_key("chrome-policy");
+ policy_setting->set_policy_key(kChromeDevicePolicySettingKey);
policy_setting->set_watermark("fresh");
em::GenericSetting* policy_value = policy_setting->mutable_policy_value();
em::GenericNamedValue* named_value = policy_value->add_named_value();
@@ -368,10 +371,10 @@ TEST_F(DeviceManagementServiceTest, PolicyRequest) {
EXPECT_CALL(mock, HandlePolicyResponse(MessageEquals(expected_response)));
em::DevicePolicyRequest request;
- request.set_policy_scope("chromeos/device");
+ request.set_policy_scope(kChromePolicyScope);
em::DevicePolicySettingRequest* setting_request =
request.add_setting_request();
- setting_request->set_key("policy");
+ setting_request->set_key(kChromeDevicePolicySettingKey);
setting_request->set_watermark("stale");
backend_->ProcessPolicyRequest(kDMToken, kDeviceId, request, &mock);
TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
@@ -431,10 +434,10 @@ TEST_F(DeviceManagementServiceTest, CancelPolicyRequest) {
DevicePolicyResponseDelegateMock mock;
EXPECT_CALL(mock, HandlePolicyResponse(_)).Times(0);
em::DevicePolicyRequest request;
- request.set_policy_scope("chromium");
+ request.set_policy_scope(kChromePolicyScope);
em::DevicePolicySettingRequest* setting_request =
request.add_setting_request();
- setting_request->set_key("policy");
+ setting_request->set_key(kChromeDevicePolicySettingKey);
setting_request->set_watermark("stale");
backend_->ProcessPolicyRequest(kDMToken, kDeviceId, request, &mock);
TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
diff --git a/chrome/browser/policy/mock_device_management_backend.h b/chrome/browser/policy/mock_device_management_backend.h
index 3b0cb33..83323de 100644
--- a/chrome/browser/policy/mock_device_management_backend.h
+++ b/chrome/browser/policy/mock_device_management_backend.h
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/policy/device_management_backend.h"
+#include "chrome/browser/policy/proto/device_management_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -62,7 +63,7 @@ ACTION(MockDeviceManagementBackendSucceedRegister) {
ACTION_P2(MockDeviceManagementBackendSucceedBooleanPolicy, name, value) {
em::DevicePolicyResponse response;
em::DevicePolicySetting* setting = response.add_setting();
- setting->set_policy_key("chrome-policy");
+ setting->set_policy_key(kChromeDevicePolicySettingKey);
setting->set_watermark("fresh");
em::GenericSetting* policy_value = setting->mutable_policy_value();
em::GenericNamedValue* named_value = policy_value->add_named_value();
diff --git a/chrome/browser/policy/proto/device_management_constants.cc b/chrome/browser/policy/proto/device_management_constants.cc
new file mode 100644
index 0000000..3912eb1
--- /dev/null
+++ b/chrome/browser/policy/proto/device_management_constants.cc
@@ -0,0 +1,12 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/policy/proto/device_management_constants.h"
+
+namespace policy {
+
+const char kChromePolicyScope[] = "chromeos/device";
+const char kChromeDevicePolicySettingKey[] = "chrome-policy";
+
+} // namespace policy
diff --git a/chrome/browser/policy/proto/device_management_constants.h b/chrome/browser/policy/proto/device_management_constants.h
new file mode 100644
index 0000000..e37c514
--- /dev/null
+++ b/chrome/browser/policy/proto/device_management_constants.h
@@ -0,0 +1,15 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_
+#define CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_
+
+namespace policy {
+
+extern const char kChromePolicyScope[];
+extern const char kChromeDevicePolicySettingKey[];
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_