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

Side by Side Diff: chrome/browser/chromeos/cros/network_library_unittest.cc

Issue 16946002: Resolve certificate references in ONC by PEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trust update. Add a utils test. Remove X509 dependency from Shill parsing. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <pk11pub.h> 5 #include <pk11pub.h>
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 cros_ = NULL; 147 cros_ = NULL;
148 } 148 }
149 149
150 // Load the ONC from |onc_file| using NetworkLibrary::LoadOncNetworks. Check 150 // Load the ONC from |onc_file| using NetworkLibrary::LoadOncNetworks. Check
151 // that return value matches |expect_successful_import| and the configuration 151 // that return value matches |expect_successful_import| and the configuration
152 // that would be sent to Shill matches |shill_json|. 152 // that would be sent to Shill matches |shill_json|.
153 void LoadOncAndVerifyNetworks(std::string onc_file, 153 void LoadOncAndVerifyNetworks(std::string onc_file,
154 std::string shill_json, 154 std::string shill_json,
155 onc::ONCSource source, 155 onc::ONCSource source,
156 bool expect_successful_import) { 156 bool expect_successful_import) {
157 MockUserManager* mock_user_manager = new MockUserManager; 157 MockUserManager* mock_user_manager =
158 new ::testing::StrictMock<MockUserManager>;
158 // Takes ownership of |mock_user_manager|. 159 // Takes ownership of |mock_user_manager|.
159 ScopedUserManagerEnabler user_manager_enabler(mock_user_manager); 160 ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
160 mock_user_manager->SetActiveUser("madmax@my.domain.com"); 161 mock_user_manager->SetActiveUser("madmax@my.domain.com");
161 EXPECT_CALL(*mock_user_manager, IsUserLoggedIn()) 162 EXPECT_CALL(*mock_user_manager, IsUserLoggedIn())
162 .Times(AnyNumber()) 163 .Times(AnyNumber())
163 .WillRepeatedly(Return(true)); 164 .WillRepeatedly(Return(true));
165 EXPECT_CALL(*mock_user_manager, Shutdown());
164 166
165 scoped_ptr<base::DictionaryValue> onc_blob = 167 scoped_ptr<base::DictionaryValue> onc_blob =
166 onc::test_utils::ReadTestDictionary(onc_file); 168 onc::test_utils::ReadTestDictionary(onc_file);
167 base::ListValue* onc_network_configs; 169 base::ListValue* onc_network_configs;
168 onc_blob->GetListWithoutPathExpansion( 170 onc_blob->GetListWithoutPathExpansion(
169 onc::toplevel_config::kNetworkConfigurations, 171 onc::toplevel_config::kNetworkConfigurations,
170 &onc_network_configs); 172 &onc_network_configs);
171 ASSERT_TRUE(onc_network_configs); 173 ASSERT_TRUE(onc_network_configs);
172 174
173 scoped_ptr<base::Value> expected_value = 175 scoped_ptr<base::Value> expected_value =
174 google_apis::test_util::LoadJSONFile(shill_json); 176 google_apis::test_util::LoadJSONFile(shill_json);
175 base::DictionaryValue* expected_configs; 177 base::DictionaryValue* expected_configs;
176 expected_value->GetAsDictionary(&expected_configs); 178 expected_value->GetAsDictionary(&expected_configs);
177 179
178 cros_->LoadOncNetworks(*onc_network_configs, source); 180 cros_->LoadOncNetworks(*onc_network_configs, source,
181 base::Bind(&onc::test_utils::FakeFingerprintToPEM));
179 182
180 const std::map<std::string, base::DictionaryValue*>& configs = 183 const std::map<std::string, base::DictionaryValue*>& configs =
181 cros_->GetConfigurations(); 184 cros_->GetConfigurations();
182 185
183 EXPECT_EQ(expected_configs->size(), configs.size()); 186 EXPECT_EQ(expected_configs->size(), configs.size());
184 187
185 for (base::DictionaryValue::Iterator it(*expected_configs); !it.IsAtEnd(); 188 for (base::DictionaryValue::Iterator it(*expected_configs); !it.IsAtEnd();
186 it.Advance()) { 189 it.Advance()) {
187 const base::DictionaryValue* expected_config; 190 const base::DictionaryValue* expected_config;
188 it.value().GetAsDictionary(&expected_config); 191 it.value().GetAsDictionary(&expected_config);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_TRUE(wifi1->connected()); 285 EXPECT_TRUE(wifi1->connected());
283 cros_->DisconnectFromNetwork(wifi1); 286 cros_->DisconnectFromNetwork(wifi1);
284 EXPECT_FALSE(wifi1->connected()); 287 EXPECT_FALSE(wifi1->connected());
285 EXPECT_TRUE(cros_->CanConnectToNetwork(wifi1)); 288 EXPECT_TRUE(cros_->CanConnectToNetwork(wifi1));
286 cros_->ConnectToWifiNetwork(wifi1); 289 cros_->ConnectToWifiNetwork(wifi1);
287 EXPECT_TRUE(wifi1->connected()); 290 EXPECT_TRUE(wifi1->connected());
288 } 291 }
289 292
290 TEST_F(NetworkLibraryStubTest, NetworkConnectWifiWithCertPattern) { 293 TEST_F(NetworkLibraryStubTest, NetworkConnectWifiWithCertPattern) {
291 scoped_ptr<base::DictionaryValue> onc_root = 294 scoped_ptr<base::DictionaryValue> onc_root =
292 onc::test_utils::ReadTestDictionary("toplevel_wifi_eap_clientcert.onc"); 295 onc::test_utils::ReadTestDictionary("certificate-client.onc");
293 base::ListValue* certificates; 296 base::ListValue* certificates;
294 onc_root->GetListWithoutPathExpansion(onc::toplevel_config::kCertificates, 297 onc_root->GetListWithoutPathExpansion(onc::toplevel_config::kCertificates,
295 &certificates); 298 &certificates);
296 299
297 onc::CertificateImporter importer(true /* allow trust imports */); 300 onc::CertificateImporter importer(true /* allow trust imports */);
298 ASSERT_EQ(onc::CertificateImporter::IMPORT_OK, 301 ASSERT_EQ(onc::CertificateImporter::IMPORT_OK,
299 importer.ParseAndStoreCertificates(*certificates, NULL)); 302 importer.ParseAndStoreCertificates(*certificates, NULL, NULL));
300 303
301 WifiNetwork* wifi = cros_->FindWifiNetworkByPath("wifi_cert_pattern"); 304 WifiNetwork* wifi = cros_->FindWifiNetworkByPath("wifi_cert_pattern");
302 305
303 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); 306 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate();
304 wifi->SetEnrollmentDelegate(enrollment_delegate); 307 wifi->SetEnrollmentDelegate(enrollment_delegate);
305 EXPECT_FALSE(enrollment_delegate->did_enroll); 308 EXPECT_FALSE(enrollment_delegate->did_enroll);
306 EXPECT_FALSE(enrollment_delegate->correct_args); 309 EXPECT_FALSE(enrollment_delegate->correct_args);
307 310
308 ASSERT_NE(static_cast<const WifiNetwork*>(NULL), wifi); 311 ASSERT_NE(static_cast<const WifiNetwork*>(NULL), wifi);
309 EXPECT_FALSE(wifi->connected()); 312 EXPECT_FALSE(wifi->connected());
310 EXPECT_TRUE(cros_->CanConnectToNetwork(wifi)); 313 EXPECT_TRUE(cros_->CanConnectToNetwork(wifi));
311 EXPECT_FALSE(wifi->connected()); 314 EXPECT_FALSE(wifi->connected());
312 wifi->AttemptConnection( 315 wifi->AttemptConnection(
313 base::Bind(&WifiNetworkConnectCallback, cros_, wifi)); 316 base::Bind(&WifiNetworkConnectCallback, cros_, wifi));
314 EXPECT_TRUE(wifi->connected()); 317 EXPECT_TRUE(wifi->connected());
315 EXPECT_TRUE(enrollment_delegate->did_enroll); 318 EXPECT_TRUE(enrollment_delegate->did_enroll);
316 EXPECT_TRUE(enrollment_delegate->correct_args); 319 EXPECT_TRUE(enrollment_delegate->correct_args);
317 } 320 }
318 321
319 TEST_F(NetworkLibraryStubTest, NetworkConnectVPNWithCertPattern) { 322 TEST_F(NetworkLibraryStubTest, NetworkConnectVPNWithCertPattern) {
320 scoped_ptr<base::DictionaryValue> onc_root = 323 scoped_ptr<base::DictionaryValue> onc_root =
321 onc::test_utils::ReadTestDictionary("toplevel_openvpn_clientcert.onc"); 324 onc::test_utils::ReadTestDictionary("certificate-client.onc");
322 base::ListValue* certificates; 325 base::ListValue* certificates;
323 onc_root->GetListWithoutPathExpansion(onc::toplevel_config::kCertificates, 326 onc_root->GetListWithoutPathExpansion(onc::toplevel_config::kCertificates,
324 &certificates); 327 &certificates);
325 328
326 onc::CertificateImporter importer(true /* allow trust imports */); 329 onc::CertificateImporter importer(true /* allow trust imports */);
327 ASSERT_EQ(onc::CertificateImporter::IMPORT_OK, 330 ASSERT_EQ(onc::CertificateImporter::IMPORT_OK,
328 importer.ParseAndStoreCertificates(*certificates, NULL)); 331 importer.ParseAndStoreCertificates(*certificates, NULL, NULL));
329 332
330 VirtualNetwork* vpn = cros_->FindVirtualNetworkByPath("vpn_cert_pattern"); 333 VirtualNetwork* vpn = cros_->FindVirtualNetworkByPath("vpn_cert_pattern");
331 334
332 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); 335 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate();
333 vpn->SetEnrollmentDelegate(enrollment_delegate); 336 vpn->SetEnrollmentDelegate(enrollment_delegate);
334 EXPECT_FALSE(enrollment_delegate->did_enroll); 337 EXPECT_FALSE(enrollment_delegate->did_enroll);
335 EXPECT_FALSE(enrollment_delegate->correct_args); 338 EXPECT_FALSE(enrollment_delegate->correct_args);
336 339
337 ASSERT_NE(static_cast<const VirtualNetwork*>(NULL), vpn); 340 ASSERT_NE(static_cast<const VirtualNetwork*>(NULL), vpn);
338 EXPECT_FALSE(vpn->connected()); 341 EXPECT_FALSE(vpn->connected());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 GetParam().expect_import_result); 403 GetParam().expect_import_result);
401 } 404 }
402 405
403 INSTANTIATE_TEST_CASE_P( 406 INSTANTIATE_TEST_CASE_P(
404 LoadOncNetworksTest, 407 LoadOncNetworksTest,
405 LoadOncNetworksTest, 408 LoadOncNetworksTest,
406 ::testing::Values( 409 ::testing::Values(
407 ImportParams("managed_toplevel1.onc", 410 ImportParams("managed_toplevel1.onc",
408 "chromeos/net/shill_for_managed_toplevel1.json", 411 "chromeos/net/shill_for_managed_toplevel1.json",
409 onc::ONC_SOURCE_USER_POLICY), 412 onc::ONC_SOURCE_USER_POLICY),
410 ImportParams("managed_toplevel2.onc", 413 ImportParams("managed_toplevel2_with_cert_fingerprints.onc",
411 "chromeos/net/shill_for_managed_toplevel2.json", 414 "chromeos/net/shill_for_managed_toplevel2.json",
412 onc::ONC_SOURCE_USER_POLICY), 415 onc::ONC_SOURCE_USER_POLICY),
413 ImportParams("managed_toplevel_l2tpipsec.onc", 416 ImportParams("managed_toplevel_l2tpipsec.onc",
414 "chromeos/net/shill_for_managed_toplevel_l2tpipsec.json", 417 "chromeos/net/shill_for_managed_toplevel_l2tpipsec.json",
415 onc::ONC_SOURCE_USER_POLICY), 418 onc::ONC_SOURCE_USER_POLICY),
416 ImportParams("managed_toplevel_wifi_peap.onc", 419 ImportParams("managed_toplevel_wifi_peap.onc",
417 "chromeos/net/shill_for_managed_toplevel_wifi_peap.json", 420 "chromeos/net/shill_for_managed_toplevel_wifi_peap.json",
418 onc::ONC_SOURCE_DEVICE_POLICY), 421 onc::ONC_SOURCE_DEVICE_POLICY),
419 ImportParams("toplevel_wifi_open.onc", 422 ImportParams("toplevel_wifi_open.onc",
420 "chromeos/net/shill_for_toplevel_wifi_open.json", 423 "chromeos/net/shill_for_toplevel_wifi_open.json",
421 onc::ONC_SOURCE_DEVICE_POLICY), 424 onc::ONC_SOURCE_DEVICE_POLICY),
422 ImportParams("toplevel_wifi_wep_proxy.onc", 425 ImportParams("toplevel_wifi_wep_proxy.onc",
423 "chromeos/net/shill_for_toplevel_wifi_wep_proxy.json", 426 "chromeos/net/shill_for_toplevel_wifi_wep_proxy.json",
424 onc::ONC_SOURCE_USER_POLICY), 427 onc::ONC_SOURCE_USER_POLICY),
425 ImportParams("toplevel_wifi_wpa_psk.onc", 428 ImportParams("toplevel_wifi_wpa_psk.onc",
426 "chromeos/net/shill_for_toplevel_wifi_wpa_psk.json", 429 "chromeos/net/shill_for_toplevel_wifi_wpa_psk.json",
427 onc::ONC_SOURCE_USER_POLICY), 430 onc::ONC_SOURCE_USER_POLICY),
428 ImportParams("toplevel_wifi_leap.onc", 431 ImportParams("toplevel_wifi_leap.onc",
429 "chromeos/net/shill_for_toplevel_wifi_leap.json", 432 "chromeos/net/shill_for_toplevel_wifi_leap.json",
430 onc::ONC_SOURCE_USER_POLICY), 433 onc::ONC_SOURCE_USER_POLICY),
431 ImportParams( 434 ImportParams(
432 "toplevel_wifi_eap_clientcert.onc", 435 "toplevel_wifi_eap_clientcert_with_cert_fingerprints.onc",
433 "chromeos/net/shill_for_toplevel_wifi_eap_clientcert.json", 436 "chromeos/net/shill_for_toplevel_wifi_eap_clientcert.json",
434 onc::ONC_SOURCE_USER_POLICY), 437 onc::ONC_SOURCE_USER_POLICY),
435 ImportParams("toplevel_openvpn_clientcert.onc", 438 ImportParams("toplevel_openvpn_clientcert_with_cert_fingerprints.onc",
436 "chromeos/net/shill_for_toplevel_openvpn_clientcert.json", 439 "chromeos/net/shill_for_toplevel_openvpn_clientcert.json",
437 onc::ONC_SOURCE_USER_POLICY), 440 onc::ONC_SOURCE_USER_POLICY),
438 ImportParams("toplevel_wifi_remove.onc", 441 ImportParams("toplevel_wifi_remove.onc",
439 "chromeos/net/shill_for_toplevel_wifi_remove.json", 442 "chromeos/net/shill_for_toplevel_wifi_remove.json",
440 onc::ONC_SOURCE_USER_POLICY))); 443 onc::ONC_SOURCE_USER_POLICY)));
441 444
442 // TODO(stevenjb): Test remembered networks. 445 // TODO(stevenjb): Test remembered networks.
443 446
444 // TODO(stevenjb): Test network profiles. 447 // TODO(stevenjb): Test network profiles.
445 448
446 // TODO(stevenjb): Test network devices. 449 // TODO(stevenjb): Test network devices.
447 450
448 // TODO(stevenjb): Test data plans. 451 // TODO(stevenjb): Test data plans.
449 452
450 // TODO(stevenjb): Test monitor network / device. 453 // TODO(stevenjb): Test monitor network / device.
451 454
452 } // namespace chromeos 455 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698