summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy
diff options
context:
space:
mode:
authorstepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-12 20:13:03 +0000
committerstepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-12 20:13:03 +0000
commit92f84857b36f3ca684027970cbad0ed241e27db9 (patch)
treefa9f48901ff63d82e665d12f69f3a4040ac95df5 /chrome/browser/policy
parentc310432c146623319e517de58bfc8ed15150e20d (diff)
downloadchromium_src-92f84857b36f3ca684027970cbad0ed241e27db9.zip
chromium_src-92f84857b36f3ca684027970cbad0ed241e27db9.tar.gz
chromium_src-92f84857b36f3ca684027970cbad0ed241e27db9.tar.bz2
Add integration test for policy invalidations.
BUG=266975 Review URL: https://chromiumcodereview.appspot.com/23549031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy')
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_browsertest.cc86
-rw-r--r--chrome/browser/policy/test/policy_testserver.py12
2 files changed, 86 insertions, 12 deletions
diff --git a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc
index 3ccf690..61ca336 100644
--- a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc
@@ -14,6 +14,8 @@
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/invalidation/fake_invalidation_service.h"
+#include "chrome/browser/invalidation/invalidation_service_factory.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/cloud/cloud_policy_client.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
@@ -89,31 +91,35 @@ std::string GetEmptyPolicy() {
kEmptyPolicy, dm_protocol::kChromeUserPolicyType, GetTestUser());
}
-std::string GetTestPolicy(int key_version) {
+std::string GetTestPolicy(const char* homepage, int key_version) {
const char kTestPolicy[] =
"{"
" \"%s\": {"
" \"mandatory\": {"
" \"ShowHomeButton\": true,"
" \"RestoreOnStartup\": 4,"
- " \"URLBlacklist\": [ \"dev.chromium.org\", \"youtube.com\" ]"
+ " \"URLBlacklist\": [ \"dev.chromium.org\", \"youtube.com\" ],"
+ " \"MaxInvalidationFetchDelay\": 1000"
" },"
" \"recommended\": {"
- " \"HomepageLocation\": \"google.com\""
+ " \"HomepageLocation\": \"%s\""
" }"
" },"
" \"managed_users\": [ \"*\" ],"
" \"policy_user\": \"%s\","
- " \"current_key_index\": %d"
+ " \"current_key_index\": %d,"
+ " \"invalidation_source\": 16,"
+ " \"invalidation_name\": \"test_policy\""
"}";
return base::StringPrintf(kTestPolicy,
dm_protocol::kChromeUserPolicyType,
+ homepage,
GetTestUser(),
key_version);
}
-void GetExpectedTestPolicy(PolicyMap* expected) {
+void GetExpectedTestPolicy(PolicyMap* expected, const char* homepage) {
expected->Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
base::Value::CreateBooleanValue(true), NULL);
expected->Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY,
@@ -125,14 +131,18 @@ void GetExpectedTestPolicy(PolicyMap* expected) {
key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
list.DeepCopy(), NULL);
expected->Set(
+ key::kMaxInvalidationFetchDelay, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, base::Value::CreateIntegerValue(1000), NULL);
+ expected->Set(
key::kHomepageLocation, POLICY_LEVEL_RECOMMENDED,
- POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com"), NULL);
+ POLICY_SCOPE_USER, base::Value::CreateStringValue(homepage), NULL);
}
} // namespace
// Tests the cloud policy stack(s).
-class CloudPolicyTest : public InProcessBrowserTest {
+class CloudPolicyTest : public InProcessBrowserTest,
+ public PolicyService::Observer {
protected:
CloudPolicyTest() {}
virtual ~CloudPolicyTest() {}
@@ -148,6 +158,9 @@ class CloudPolicyTest : public InProcessBrowserTest {
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url);
+
+ invalidation::InvalidationServiceFactory::GetInstance()->
+ SetBuildOnlyFakeInvalidatorsForTest(true);
}
virtual void SetUpOnMainThread() OVERRIDE {
@@ -220,6 +233,12 @@ class CloudPolicyTest : public InProcessBrowserTest {
return profile_connector->policy_service();
}
+ invalidation::FakeInvalidationService* GetInvalidationService() {
+ return static_cast<invalidation::FakeInvalidationService*>(
+ invalidation::InvalidationServiceFactory::GetForProfile(
+ browser()->profile()));
+ }
+
void SetServerPolicy(const std::string& policy) {
int result = file_util::WriteFile(policy_file_path(), policy.data(),
policy.size());
@@ -230,9 +249,21 @@ class CloudPolicyTest : public InProcessBrowserTest {
return temp_dir_.path().AppendASCII("policy.json");
}
+ virtual void OnPolicyUpdated(const PolicyNamespace& ns,
+ const PolicyMap& previous,
+ const PolicyMap& current) OVERRIDE {
+ if (!on_policy_updated_.is_null()) {
+ on_policy_updated_.Run();
+ on_policy_updated_.Reset();
+ }
+ }
+
+ virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE {}
+
base::ScopedTempDir temp_dir_;
scoped_ptr<LocalPolicyTestServer> test_server_;
base::FilePath user_policy_key_file_;
+ base::Closure on_policy_updated_;
};
IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) {
@@ -248,9 +279,9 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) {
EXPECT_TRUE(empty.Equals(policy_service->GetPolicies(
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
- ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(0)));
+ ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("google.com", 0)));
PolicyMap expected;
- GetExpectedTestPolicy(&expected);
+ GetExpectedTestPolicy(&expected, "google.com");
{
base::RunLoop run_loop;
// This fetches the new policies, using the same key.
@@ -261,6 +292,39 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) {
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
}
+IN_PROC_BROWSER_TEST_F(CloudPolicyTest, InvalidatePolicy) {
+ PolicyService* policy_service = GetPolicyService();
+ policy_service->AddObserver(POLICY_DOMAIN_CHROME, this);
+
+ // Perform the initial fetch.
+ ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("google.com", 0)));
+ {
+ base::RunLoop run_loop;
+ policy_service->RefreshPolicies(run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ // Update the homepage in the policy and trigger an invalidation.
+ ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("youtube.com", 0)));
+ GetInvalidationService()->EmitInvalidationForTest(
+ invalidation::ObjectId(16, "test_policy"),
+ 1 /* version */,
+ "payload");
+ {
+ base::RunLoop run_loop;
+ on_policy_updated_ = run_loop.QuitClosure();
+ run_loop.Run();
+ }
+
+ // Check that the updated policy was fetched.
+ PolicyMap expected;
+ GetExpectedTestPolicy(&expected, "youtube.com");
+ EXPECT_TRUE(expected.Equals(policy_service->GetPolicies(
+ PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
+
+ policy_service->RemoveObserver(POLICY_DOMAIN_CHROME, this);
+}
+
#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) {
PolicyService* policy_service = GetPolicyService();
@@ -280,9 +344,9 @@ IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) {
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
// Set the new policies and a new key at the server.
- ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(1)));
+ ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("google.com", 1)));
PolicyMap expected;
- GetExpectedTestPolicy(&expected);
+ GetExpectedTestPolicy(&expected, "google.com");
{
base::RunLoop run_loop;
// This fetches the new policies and does a key rotation.
diff --git a/chrome/browser/policy/test/policy_testserver.py b/chrome/browser/policy/test/policy_testserver.py
index 1ccf35a..5f4ca45 100644
--- a/chrome/browser/policy/test/policy_testserver.py
+++ b/chrome/browser/policy/test/policy_testserver.py
@@ -47,7 +47,9 @@ Example:
"secret123456"
],
"current_key_index": 0,
- "robot_api_auth_code": "fake_auth_code"
+ "robot_api_auth_code": "fake_auth_code",
+ "invalidation_source": 1025,
+ "invalidation_name": "UENUPOL"
}
"""
@@ -595,6 +597,14 @@ class PolicyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
policy_data.service_account_identity = policy.get(
'service_account_identity',
'policy_testserver.py-service_account_identity')
+ invalidation_source = policy.get('invalidation_source')
+ if invalidation_source is not None:
+ policy_data.invalidation_source = invalidation_source
+ # Since invalidation_name is type bytes in the proto, the Unicode name
+ # provided needs to be encoded as ASCII to set the correct byte pattern.
+ invalidation_name = policy.get('invalidation_name')
+ if invalidation_name is not None:
+ policy_data.invalidation_name = invalidation_name.encode('ascii')
if signing_key:
policy_data.public_key_version = current_key_index + 1