Commit c8236710 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

cros_network_config fixes to required properties and policy indicators

In C++ mojo uses StructPtr for embedded structs, regardless of whether
they are required, so it is possible to pass 'nullptr' for required
properties, causing a runtime error when the properties are received.

This CL:
* Ensures that required ManagedString properties are provided in the
  C++ code, and fixes the set of properties provided for VPNs based on
  type.
* Fixes some CSS causing incorrect indicators, and cleans up some logic
  in the JS.

Bug: 1008230
Change-Id: I51484fc74e672b7b8434228abd219428461b92f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824320
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700060}
parent d1618649
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<template> <template>
<style include="internet-shared cr-hidden-style iron-flex <style include="internet-shared cr-hidden-style iron-flex
iron-flex-alignment"> iron-flex-alignment">
cr-policy-network-indicator { cr-policy-network-indicator-mojo {
margin-inline-end: 10px; margin-inline-end: 10px;
} }
......
...@@ -617,6 +617,16 @@ mojom::ManagedStringPtr GetManagedString(const base::Value* dict, ...@@ -617,6 +617,16 @@ mojom::ManagedStringPtr GetManagedString(const base::Value* dict,
return nullptr; return nullptr;
} }
mojom::ManagedStringPtr GetRequiredManagedString(const base::Value* dict,
const char* key) {
mojom::ManagedStringPtr result = GetManagedString(dict, key);
if (!result) {
// Return an empty string with no policy source.
result = mojom::ManagedString::New();
}
return result;
}
mojom::ManagedStringListPtr GetManagedStringList(const base::Value* dict, mojom::ManagedStringListPtr GetManagedStringList(const base::Value* dict,
const char* key) { const char* key) {
const base::Value* v = dict->FindKey(key); const base::Value* v = dict->FindKey(key);
...@@ -744,8 +754,13 @@ mojom::ManagedProxyLocationPtr GetManagedProxyLocation(const base::Value* dict, ...@@ -744,8 +754,13 @@ mojom::ManagedProxyLocationPtr GetManagedProxyLocation(const base::Value* dict,
if (!location_dict) if (!location_dict)
return nullptr; return nullptr;
auto proxy_location = mojom::ManagedProxyLocation::New(); auto proxy_location = mojom::ManagedProxyLocation::New();
proxy_location->host = GetManagedString(location_dict, ::onc::proxy::kHost); proxy_location->host =
GetRequiredManagedString(location_dict, ::onc::proxy::kHost);
proxy_location->port = GetManagedInt32(location_dict, ::onc::proxy::kPort); proxy_location->port = GetManagedInt32(location_dict, ::onc::proxy::kPort);
if (!proxy_location->port) {
NET_LOG(ERROR) << "ProxyLocation: No port: " << *location_dict;
return nullptr;
}
return proxy_location; return proxy_location;
} }
...@@ -763,7 +778,7 @@ void SetProxyLocation(const char* key, ...@@ -763,7 +778,7 @@ void SetProxyLocation(const char* key,
mojom::ManagedProxySettingsPtr GetManagedProxySettings( mojom::ManagedProxySettingsPtr GetManagedProxySettings(
const base::Value* dict) { const base::Value* dict) {
auto proxy_settings = mojom::ManagedProxySettings::New(); auto proxy_settings = mojom::ManagedProxySettings::New();
proxy_settings->type = GetManagedString(dict, ::onc::proxy::kType); proxy_settings->type = GetRequiredManagedString(dict, ::onc::proxy::kType);
const base::Value* manual_dict = GetDictionary(dict, ::onc::proxy::kManual); const base::Value* manual_dict = GetDictionary(dict, ::onc::proxy::kManual);
if (manual_dict) { if (manual_dict) {
auto manual_proxy_settings = mojom::ManagedManualProxySettings::New(); auto manual_proxy_settings = mojom::ManagedManualProxySettings::New();
...@@ -807,7 +822,7 @@ mojom::ManagedApnPropertiesPtr GetManagedApnProperties(const base::Value* dict, ...@@ -807,7 +822,7 @@ mojom::ManagedApnPropertiesPtr GetManagedApnProperties(const base::Value* dict,
} }
auto apn = mojom::ManagedApnProperties::New(); auto apn = mojom::ManagedApnProperties::New();
apn->access_point_name = apn->access_point_name =
GetManagedString(apn_dict, ::onc::cellular_apn::kAccessPointName); GetRequiredManagedString(apn_dict, ::onc::cellular_apn::kAccessPointName);
CHECK(apn->access_point_name); CHECK(apn->access_point_name);
apn->authentication = apn->authentication =
GetManagedString(apn_dict, ::onc::cellular_apn::kAuthentication); GetManagedString(apn_dict, ::onc::cellular_apn::kAuthentication);
...@@ -988,7 +1003,7 @@ mojom::ManagedIPSecPropertiesPtr GetManagedIPSecProperties( ...@@ -988,7 +1003,7 @@ mojom::ManagedIPSecPropertiesPtr GetManagedIPSecProperties(
return ipsec; return ipsec;
} }
ipsec->authentication_type = ipsec->authentication_type =
GetManagedString(ipsec_dict, ::onc::ipsec::kAuthenticationType); GetRequiredManagedString(ipsec_dict, ::onc::ipsec::kAuthenticationType);
ipsec->client_cert_pattern = GetManagedCertificatePattern( ipsec->client_cert_pattern = GetManagedCertificatePattern(
ipsec_dict, ::onc::client_cert::kClientCertPattern); ipsec_dict, ::onc::client_cert::kClientCertPattern);
ipsec->client_cert_pkcs11_id = ipsec->client_cert_pkcs11_id =
...@@ -1295,37 +1310,43 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1295,37 +1310,43 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
vpn->auto_connect = GetManagedBoolean(vpn_dict, ::onc::vpn::kAutoConnect); vpn->auto_connect = GetManagedBoolean(vpn_dict, ::onc::vpn::kAutoConnect);
vpn->host = GetManagedString(vpn_dict, ::onc::vpn::kHost); vpn->host = GetManagedString(vpn_dict, ::onc::vpn::kHost);
vpn->ip_sec = GetManagedIPSecProperties(vpn_dict, ::onc::vpn::kIPsec);
vpn->l2tp = GetManagedL2TPProperties(vpn_dict, ::onc::vpn::kL2TP); switch (vpn->type) {
vpn->open_vpn = case mojom::VpnType::kL2TPIPsec:
GetManagedOpenVPNProperties(vpn_dict, ::onc::vpn::kOpenVPN); vpn->ip_sec = GetManagedIPSecProperties(vpn_dict, ::onc::vpn::kIPsec);
vpn->l2tp = GetManagedL2TPProperties(vpn_dict, ::onc::vpn::kL2TP);
if (vpn->type == mojom::VpnType::kExtension || break;
vpn->type == mojom::VpnType::kArc) { case mojom::VpnType::kOpenVPN:
const base::Value* third_party_dict = vpn->open_vpn =
vpn_dict->FindKey(::onc::vpn::kThirdPartyVpn); GetManagedOpenVPNProperties(vpn_dict, ::onc::vpn::kOpenVPN);
if (third_party_dict) { break;
vpn->provider_id = GetManagedString( case mojom::VpnType::kExtension:
third_party_dict, ::onc::third_party_vpn::kExtensionID); case mojom::VpnType::kArc:
base::Optional<std::string> provider_name = GetString( const base::Value* third_party_dict =
third_party_dict, ::onc::third_party_vpn::kProviderName); vpn_dict->FindKey(::onc::vpn::kThirdPartyVpn);
if (provider_name) if (third_party_dict) {
vpn->provider_name = *provider_name; vpn->provider_id = GetManagedString(
if (vpn->provider_id && vpn->provider_name.empty()) { third_party_dict, ::onc::third_party_vpn::kExtensionID);
vpn->provider_name = GetVpnProviderName( base::Optional<std::string> provider_name = GetString(
vpn_providers, vpn->provider_id->active_value); third_party_dict, ::onc::third_party_vpn::kProviderName);
} if (provider_name)
} else { vpn->provider_name = *provider_name;
// Lookup VPN provider details from the NetworkState. if (vpn->provider_id && vpn->provider_name.empty()) {
const NetworkState::VpnProviderInfo* vpn_provider = vpn->provider_name = GetVpnProviderName(
network_state->vpn_provider(); vpn_providers, vpn->provider_id->active_value);
if (vpn_provider) { }
vpn->provider_id = mojom::ManagedString::New(); } else {
vpn->provider_id->active_value = vpn_provider->id; // Lookup VPN provider details from the NetworkState.
vpn->provider_name = const NetworkState::VpnProviderInfo* vpn_provider =
GetVpnProviderName(vpn_providers, vpn_provider->id); network_state->vpn_provider();
if (vpn_provider) {
vpn->provider_id = mojom::ManagedString::New();
vpn->provider_id->active_value = vpn_provider->id;
vpn->provider_name =
GetVpnProviderName(vpn_providers, vpn_provider->id);
}
} }
} break;
} }
result->vpn = std::move(vpn); result->vpn = std::move(vpn);
break; break;
...@@ -1355,7 +1376,7 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1355,7 +1376,7 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
GetManagedBoolean(wifi_dict, ::onc::wifi::kHiddenSSID); GetManagedBoolean(wifi_dict, ::onc::wifi::kHiddenSSID);
wifi->roam_threshold = wifi->roam_threshold =
GetManagedInt32(wifi_dict, ::onc::wifi::kRoamThreshold); GetManagedInt32(wifi_dict, ::onc::wifi::kRoamThreshold);
wifi->ssid = GetManagedString(wifi_dict, ::onc::wifi::kSSID); wifi->ssid = GetRequiredManagedString(wifi_dict, ::onc::wifi::kSSID);
CHECK(wifi->ssid); CHECK(wifi->ssid);
wifi->signal_strength = GetInt32(wifi_dict, ::onc::wifi::kSignalStrength); wifi->signal_strength = GetInt32(wifi_dict, ::onc::wifi::kSignalStrength);
wifi->tethering_state = wifi->tethering_state =
......
...@@ -608,6 +608,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) { ...@@ -608,6 +608,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) {
properties->connection_state); properties->connection_state);
ASSERT_TRUE(properties->wifi); ASSERT_TRUE(properties->wifi);
EXPECT_EQ(50, properties->wifi->signal_strength); EXPECT_EQ(50, properties->wifi->signal_strength);
EXPECT_EQ(mojom::OncSource::kNone, properties->source);
properties = GetManagedProperties("wifi2_guid"); properties = GetManagedProperties("wifi2_guid");
ASSERT_TRUE(properties); ASSERT_TRUE(properties);
...@@ -618,6 +619,15 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) { ...@@ -618,6 +619,15 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) {
ASSERT_TRUE(properties->wifi); ASSERT_TRUE(properties->wifi);
EXPECT_EQ(mojom::SecurityType::kWpaPsk, properties->wifi->security); EXPECT_EQ(mojom::SecurityType::kWpaPsk, properties->wifi->security);
EXPECT_EQ(100, properties->wifi->signal_strength); EXPECT_EQ(100, properties->wifi->signal_strength);
EXPECT_EQ(mojom::OncSource::kUserPolicy, properties->source);
properties = GetManagedProperties("wifi3_guid");
ASSERT_TRUE(properties);
EXPECT_EQ("wifi3_guid", properties->guid);
EXPECT_EQ(mojom::NetworkType::kWiFi, properties->type);
EXPECT_EQ(mojom::ConnectionStateType::kNotConnected,
properties->connection_state);
EXPECT_EQ(mojom::OncSource::kDevice, properties->source);
properties = GetManagedProperties("cellular_guid"); properties = GetManagedProperties("cellular_guid");
ASSERT_TRUE(properties); ASSERT_TRUE(properties);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
--cr-input-background-color: transparent; --cr-input-background-color: transparent;
} }
cr-policy-network-indicator { cr-policy-network-indicator-mojo {
margin-inline-start: var(--settings-controlled-by-spacing); margin-inline-start: var(--settings-controlled-by-spacing);
} }
</style> </style>
......
...@@ -167,7 +167,7 @@ Polymer({ ...@@ -167,7 +167,7 @@ Polymer({
return true; return true;
} }
const value = this.getPropertyValue_(key, prefix, propertyDict); const value = this.getPropertyValue_(key, prefix, propertyDict);
return value !== undefined && value !== ''; return value !== '';
}; };
}, },
...@@ -247,14 +247,13 @@ Polymer({ ...@@ -247,14 +247,13 @@ Polymer({
*/ */
getProperty_: function(key, propertyDict) { getProperty_: function(key, propertyDict) {
const property = this.get(key, this.propertyDict); const property = this.get(key, this.propertyDict);
if ((property === undefined || property === null) && if (property === undefined || property === null) {
propertyDict.source !== undefined) {
// If the dictionary is policy controlled, provide an empty property
// object with the network policy source. See https://crbug.com/819837
// for more info.
const policySource = const policySource =
OncMojo.getEnforcedPolicySourceFromOncSource(propertyDict.source); OncMojo.getEnforcedPolicySourceFromOncSource(propertyDict.source);
if (policySource != chromeos.networkConfig.mojom.PolicySource.kNone) { if (policySource != chromeos.networkConfig.mojom.PolicySource.kNone) {
// If the dictionary is policy controlled, provide an empty property
// object with the network policy source. See https://crbug.com/819837
// for more info.
return /** @type{!OncMojo.ManagedProperty} */ ({ return /** @type{!OncMojo.ManagedProperty} */ ({
activeValue: '', activeValue: '',
policySource: policySource, policySource: policySource,
......
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