Commit 0e3f2d23 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Don't augment GUID in ONC merging.

The GUID property is used to pick user settings, policies and active settings for the same network. Thus it's more an identifier than a property and should not be exposed with additional meta information as it is the case for other properties.

BUG=372337

Review URL: https://codereview.chromium.org/291553006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274603 0039d316-1c4b-4281-b951-d872f2087c98
parent 01924fbe
...@@ -323,11 +323,7 @@ var availableTests = [ ...@@ -323,11 +323,7 @@ var availableTests = [
"Active": "NotConnected", "Active": "NotConnected",
"Effective": "Unmanaged" "Effective": "Unmanaged"
}, },
"GUID": { "GUID": "stub_wifi2",
"Active": "stub_wifi2",
"Effective": "UserPolicy",
"UserPolicy": "stub_wifi2"
},
"Name": { "Name": {
"Active": "wifi2_PSK", "Active": "wifi2_PSK",
"Effective": "UserPolicy", "Effective": "UserPolicy",
......
...@@ -20,6 +20,18 @@ namespace { ...@@ -20,6 +20,18 @@ namespace {
typedef scoped_ptr<base::DictionaryValue> DictionaryPtr; typedef scoped_ptr<base::DictionaryValue> DictionaryPtr;
// Returns true if the field is the identifier of a configuration, i.e. the GUID
// of a network or a certificate. These can be special handled during merging
// because they are always identical for the various setting sources.
bool IsIdentifierField(const OncValueSignature& value_signature,
const std::string& field_name) {
if (&value_signature == &kNetworkConfigurationSignature)
return field_name == ::onc::network_config::kGUID;
if (&value_signature == &kCertificateSignature)
return field_name == ::onc::certificate::kGUID;
return false;
}
// Inserts |true| at every field name in |result| that is recommended in // Inserts |true| at every field name in |result| that is recommended in
// |policy|. // |policy|.
void MarkRecommendedFieldnames(const base::DictionaryValue& policy, void MarkRecommendedFieldnames(const base::DictionaryValue& policy,
...@@ -302,6 +314,26 @@ class MergeToEffective : public MergeSettingsAndPolicies { ...@@ -302,6 +314,26 @@ class MergeToEffective : public MergeSettingsAndPolicies {
DISALLOW_COPY_AND_ASSIGN(MergeToEffective); DISALLOW_COPY_AND_ASSIGN(MergeToEffective);
}; };
namespace {
// Returns true if all not-null values in |values| are equal to |value|.
bool AllPresentValuesEqual(const MergeSettingsAndPolicies::ValueParams& values,
const base::Value& value) {
if (values.user_policy && !value.Equals(values.user_policy))
return false;
if (values.device_policy && !value.Equals(values.device_policy))
return false;
if (values.user_setting && !value.Equals(values.user_setting))
return false;
if (values.shared_setting && !value.Equals(values.shared_setting))
return false;
if (values.active_setting && !value.Equals(values.active_setting))
return false;
return true;
}
} // namespace
// Call MergeDictionaries to merge policies and settings to an augmented // Call MergeDictionaries to merge policies and settings to an augmented
// dictionary which contains a dictionary for each value in the original // dictionary which contains a dictionary for each value in the original
// dictionaries. See the description of MergeSettingsAndPoliciesToAugmented. // dictionaries. See the description of MergeSettingsAndPoliciesToAugmented.
...@@ -329,10 +361,11 @@ class MergeToAugmented : public MergeToEffective { ...@@ -329,10 +361,11 @@ class MergeToAugmented : public MergeToEffective {
virtual scoped_ptr<base::Value> MergeValues( virtual scoped_ptr<base::Value> MergeValues(
const std::string& key, const std::string& key,
const ValueParams& values) OVERRIDE { const ValueParams& values) OVERRIDE {
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); scoped_ptr<base::DictionaryValue> augmented_value(
new base::DictionaryValue);
if (values.active_setting) { if (values.active_setting) {
result->SetWithoutPathExpansion(::onc::kAugmentationActiveSetting, augmented_value->SetWithoutPathExpansion(
values.active_setting->DeepCopy()); ::onc::kAugmentationActiveSetting, values.active_setting->DeepCopy());
} }
const OncFieldSignature* field = NULL; const OncFieldSignature* field = NULL;
...@@ -343,9 +376,22 @@ class MergeToAugmented : public MergeToEffective { ...@@ -343,9 +376,22 @@ class MergeToAugmented : public MergeToEffective {
// This field is part of the provided ONCSignature, thus it can be // This field is part of the provided ONCSignature, thus it can be
// controlled by policy. // controlled by policy.
std::string which_effective; std::string which_effective;
MergeToEffective::MergeValues(key, values, &which_effective).reset(); scoped_ptr<base::Value> effective_value =
MergeToEffective::MergeValues(key, values, &which_effective);
if (IsIdentifierField(*signature_, key)) {
// Don't augment the GUID but write the plain value.
DCHECK(effective_value);
// DCHECK that all provided GUIDs are identical.
DCHECK(AllPresentValuesEqual(values, *effective_value));
// Return the un-augmented GUID.
return effective_value.Pass();
}
if (!which_effective.empty()) { if (!which_effective.empty()) {
result->SetStringWithoutPathExpansion( augmented_value->SetStringWithoutPathExpansion(
::onc::kAugmentationEffectiveSetting, which_effective); ::onc::kAugmentationEffectiveSetting, which_effective);
} }
bool is_credential = onc::FieldIsCredential(*signature_, key); bool is_credential = onc::FieldIsCredential(*signature_, key);
...@@ -355,39 +401,41 @@ class MergeToAugmented : public MergeToEffective { ...@@ -355,39 +401,41 @@ class MergeToAugmented : public MergeToEffective {
// leak here. // leak here.
if (!is_credential) { if (!is_credential) {
if (values.user_policy) { if (values.user_policy) {
result->SetWithoutPathExpansion(::onc::kAugmentationUserPolicy, augmented_value->SetWithoutPathExpansion(
values.user_policy->DeepCopy()); ::onc::kAugmentationUserPolicy, values.user_policy->DeepCopy());
} }
if (values.device_policy) { if (values.device_policy) {
result->SetWithoutPathExpansion(::onc::kAugmentationDevicePolicy, augmented_value->SetWithoutPathExpansion(
values.device_policy->DeepCopy()); ::onc::kAugmentationDevicePolicy,
values.device_policy->DeepCopy());
} }
} }
if (values.user_setting) { if (values.user_setting) {
result->SetWithoutPathExpansion(::onc::kAugmentationUserSetting, augmented_value->SetWithoutPathExpansion(
values.user_setting->DeepCopy()); ::onc::kAugmentationUserSetting, values.user_setting->DeepCopy());
} }
if (values.shared_setting) { if (values.shared_setting) {
result->SetWithoutPathExpansion(::onc::kAugmentationSharedSetting, augmented_value->SetWithoutPathExpansion(
values.shared_setting->DeepCopy()); ::onc::kAugmentationSharedSetting,
values.shared_setting->DeepCopy());
} }
if (HasUserPolicy() && values.user_editable) { if (HasUserPolicy() && values.user_editable) {
result->SetBooleanWithoutPathExpansion(::onc::kAugmentationUserEditable, augmented_value->SetBooleanWithoutPathExpansion(
true); ::onc::kAugmentationUserEditable, true);
} }
if (HasDevicePolicy() && values.device_editable) { if (HasDevicePolicy() && values.device_editable) {
result->SetBooleanWithoutPathExpansion( augmented_value->SetBooleanWithoutPathExpansion(
::onc::kAugmentationDeviceEditable, true); ::onc::kAugmentationDeviceEditable, true);
} }
} else { } else {
// This field is not part of the provided ONCSignature, thus it cannot be // This field is not part of the provided ONCSignature, thus it cannot be
// controlled by policy. // controlled by policy.
result->SetStringWithoutPathExpansion( augmented_value->SetStringWithoutPathExpansion(
::onc::kAugmentationEffectiveSetting, ::onc::kAugmentationUnmanaged); ::onc::kAugmentationEffectiveSetting, ::onc::kAugmentationUnmanaged);
} }
if (result->empty()) if (augmented_value->empty())
result.reset(); augmented_value.reset();
return result.PassAs<base::Value>(); return augmented_value.PassAs<base::Value>();
} }
// MergeListOfDictionaries override. // MergeListOfDictionaries override.
......
...@@ -53,6 +53,7 @@ class ONCMergerTest : public testing::Test { ...@@ -53,6 +53,7 @@ class ONCMergerTest : public testing::Test {
scoped_ptr<const base::DictionaryValue> policy_; scoped_ptr<const base::DictionaryValue> policy_;
scoped_ptr<const base::DictionaryValue> policy_without_recommended_; scoped_ptr<const base::DictionaryValue> policy_without_recommended_;
scoped_ptr<const base::DictionaryValue> device_policy_; scoped_ptr<const base::DictionaryValue> device_policy_;
scoped_ptr<const base::DictionaryValue> active_;
virtual void SetUp() { virtual void SetUp() {
policy_ = test_utils::ReadTestDictionary("managed_vpn.onc"); policy_ = test_utils::ReadTestDictionary("managed_vpn.onc");
...@@ -60,6 +61,7 @@ class ONCMergerTest : public testing::Test { ...@@ -60,6 +61,7 @@ class ONCMergerTest : public testing::Test {
test_utils::ReadTestDictionary("managed_vpn_without_recommended.onc"); test_utils::ReadTestDictionary("managed_vpn_without_recommended.onc");
user_ = test_utils::ReadTestDictionary("user.onc"); user_ = test_utils::ReadTestDictionary("user.onc");
device_policy_ = test_utils::ReadTestDictionary("device_policy.onc"); device_policy_ = test_utils::ReadTestDictionary("device_policy.onc");
active_ = test_utils::ReadTestDictionary("vpn_active_settings.onc");
} }
}; };
...@@ -148,7 +150,7 @@ TEST_F(ONCMergerTest, MergeToAugmented) { ...@@ -148,7 +150,7 @@ TEST_F(ONCMergerTest, MergeToAugmented) {
test_utils::ReadTestDictionary("augmented_merge.json"); test_utils::ReadTestDictionary("augmented_merge.json");
scoped_ptr<base::DictionaryValue> merged(MergeSettingsAndPoliciesToAugmented( scoped_ptr<base::DictionaryValue> merged(MergeSettingsAndPoliciesToAugmented(
kNetworkConfigurationSignature, policy_.get(), device_policy_.get(), kNetworkConfigurationSignature, policy_.get(), device_policy_.get(),
user_.get(), NULL, NULL)); user_.get(), NULL, active_.get()));
EXPECT_TRUE(test_utils::Equals(expected_augmented.get(), merged.get())); EXPECT_TRUE(test_utils::Equals(expected_augmented.get(), merged.get()));
} }
......
{ {
"GUID": { "ConnectionState": {
"DevicePolicy": "123", "Active": "Connected",
"Effective": "UserPolicy", "Effective": "Unmanaged"
"UserPolicy": "123"
}, },
"GUID": "123",
"IPConfigs": { "IPConfigs": {
"DevicePolicy": [ { "DevicePolicy": [ {
"IPAddress": "127.0.0.1", "IPAddress": "127.0.0.1",
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
} ] } ]
}, },
"Name": { "Name": {
"Active": "testopenvpn",
"DevicePolicy": "testopenvpn", "DevicePolicy": "testopenvpn",
"Effective": "UserPolicy", "Effective": "UserPolicy",
"UserPolicy": "testopenvpn", "UserPolicy": "testopenvpn",
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
} }
}, },
"Type": { "Type": {
"Active": "VPN",
"DevicePolicy": "VPN", "DevicePolicy": "VPN",
"Effective": "UserPolicy", "Effective": "UserPolicy",
"UserPolicy": "VPN", "UserPolicy": "VPN",
...@@ -61,7 +63,7 @@ ...@@ -61,7 +63,7 @@
"UserPolicy": 1 "UserPolicy": 1
}, },
"PSK": { "PSK": {
"Effective": "UserPolicy", "Effective": "UserPolicy"
} }
}, },
"OpenVPN": { "OpenVPN": {
...@@ -96,15 +98,15 @@ ...@@ -96,15 +98,15 @@
"UserPolicy": 1194, "UserPolicy": 1194,
"UserSetting": 1195 "UserSetting": 1195
}, },
"ServerCARefs": {
"Effective": "UserPolicy",
"UserPolicy": ["ref1", "ref2"]
},
"Username": { "Username": {
"DevicePolicy": "device user", "DevicePolicy": "device user",
"Effective": "DevicePolicy", "Effective": "DevicePolicy",
"UserEditable": true, "UserEditable": true,
"UserPolicy": "policy user" "UserPolicy": "policy user"
},
"ServerCARefs": {
"UserPolicy": ["ref1", "ref2"],
"Effective": "UserPolicy"
} }
}, },
"Type": { "Type": {
......
{ "Type": "VPN",
"Name": "testopenvpn",
"ConnectionState": "Connected",
"GUID": "123"
}
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