diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 08:29:39 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 08:29:39 +0000 |
commit | 34a3c4ff1fbd6faf449418d806fc63b74947cb8c (patch) | |
tree | a0b98ef540229f3869f93943aaa80537310813ed /chromeos/network | |
parent | 9b1b5fe4dc536da2cbc01a4d223ad7fff424fcff (diff) | |
download | chromium_src-34a3c4ff1fbd6faf449418d806fc63b74947cb8c.zip chromium_src-34a3c4ff1fbd6faf449418d806fc63b74947cb8c.tar.gz chromium_src-34a3c4ff1fbd6faf449418d806fc63b74947cb8c.tar.bz2 |
Normalize WiFi security type.
On browser startup, in particular after each logout, device network policy is reapplied.
If the network is still connected it could have happened that Shill reports the actual Security type (distinguishing WPA1 vs. WPA2) that deviates from what the policy configures (ONC doesn't distinguish WPA1/WPA2).
This commit fixes this issue by normalizing the Security type during network identification in the same way as Shill does.
BUG=241006
Review URL: https://codereview.chromium.org/280793003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network')
-rw-r--r-- | chromeos/network/managed_network_configuration_handler_unittest.cc | 40 | ||||
-rw-r--r-- | chromeos/network/shill_property_util.cc | 24 |
2 files changed, 59 insertions, 5 deletions
diff --git a/chromeos/network/managed_network_configuration_handler_unittest.cc b/chromeos/network/managed_network_configuration_handler_unittest.cc index 0107eeb..0d9584d 100644 --- a/chromeos/network/managed_network_configuration_handler_unittest.cc +++ b/chromeos/network/managed_network_configuration_handler_unittest.cc @@ -459,7 +459,7 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { "policy/shill_policy_on_unmanaged_wifi1.json"); // The passphrase isn't sent again, because it's configured by the user and - // Shill doesn't sent it on GetProperties calls. + // Shill doesn't send it on GetProperties calls. expected_shill_properties->RemoveWithoutPathExpansion( shill::kPassphraseProperty, NULL); @@ -484,6 +484,42 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { message_loop_.RunUntilIdle(); } +TEST_F(ManagedNetworkConfigurationHandlerTest, + SetPolicyUpdateManagedEquivalentSecurity) { + InitializeStandardProfiles(); + SetUpEntry("policy/shill_managed_wifi1_rsn.json", + kUser1ProfilePath, + "old_entry_path"); + + scoped_ptr<base::DictionaryValue> expected_shill_properties = + test_utils::ReadTestDictionary( + "policy/shill_policy_on_unmanaged_wifi1.json"); + + // The passphrase isn't sent again, because it's configured by the user and + // Shill doesn't send it on GetProperties calls. + expected_shill_properties->RemoveWithoutPathExpansion( + shill::kPassphraseProperty, NULL); + + EXPECT_CALL(*mock_profile_client_, + GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); + + EXPECT_CALL( + *mock_profile_client_, + GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); + + // The existing entry must not be deleted because the Security type 'rsa' is + // equivalent to 'psk' when identifying networks. + + EXPECT_CALL( + *mock_manager_client_, + ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath), + IsEqualTo(expected_shill_properties.get()), + _, _)); + + SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); + message_loop_.RunUntilIdle(); +} + TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { InitializeStandardProfiles(); SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", @@ -495,7 +531,7 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { "policy/shill_policy_on_unmanaged_wifi1.json"); // The passphrase isn't sent again, because it's configured by the user and - // Shill doesn't sent it on GetProperties calls. + // Shill doesn't send it on GetProperties calls. expected_shill_properties->RemoveWithoutPathExpansion( shill::kPassphraseProperty, NULL); diff --git a/chromeos/network/shill_property_util.cc b/chromeos/network/shill_property_util.cc index ff3980a..0bf6d84 100644 --- a/chromeos/network/shill_property_util.cc +++ b/chromeos/network/shill_property_util.cc @@ -50,12 +50,23 @@ bool CopyStringFromDictionary(const base::DictionaryValue& source, base::DictionaryValue* dest) { std::string string_value; if (!source.GetStringWithoutPathExpansion(key, &string_value) || - string_value.empty()) + string_value.empty()) { return false; + } dest->SetStringWithoutPathExpansion(key, string_value); return true; } +// This is the same normalization that Shill applies to security types for the +// sake of comparing/identifying WiFi networks. See Shill's +// WiFiService::GetSecurityClass. +std::string GetSecurityClass(const std::string& security) { + if (security == shill::kSecurityRsn || security == shill::kSecurityWpa) + return shill::kSecurityPsk; + else + return security; +} + } // namespace void SetSSID(const std::string ssid, base::DictionaryValue* properties) { @@ -229,8 +240,15 @@ bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, success &= !type.empty(); dest->SetStringWithoutPathExpansion(shill::kTypeProperty, type); if (type == shill::kTypeWifi) { - success &= CopyStringFromDictionary( - service_properties, shill::kSecurityProperty, dest); + std::string security; + service_properties.GetStringWithoutPathExpansion(shill::kSecurityProperty, + &security); + if (security.empty()) { + success = false; + } else { + dest->SetStringWithoutPathExpansion(shill::kSecurityProperty, + GetSecurityClass(security)); + } success &= CopyStringFromDictionary(service_properties, shill::kWifiHexSsid, dest); success &= CopyStringFromDictionary( |