Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1478)

Unified Diff: chrome/browser/policy/policy_loader_win_unittest.cc

Issue 22645011: policy: use JSON schema to deserialize entries from Windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 3rd party policy unit tests Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/policy_loader_win.cc ('k') | chrome/browser/policy/registry_dict_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/policy_loader_win_unittest.cc
diff --git a/chrome/browser/policy/policy_loader_win_unittest.cc b/chrome/browser/policy/policy_loader_win_unittest.cc
index de822a1344f7bc9d17b7df28fc2f834ea6868459..00ed46359c2385bee8f4fe25653ef4a1ffb001ed 100644
--- a/chrome/browser/policy/policy_loader_win_unittest.cc
+++ b/chrome/browser/policy/policy_loader_win_unittest.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/policy/configuration_policy_provider_test.h"
#include "chrome/browser/policy/external_data_fetcher.h"
#include "chrome/browser/policy/policy_bundle.h"
+#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/preg_parser_win.h"
#include "components/json_schema/json_schema_constants.h"
@@ -53,6 +54,78 @@ const wchar_t kMandatory[] = L"policy";
const wchar_t kRecommended[] = L"recommended";
const wchar_t kSchema[] = L"schema";
+void InstallTestChromePolicySchema(AsyncPolicyLoader* loader) {
+ std::string err = "";
+ scoped_ptr<PolicySchema> schema = PolicySchema::Parse(
+ "{"
+ " \"$schema\": \"http://json-schema.org/draft-03/schema#\","
+ " \"type\": \"object\","
+ " \"properties\": {"
+ " \"BooleanPolicy\": { \"type\": \"boolean\" },"
+ " \"IntegerPolicy\": { \"type\": \"integer\" },"
+ " \"StringListPolicy\": {"
+ " \"type\": \"array\","
+ " \"items\": { \"type\": \"string\" } "
+ " },"
+ " \"StringPolicy\": { \"type\": \"string\" },"
+ " \"DictionaryPolicy\": {"
+ " \"type\": \"object\", "
+ " \"properties\": {"
+ " \"int\": {"
+ " \"type\": \"integer\""
+ " }, "
+ " \"list\": {"
+ " \"items\": {"
+ " \"type\": \"string\""
+ " }, "
+ " \"type\": \"array\""
+ " }, "
+ " \"bool\": {"
+ " \"type\": \"boolean\""
+ " }, "
+ " \"str\": {"
+ " \"type\": \"string\""
+ " }, "
+ " \"dict\": {"
+ " \"type\": \"object\", "
+ " \"properties\": {"
+ " \"sub\": {"
+ " \"type\": \"string\""
+ " }, "
+ " \"sublist\": {"
+ " \"items\": {"
+ " \"type\": \"object\", "
+ " \"properties\": {"
+ " \"aaa\": {"
+ " \"type\": \"integer\""
+ " }, "
+ " \"bbb\": {"
+ " \"type\": \"integer\""
+ " }, "
+ " \"ccc\": {"
+ " \"type\": \"string\""
+ " }, "
+ " \"ddd\": {"
+ " \"type\": \"string\""
+ " }"
+ " }"
+ " }, "
+ " \"type\": \"array\""
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ "}",
+ &err);
+ CHECK("" == err) << err;
+ scoped_refptr<PolicyDomainDescriptor> descriptor =
+ new PolicyDomainDescriptor(POLICY_DOMAIN_CHROME);
+ descriptor->RegisterComponent("", schema.Pass());
+ loader->InitialRegisterPolicyDomain(descriptor);
+}
+
// Installs |value| in the given registry |path| and |hive|, under the key
// |name|. Returns false on errors.
// Some of the possible Value types are stored after a conversion (e.g. doubles
@@ -183,6 +256,7 @@ base::DictionaryValue* BuildSchema(const base::Value& value) {
case base::Value::TYPE_BINARY:
break;
}
+ schema->SetString(schema::kSchema, "http://json-schema.org/draft-03/schema#");
return schema;
}
@@ -213,6 +287,9 @@ bool InstallSchema(const base::Value& value,
return WriteSchema(*schema_dict, hive, path, name);
}
+void DoNothing(scoped_ptr<PolicyBundle> bundle) {
+}
+
// This class provides sandboxing and mocking for the parts of the Windows
// Registry implementing Group Policy. It prepares two temporary sandbox keys,
// one for HKLM and one for HKCU. A test's calls to the registry are redirected
@@ -424,6 +501,7 @@ ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider(
const PolicyDefinitionList* policy_list) {
scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(
task_runner, policy_list, kRegistryChromePolicyKey, this));
+ InstallTestChromePolicySchema(loader.get());
return new AsyncPolicyProvider(loader.Pass());
}
@@ -556,6 +634,7 @@ ConfigurationPolicyProvider* PRegTestHarness::CreateProvider(
const PolicyDefinitionList* policy_list) {
scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(
task_runner, policy_list, kRegistryChromePolicyKey, this));
+ InstallTestChromePolicySchema(loader.get());
return new AsyncPolicyProvider(loader.Pass());
}
@@ -826,6 +905,8 @@ class PolicyLoaderWinTest : public PolicyTestBase,
PolicyLoaderWin loader(loop_.message_loop_proxy(),
&test_policy_definitions::kList, kTestPolicyKey,
this);
+ InstallTestChromePolicySchema(&loader);
+ loader.Init(base::Bind(&DoNothing));
scoped_ptr<PolicyBundle> loaded(loader.Load());
return loaded->Equals(expected);
}
@@ -1030,47 +1111,6 @@ TEST_F(PolicyLoaderWinTest, LoadIntegerEncodedValues) {
EXPECT_TRUE(Matches(expected));
}
-TEST_F(PolicyLoaderWinTest, DefaultPropertySchemaType) {
- // Build a schema for an "object" with a default schema for its properties.
- base::DictionaryValue default_schema;
- default_schema.SetString(schema::kType, "number");
- base::DictionaryValue integer_schema;
- integer_schema.SetString(schema::kType, "integer");
- base::DictionaryValue properties;
- properties.Set("special-int1", integer_schema.DeepCopy());
- properties.Set("special-int2", integer_schema.DeepCopy());
- base::DictionaryValue schema;
- schema.SetString(schema::kType, "object");
- schema.Set(schema::kProperties, properties.DeepCopy());
- schema.Set(schema::kAdditionalProperties, default_schema.DeepCopy());
-
- const string16 kPathSuffix =
- kTestPolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\test");
- EXPECT_TRUE(WriteSchema(schema, HKEY_CURRENT_USER, kPathSuffix, kSchema));
-
- // Write some test values.
- base::DictionaryValue policy;
- // These special values have a specific schema for them.
- policy.SetInteger("special-int1", 123);
- policy.SetString("special-int2", "-456");
- // Other values default to be loaded as doubles.
- policy.SetInteger("double1", 789.0);
- policy.SetString("double2", "123.456e7");
- policy.SetString("invalid", "omg");
- EXPECT_TRUE(InstallValue(policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory));
-
- base::DictionaryValue expected_policy;
- expected_policy.SetInteger("special-int1", 123);
- expected_policy.SetInteger("special-int2", -456);
- expected_policy.SetDouble("double1", 789.0);
- expected_policy.SetDouble("double2", 123.456e7);
- expected_policy.Set("invalid", base::Value::CreateNullValue());
- PolicyBundle expected;
- expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "test"))
- .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
- EXPECT_TRUE(Matches(expected));
-}
-
TEST_F(PolicyLoaderWinTest, AppliedPolicyNotPresent) {
InstallRegistrySentinel();
gpo_list_ = NULL;
« no previous file with comments | « chrome/browser/policy/policy_loader_win.cc ('k') | chrome/browser/policy/registry_dict_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698