OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 " \"Name\": \"My Ethernet\"," | 51 " \"Name\": \"My Ethernet\"," |
52 " \"Ethernet\": {" | 52 " \"Ethernet\": {" |
53 " \"Authentication\": \"None\" }," | 53 " \"Authentication\": \"None\" }," |
54 " \"ProxySettings\": {" | 54 " \"ProxySettings\": {" |
55 " \"PAC\": \"http://domain.com/x\"," | 55 " \"PAC\": \"http://domain.com/x\"," |
56 " \"Type\": \"PAC\" }" | 56 " \"Type\": \"PAC\" }" |
57 " }" | 57 " }" |
58 " ]," | 58 " ]," |
59 " \"Type\": \"UnencryptedConfiguration\"" | 59 " \"Type\": \"UnencryptedConfiguration\"" |
60 "}"; | 60 "}"; |
| 61 |
| 62 constexpr char kDeviceONCPolicy[] = |
| 63 "{" |
| 64 " \"GlobalNetworkConfiguration\": {" |
| 65 " \"AllowOnlyPolicyNetworksToAutoconnect\": false," |
| 66 " \"AllowOnlyPolicyNetworksToConnect\": false" |
| 67 " }," |
| 68 " \"NetworkConfigurations\": [ {" |
| 69 " \"GUID\": \"{wifi1_guid}\"," |
| 70 " \"Name\": \"wifi1\"," |
| 71 " \"ProxySettings\": {" |
| 72 " \"Manual\": {" |
| 73 " \"FTPProxy\": {" |
| 74 " \"Host\": \"proxy\"," |
| 75 " \"Port\": 5000" |
| 76 " }," |
| 77 " \"HTTPProxy\": {" |
| 78 " \"Host\": \"proxy\"," |
| 79 " \"Port\": 5000" |
| 80 " }," |
| 81 " \"SOCKS\": {" |
| 82 " \"Host\": \"proxy\"," |
| 83 " \"Port\": 5000" |
| 84 " }," |
| 85 " \"SecureHTTPProxy\": {" |
| 86 " \"Host\": \"proxy\"," |
| 87 " \"Port\": 5000" |
| 88 " }" |
| 89 " }," |
| 90 " \"Type\": \"Manual\"" |
| 91 " }," |
| 92 " \"Type\": \"WiFi\"," |
| 93 " \"WiFi\": {" |
| 94 " \"AutoConnect\": false," |
| 95 " \"HiddenSSID\": false," |
| 96 " \"SSID\": \"wifi1\"," |
| 97 " \"Security\": \"None\"" |
| 98 " }" |
| 99 " } ]" |
| 100 "}"; |
| 101 |
| 102 constexpr char kUserONCPolicy[] = |
| 103 "{" |
| 104 " \"NetworkConfigurations\": [ {" |
| 105 " \"GUID\": \"{direct_guid}\"," |
| 106 " \"Name\": \"EAP-TTLS\"," |
| 107 " \"ProxySettings\": {" |
| 108 " \"Type\": \"Direct\"" |
| 109 " }," |
| 110 " \"Type\": \"WiFi\"," |
| 111 " \"WiFi\": {" |
| 112 " \"AutoConnect\": false," |
| 113 " \"EAP\": {" |
| 114 " \"Identity\": \"CrOS\"," |
| 115 " \"Inner\": \"Automatic\"," |
| 116 " \"Outer\": \"EAP-TTLS\"," |
| 117 " \"Password\": \"********\"," |
| 118 " \"Recommended\": [" |
| 119 " \"AnonymousIdentity\"," |
| 120 " \"Identity\"," |
| 121 " \"Password\"" |
| 122 " ]," |
| 123 " \"SaveCredentials\": true," |
| 124 " \"UseSystemCAs\": false" |
| 125 " }," |
| 126 " \"HiddenSSID\": false," |
| 127 " \"SSID\": \"direct_ssid\"," |
| 128 " \"Security\": \"WPA-EAP\"" |
| 129 " }" |
| 130 " }, {" |
| 131 " \"GUID\": \"{wifi0_guid}\"," |
| 132 " \"Name\": \"wifi0\"," |
| 133 " \"ProxySettings\": {" |
| 134 " \"Manual\": {" |
| 135 " \"FTPProxy\": {" |
| 136 " \"Host\": \"proxy-n300\"," |
| 137 " \"Port\": 3000" |
| 138 " }," |
| 139 " \"HTTPProxy\": {" |
| 140 " \"Host\": \"proxy-n300\"," |
| 141 " \"Port\": 3000" |
| 142 " }," |
| 143 " \"SOCKS\": {" |
| 144 " \"Host\": \"proxy-n300\"," |
| 145 " \"Port\": 3000" |
| 146 " }," |
| 147 " \"SecureHTTPProxy\": {" |
| 148 " \"Host\": \"proxy-n300\"," |
| 149 " \"Port\": 3000" |
| 150 " }" |
| 151 " }," |
| 152 " \"Type\": \"Manual\"" |
| 153 " }," |
| 154 " \"Type\": \"WiFi\"," |
| 155 " \"WiFi\": {" |
| 156 " \"AutoConnect\": false," |
| 157 " \"HiddenSSID\": false," |
| 158 " \"SSID\": \"wifi0\"," |
| 159 " \"Security\": \"None\"" |
| 160 " }" |
| 161 " } ]" |
| 162 "}"; |
| 163 |
| 164 constexpr char kUserProfilePath[] = "user_profile"; |
| 165 constexpr char kDefaultServicePath[] = "stub_ethernet"; |
| 166 |
| 167 constexpr char kWifi0ServicePath[] = "stub_wifi0"; |
| 168 constexpr char kWifi0Ssid[] = "wifi0"; |
| 169 constexpr char kWifi0Guid[] = "{wifi0_guid}"; |
| 170 |
| 171 constexpr char kWifi1ServicePath[] = "stub_wifi1"; |
| 172 constexpr char kWifi1Ssid[] = "wifi1"; |
| 173 constexpr char kWifi1Guid[] = "{wifi1_guid}"; |
| 174 |
61 constexpr char kONCPacUrl[] = "http://domain.com/x"; | 175 constexpr char kONCPacUrl[] = "http://domain.com/x"; |
62 constexpr char kDefaultServicePath[] = "stub_ethernet"; | |
63 constexpr char kWifiServicePath[] = "stub_wifi"; | |
64 constexpr char kUserProfilePath[] = "user_profile"; | |
65 | 176 |
66 // Returns an amount of |broadcasts| matched with |proxy_settings|. | 177 // Returns an amount of |broadcasts| matched with |proxy_settings|. |
67 int CountProxyBroadcasts( | 178 int CountProxyBroadcasts( |
68 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, | 179 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, |
69 const base::DictionaryValue* proxy_settings) { | 180 const base::DictionaryValue* proxy_settings) { |
70 size_t count = 0; | 181 size_t count = 0; |
71 for (const FakeIntentHelperInstance::Broadcast& broadcast : broadcasts) { | 182 for (const FakeIntentHelperInstance::Broadcast& broadcast : broadcasts) { |
72 if (broadcast.action == "org.chromium.arc.intent_helper.SET_PROXY") { | 183 if (broadcast.action == "org.chromium.arc.intent_helper.SET_PROXY") { |
73 EXPECT_TRUE( | 184 EXPECT_TRUE( |
74 base::JSONReader::Read(broadcast.extras)->Equals(proxy_settings)); | 185 base::JSONReader::Read(broadcast.extras)->Equals(proxy_settings)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 233 |
123 protected: | 234 protected: |
124 void DisconnectNetworkService(const std::string& service_path) { | 235 void DisconnectNetworkService(const std::string& service_path) { |
125 chromeos::ShillServiceClient::TestInterface* service_test = | 236 chromeos::ShillServiceClient::TestInterface* service_test = |
126 chromeos::DBusThreadManager::Get() | 237 chromeos::DBusThreadManager::Get() |
127 ->GetShillServiceClient() | 238 ->GetShillServiceClient() |
128 ->GetTestInterface(); | 239 ->GetTestInterface(); |
129 base::StringValue value(shill::kStateIdle); | 240 base::StringValue value(shill::kStateIdle); |
130 service_test->SetServiceProperty(service_path, shill::kStateProperty, | 241 service_test->SetServiceProperty(service_path, shill::kStateProperty, |
131 value); | 242 value); |
| 243 RunUntilIdle(); |
| 244 } |
| 245 |
| 246 void ConnectWifiNetworkService(const std::string& service_path, |
| 247 const std::string& guid, |
| 248 const std::string& ssid) { |
| 249 chromeos::ShillServiceClient::TestInterface* service_test = |
| 250 chromeos::DBusThreadManager::Get() |
| 251 ->GetShillServiceClient() |
| 252 ->GetTestInterface(); |
| 253 |
| 254 service_test->AddService(service_path, guid, ssid, shill::kTypeWifi, |
| 255 shill::kStateOnline, true /* add_to_visible */); |
| 256 |
| 257 service_test->SetServiceProperty(service_path, shill::kProfileProperty, |
| 258 base::StringValue(kUserProfilePath)); |
| 259 RunUntilIdle(); |
132 } | 260 } |
133 | 261 |
134 void SetProxyConfigForNetworkService( | 262 void SetProxyConfigForNetworkService( |
135 const std::string& service_path, | 263 const std::string& service_path, |
136 const base::DictionaryValue* proxy_config) { | 264 const base::DictionaryValue* proxy_config) { |
137 ProxyConfigDictionary proxy_config_dict(proxy_config); | 265 ProxyConfigDictionary proxy_config_dict(proxy_config); |
138 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | 266 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() |
139 ->network_state_handler() | 267 ->network_state_handler() |
140 ->GetNetworkState(service_path); | 268 ->GetNetworkState(service_path); |
141 ASSERT_TRUE(network); | 269 ASSERT_TRUE(network); |
(...skipping 17 matching lines...) Expand all Loading... |
159 profile_test->AddProfile(kUserProfilePath, "user"); | 287 profile_test->AddProfile(kUserProfilePath, "user"); |
160 | 288 |
161 service_test->ClearServices(); | 289 service_test->ClearServices(); |
162 | 290 |
163 service_test->AddService(kDefaultServicePath, "stub_ethernet_guid", "eth0", | 291 service_test->AddService(kDefaultServicePath, "stub_ethernet_guid", "eth0", |
164 shill::kTypeEthernet, shill::kStateOnline, | 292 shill::kTypeEthernet, shill::kStateOnline, |
165 true /* add_to_visible */); | 293 true /* add_to_visible */); |
166 service_test->SetServiceProperty(kDefaultServicePath, | 294 service_test->SetServiceProperty(kDefaultServicePath, |
167 shill::kProfileProperty, | 295 shill::kProfileProperty, |
168 base::StringValue(kUserProfilePath)); | 296 base::StringValue(kUserProfilePath)); |
169 | |
170 service_test->AddService(kWifiServicePath, "stub_wifi_guid", "wifi0", | |
171 shill::kTypeWifi, shill::kStateOnline, | |
172 true /* add_to_visible */); | |
173 service_test->SetServiceProperty(kWifiServicePath, shill::kProfileProperty, | |
174 base::StringValue(kUserProfilePath)); | |
175 } | 297 } |
176 | 298 |
177 policy::MockConfigurationPolicyProvider provider_; | 299 policy::MockConfigurationPolicyProvider provider_; |
178 | 300 |
179 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); | 301 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); |
180 }; | 302 }; |
181 | 303 |
182 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { | 304 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { |
183 fake_intent_helper_instance_->clear_broadcasts(); | 305 fake_intent_helper_instance_->clear_broadcasts(); |
184 | 306 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 expected_proxy_config->SetString("mode", | 415 expected_proxy_config->SetString("mode", |
294 ProxyPrefs::kFixedServersProxyModeName); | 416 ProxyPrefs::kFixedServersProxyModeName); |
295 expected_proxy_config->SetString("host", "proxy"); | 417 expected_proxy_config->SetString("host", "proxy"); |
296 expected_proxy_config->SetInteger("port", 8080); | 418 expected_proxy_config->SetInteger("port", 8080); |
297 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | 419 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
298 expected_proxy_config.get()), | 420 expected_proxy_config.get()), |
299 1); | 421 1); |
300 } | 422 } |
301 | 423 |
302 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, DefaultNetworkDisconnectedTest) { | 424 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, DefaultNetworkDisconnectedTest) { |
| 425 ConnectWifiNetworkService(kWifi0ServicePath, kWifi0Guid, kWifi0Ssid); |
303 fake_intent_helper_instance_->clear_broadcasts(); | 426 fake_intent_helper_instance_->clear_broadcasts(); |
304 // Set proxy confog for default network. | 427 // Set proxy confog for default network. |
305 std::unique_ptr<base::DictionaryValue> default_proxy_config( | 428 std::unique_ptr<base::DictionaryValue> default_proxy_config( |
306 base::MakeUnique<base::DictionaryValue>()); | 429 base::MakeUnique<base::DictionaryValue>()); |
307 default_proxy_config->SetString("mode", | 430 default_proxy_config->SetString("mode", |
308 ProxyPrefs::kFixedServersProxyModeName); | 431 ProxyPrefs::kFixedServersProxyModeName); |
309 default_proxy_config->SetString("server", "default/proxy:8080"); | 432 default_proxy_config->SetString("server", "default/proxy:8080"); |
310 SetProxyConfigForNetworkService(kDefaultServicePath, | 433 SetProxyConfigForNetworkService(kDefaultServicePath, |
311 default_proxy_config.get()); | 434 default_proxy_config.get()); |
312 RunUntilIdle(); | 435 RunUntilIdle(); |
313 | 436 |
314 // Set proxy confog for WI-FI network. | 437 // Set proxy confog for WI-FI network. |
315 std::unique_ptr<base::DictionaryValue> wifi_proxy_config( | 438 std::unique_ptr<base::DictionaryValue> wifi_proxy_config( |
316 base::MakeUnique<base::DictionaryValue>()); | 439 base::MakeUnique<base::DictionaryValue>()); |
317 wifi_proxy_config->SetString("mode", ProxyPrefs::kFixedServersProxyModeName); | 440 wifi_proxy_config->SetString("mode", ProxyPrefs::kFixedServersProxyModeName); |
318 wifi_proxy_config->SetString("server", "wifi/proxy:8080"); | 441 wifi_proxy_config->SetString("server", "wifi/proxy:8080"); |
319 SetProxyConfigForNetworkService(kWifiServicePath, wifi_proxy_config.get()); | 442 SetProxyConfigForNetworkService(kWifi0ServicePath, wifi_proxy_config.get()); |
320 RunUntilIdle(); | 443 RunUntilIdle(); |
321 | 444 |
322 // Observe default network proxy config broadcast. | 445 // Observe default network proxy config broadcast. |
323 std::unique_ptr<base::DictionaryValue> expected_default_proxy_config( | 446 std::unique_ptr<base::DictionaryValue> expected_default_proxy_config( |
324 base::MakeUnique<base::DictionaryValue>()); | 447 base::MakeUnique<base::DictionaryValue>()); |
325 expected_default_proxy_config->SetString( | 448 expected_default_proxy_config->SetString( |
326 "mode", ProxyPrefs::kFixedServersProxyModeName); | 449 "mode", ProxyPrefs::kFixedServersProxyModeName); |
327 expected_default_proxy_config->SetString("host", "default/proxy"); | 450 expected_default_proxy_config->SetString("host", "default/proxy"); |
328 expected_default_proxy_config->SetInteger("port", 8080); | 451 expected_default_proxy_config->SetInteger("port", 8080); |
329 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | 452 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
330 expected_default_proxy_config.get()), | 453 expected_default_proxy_config.get()), |
331 1); | 454 1); |
332 | 455 |
333 // Disconnect default network. | 456 // Disconnect default network. |
334 fake_intent_helper_instance_->clear_broadcasts(); | 457 fake_intent_helper_instance_->clear_broadcasts(); |
335 DisconnectNetworkService(kDefaultServicePath); | 458 DisconnectNetworkService(kDefaultServicePath); |
336 RunUntilIdle(); | |
337 | 459 |
338 // Observe WI-FI network proxy config broadcast. | 460 // Observe WI-FI network proxy config broadcast. |
339 std::unique_ptr<base::DictionaryValue> expected_wifi_proxy_config( | 461 std::unique_ptr<base::DictionaryValue> expected_wifi_proxy_config( |
340 base::MakeUnique<base::DictionaryValue>()); | 462 base::MakeUnique<base::DictionaryValue>()); |
341 expected_wifi_proxy_config->SetString("mode", | 463 expected_wifi_proxy_config->SetString("mode", |
342 ProxyPrefs::kFixedServersProxyModeName); | 464 ProxyPrefs::kFixedServersProxyModeName); |
343 expected_wifi_proxy_config->SetString("host", "wifi/proxy"); | 465 expected_wifi_proxy_config->SetString("host", "wifi/proxy"); |
344 expected_wifi_proxy_config->SetInteger("port", 8080); | 466 expected_wifi_proxy_config->SetInteger("port", 8080); |
345 | 467 |
346 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | 468 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
347 expected_wifi_proxy_config.get()), | 469 expected_wifi_proxy_config.get()), |
348 1); | 470 1); |
349 } | 471 } |
350 | 472 |
351 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, NoNetworkConnectedTest) { | 473 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, NoNetworkConnectedTest) { |
352 // Disconnect all networks. | 474 // Disconnect all networks. |
353 fake_intent_helper_instance_->clear_broadcasts(); | 475 fake_intent_helper_instance_->clear_broadcasts(); |
354 DisconnectNetworkService(kDefaultServicePath); | 476 DisconnectNetworkService(kDefaultServicePath); |
355 DisconnectNetworkService(kWifiServicePath); | |
356 RunUntilIdle(); | |
357 | 477 |
358 EXPECT_EQ( | 478 EXPECT_EQ( |
359 CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), nullptr), | 479 CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), nullptr), |
360 0); | 480 0); |
361 } | 481 } |
362 | 482 |
| 483 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, TwoONCProxyPolicyTest) { |
| 484 // Connect to wifi1 with appliead device ONC policy. |
| 485 ConnectWifiNetworkService(kWifi1ServicePath, kWifi1Guid, kWifi1Ssid); |
| 486 |
| 487 // Disconnect default network. |
| 488 DisconnectNetworkService(kDefaultServicePath); |
| 489 |
| 490 fake_intent_helper_instance_->clear_broadcasts(); |
| 491 |
| 492 policy::PolicyMap policy; |
| 493 policy.Set(policy::key::kOpenNetworkConfiguration, |
| 494 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 495 policy::POLICY_SOURCE_CLOUD, |
| 496 base::MakeUnique<base::StringValue>(kUserONCPolicy), nullptr); |
| 497 policy.Set(policy::key::kDeviceOpenNetworkConfiguration, |
| 498 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE, |
| 499 policy::POLICY_SOURCE_CLOUD, |
| 500 base::MakeUnique<base::StringValue>(kDeviceONCPolicy), nullptr); |
| 501 UpdatePolicy(policy); |
| 502 |
| 503 std::unique_ptr<base::DictionaryValue> expected_proxy_config( |
| 504 base::MakeUnique<base::DictionaryValue>()); |
| 505 expected_proxy_config->SetString("mode", |
| 506 ProxyPrefs::kFixedServersProxyModeName); |
| 507 expected_proxy_config->SetString("host", "proxy"); |
| 508 expected_proxy_config->SetInteger("port", 5000); |
| 509 |
| 510 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 511 expected_proxy_config.get()), |
| 512 1); |
| 513 |
| 514 DisconnectNetworkService(kWifi1ServicePath); |
| 515 fake_intent_helper_instance_->clear_broadcasts(); |
| 516 |
| 517 // Connect to wifi0 with appliead user ONC policy. |
| 518 ConnectWifiNetworkService(kWifi0ServicePath, kWifi0Guid, kWifi0Ssid); |
| 519 |
| 520 expected_proxy_config->SetString("mode", |
| 521 ProxyPrefs::kFixedServersProxyModeName); |
| 522 expected_proxy_config->SetString("host", "proxy-n300"); |
| 523 expected_proxy_config->SetInteger("port", 3000); |
| 524 |
| 525 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 526 expected_proxy_config.get()), |
| 527 1); |
| 528 } |
| 529 |
363 } // namespace arc | 530 } // namespace arc |
OLD | NEW |