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

Side by Side Diff: extensions/browser/api/networking_private/networking_private_chromeos_unittest.cc

Issue 2767253006: Set HexSSID in network config before matching it against policies (Closed)
Patch Set: . Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 10 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_device_client.h" 11 #include "chromeos/dbus/shill_device_client.h"
11 #include "chromeos/dbus/shill_profile_client.h" 12 #include "chromeos/dbus/shill_profile_client.h"
12 #include "chromeos/dbus/shill_service_client.h" 13 #include "chromeos/dbus/shill_service_client.h"
13 #include "chromeos/login/login_state.h" 14 #include "chromeos/login/login_state.h"
14 #include "chromeos/network/managed_network_configuration_handler.h" 15 #include "chromeos/network/managed_network_configuration_handler.h"
15 #include "chromeos/network/network_handler.h" 16 #include "chromeos/network/network_handler.h"
16 #include "chromeos/network/network_state.h" 17 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
19 #include "components/onc/onc_constants.h"
18 #include "extensions/browser/api/networking_private/networking_private_api.h" 20 #include "extensions/browser/api/networking_private/networking_private_api.h"
19 #include "extensions/browser/api_unittest.h" 21 #include "extensions/browser/api_unittest.h"
20 #include "extensions/common/value_builder.h" 22 #include "extensions/common/value_builder.h"
21 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" 23 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
22 24
23 namespace extensions { 25 namespace extensions {
24 26
25 namespace { 27 namespace {
26 28
27 const char kUserHash[] = "test_user_hash"; 29 const char kUserHash[] = "test_user_hash";
28 const char kUserProfilePath[] = "/network_profile/user/shill"; 30 const char kUserProfilePath[] = "/network_profile/user/shill";
29 31
30 const char kWifiDevicePath[] = "/device/stub_wifi_device"; 32 const char kWifiDevicePath[] = "/device/stub_wifi_device";
31 33
32 const char kSharedWifiServicePath[] = "/service/shared_wifi"; 34 const char kSharedWifiServicePath[] = "/service/shared_wifi";
33 const char kSharedWifiGuid[] = "shared_wifi_guid"; 35 const char kSharedWifiGuid[] = "shared_wifi_guid";
34 const char kSharedWifiName[] = "shared_wifi"; 36 const char kSharedWifiName[] = "shared_wifi";
35 37
36 const char kPrivateWifiServicePath[] = "/service/private_wifi"; 38 const char kPrivateWifiServicePath[] = "/service/private_wifi";
37 const char kPrivateWifiGuid[] = "private_wifi_guid"; 39 const char kPrivateWifiGuid[] = "private_wifi_guid";
38 const char kPrivateWifiName[] = "private_wifi"; 40 const char kPrivateWifiName[] = "private_wifi";
39 41
42 const char kManagedUserWifiGuid[] = "managed_user_wifi_guid";
43 const char kManagedUserWifiSsid[] = "managed_user_wifi";
44
45 const char kManagedDeviceWifiGuid[] = "managed_device_wifi_guid";
46 const char kManagedDeviceWifiSsid[] = "managed_device_wifi";
47
40 } // namespace 48 } // namespace
41 49
42 class NetworkingPrivateApiTest : public ApiUnitTest { 50 class NetworkingPrivateApiTest : public ApiUnitTest {
43 public: 51 public:
44 NetworkingPrivateApiTest() {} 52 NetworkingPrivateApiTest() {}
45 ~NetworkingPrivateApiTest() override {} 53 ~NetworkingPrivateApiTest() override {}
46 54
47 void SetUp() override { 55 void SetUp() override {
48 ApiUnitTest::SetUp(); 56 ApiUnitTest::SetUp();
49 57
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 shill::kProfileProperty, 129 shill::kProfileProperty,
122 base::Value(kUserProfilePath)); 130 base::Value(kUserProfilePath));
123 profile_test_->AddService(kUserProfilePath, kPrivateWifiServicePath); 131 profile_test_->AddService(kUserProfilePath, kPrivateWifiServicePath);
124 } 132 }
125 133
126 void SetUpNetworkPolicy() { 134 void SetUpNetworkPolicy() {
127 chromeos::ManagedNetworkConfigurationHandler* config_handler = 135 chromeos::ManagedNetworkConfigurationHandler* config_handler =
128 chromeos::NetworkHandler::Get() 136 chromeos::NetworkHandler::Get()
129 ->managed_network_configuration_handler(); 137 ->managed_network_configuration_handler();
130 138
139 const std::string user_policy_ssid = kManagedUserWifiSsid;
140 std::unique_ptr<base::ListValue> user_policy_onc =
141 ListBuilder()
142 .Append(DictionaryBuilder()
143 .Set("GUID", kManagedUserWifiGuid)
144 .Set("Type", "WiFi")
145 .Set("WiFi",
146 DictionaryBuilder()
147 .Set("Passphrase", "fake")
148 .Set("SSID", user_policy_ssid)
149 .Set("HexSSID",
150 base::HexEncode(user_policy_ssid.c_str(),
151 user_policy_ssid.size()))
152 .Set("Security", "WPA-PSK")
153 .Build())
154 .Build())
155 .Build();
156
131 config_handler->SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUserHash, 157 config_handler->SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUserHash,
132 base::ListValue(), base::DictionaryValue()); 158 *user_policy_onc, base::DictionaryValue());
133 159
160 const std::string device_policy_ssid = kManagedDeviceWifiSsid;
161 std::unique_ptr<base::ListValue> device_policy_onc =
162 ListBuilder()
163 .Append(DictionaryBuilder()
164 .Set("GUID", kManagedDeviceWifiGuid)
165 .Set("Type", "WiFi")
166 .Set("WiFi",
167 DictionaryBuilder()
168 .Set("SSID", device_policy_ssid)
169 .Set("HexSSID", base::HexEncode(
170 device_policy_ssid.c_str(),
171 device_policy_ssid.size()))
172 .Set("Security", "None")
173 .Build())
174 .Build())
175 .Build();
134 config_handler->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, "", 176 config_handler->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, "",
135 base::ListValue(), base::DictionaryValue()); 177 *device_policy_onc, base::DictionaryValue());
136 } 178 }
137 179
138 void AddSharedNetworkToUserProfile() { 180 void AddSharedNetworkToUserProfile() {
139 service_test_->SetServiceProperty(kSharedWifiServicePath, 181 service_test_->SetServiceProperty(kSharedWifiServicePath,
140 shill::kProfileProperty, 182 shill::kProfileProperty,
141 base::Value(kUserProfilePath)); 183 base::Value(kUserProfilePath));
142 profile_test_->AddService(kUserProfilePath, kSharedWifiServicePath); 184 profile_test_->AddService(kUserProfilePath, kSharedWifiServicePath);
143 185
144 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
145 } 187 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 scoped_refptr<NetworkingPrivateSetPropertiesFunction> set_properties = 319 scoped_refptr<NetworkingPrivateSetPropertiesFunction> set_properties =
278 new NetworkingPrivateSetPropertiesFunction(); 320 new NetworkingPrivateSetPropertiesFunction();
279 321
280 RunFunction(set_properties.get(), 322 RunFunction(set_properties.get(),
281 base::StringPrintf("[\"%s\", {\"Priority\": 2}]", guid.c_str())); 323 base::StringPrintf("[\"%s\", {\"Priority\": 2}]", guid.c_str()));
282 EXPECT_EQ(ExtensionFunction::SUCCEEDED, *set_properties->response_type()); 324 EXPECT_EQ(ExtensionFunction::SUCCEEDED, *set_properties->response_type());
283 325
284 EXPECT_EQ(2, GetNetworkPriority(network)); 326 EXPECT_EQ(2, GetNetworkPriority(network));
285 } 327 }
286 328
329 TEST_F(NetworkingPrivateApiTest, CreateAlreadyConfiguredUserPrivateNetwork) {
330 EXPECT_EQ("NetworkAlreadyConfigured",
331 RunFunctionAndReturnError(
332 new NetworkingPrivateCreateNetworkFunction(),
333 base::StringPrintf("[false, {"
334 " \"Priority\": 1,"
335 " \"Type\": \"WiFi\","
336 " \"WiFi\": {"
337 " \"SSID\": \"%s\","
338 " \"Security\": \"WPA-PSK\""
339 "}}]",
340 kManagedUserWifiSsid)));
341 }
342
343 TEST_F(NetworkingPrivateApiTest, CreateAlreadyConfiguredDeviceNetwork) {
344 EXPECT_EQ(
345 "NetworkAlreadyConfigured",
346 RunFunctionAndReturnError(new NetworkingPrivateCreateNetworkFunction(),
347 base::StringPrintf("[false, {"
348 " \"Priority\": 1,"
349 " \"Type\": \"WiFi\","
350 " \"WiFi\": {"
351 " \"SSID\": \"%s\""
352 "}}]",
353 kManagedDeviceWifiSsid)));
354 }
355
287 } // namespace extensions 356 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698